sasat 0.22.6 → 0.22.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.cjs +9 -6
- package/dist/cli/index.mjs +7 -4
- package/dist/getDbClient-CNcumqpO.mjs +108 -0
- package/dist/getDbClient-Dnkk-peb.cjs +131 -0
- package/dist/index.cjs +8 -7
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.mjs +3 -2
- package/dist/{migrate-BDE07ocG.cjs → migrate-COeYPag2.cjs} +5 -8
- package/dist/{migrate-DnqBdQ6r.mjs → migrate-mh3DLqgw.mjs} +5 -8
- package/dist/migration/index.cjs +1 -1
- package/dist/migration/index.d.mts +2 -2
- package/dist/migration/index.mjs +1 -1
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.d.mts +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/{util-Dkw5bD7a.mjs → util-BcMcffJ8.mjs} +1 -107
- package/dist/{util-C5Jevn5B.cjs → util-IRlTD1y7.cjs} +0 -130
- package/package.json +1 -1
- /package/dist/{comparison-BpTtc1iD.d.mts → comparison-CEpYTo3e.d.mts} +0 -0
- /package/dist/{dbClient-2mFJTQw7.d.mts → dbClient-TBYnlvTc.d.mts} +0 -0
- /package/dist/{makeCondition-3MdYUm5k.mjs → makeCondition-BQj-Av95.mjs} +0 -0
- /package/dist/{makeCondition-DKSyAkri.cjs → makeCondition-DljWZv_v.cjs} +0 -0
package/dist/cli/index.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_util = require("../util-
|
|
3
|
-
const
|
|
2
|
+
const require_util = require("../util-IRlTD1y7.cjs");
|
|
3
|
+
const require_getDbClient = require("../getDbClient-Dnkk-peb.cjs");
|
|
4
|
+
const require_migrate = require("../migrate-COeYPag2.cjs");
|
|
4
5
|
let node_fs = require("node:fs");
|
|
5
6
|
node_fs = require_util.__toESM(node_fs, 1);
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
node_path = require_util.__toESM(node_path, 1);
|
|
8
9
|
let cac = require("cac");
|
|
9
10
|
//#region src/cli/commands/createMigration.ts
|
|
10
|
-
const getMigrationFile = (className) => `import {
|
|
11
|
+
const getMigrationFile = (className) => `import type { MigrationStore, SasatMigration } from "sasat/migration";
|
|
11
12
|
|
|
12
13
|
export default class ${require_migrate.capitalizeFirstLetter(className)} implements SasatMigration {
|
|
13
14
|
|
|
@@ -15,7 +16,7 @@ export default class ${require_migrate.capitalizeFirstLetter(className)} impleme
|
|
|
15
16
|
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
down: (store: MigrationStore) => void =
|
|
19
|
+
down: (store: MigrationStore) => void = () => {
|
|
19
20
|
throw new Error('Down is not implemented on ${className}');
|
|
20
21
|
};
|
|
21
22
|
}
|
|
@@ -472,7 +473,7 @@ const serializeCreateTable = (str) => {
|
|
|
472
473
|
//#endregion
|
|
473
474
|
//#region src/cli/commands/dumpDb.ts
|
|
474
475
|
const dumpDB = async () => {
|
|
475
|
-
const con =
|
|
476
|
+
const con = require_getDbClient.getDbClient();
|
|
476
477
|
try {
|
|
477
478
|
const tables = await con.rawQuery("show tables").then((it) => it.flatMap((it) => Object.values(it)));
|
|
478
479
|
const serialized = await Promise.all(tables.map((table) => {
|
|
@@ -583,7 +584,9 @@ const migrationBuild = async () => {
|
|
|
583
584
|
const index = (0, cac.cac)();
|
|
584
585
|
try {
|
|
585
586
|
index.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").option("-b, --skipBuild", "skip compile migration files").action(async (options) => {
|
|
586
|
-
const
|
|
587
|
+
const conf = require_util.config();
|
|
588
|
+
if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
|
|
589
|
+
const client = require_getDbClient.getDbClient();
|
|
587
590
|
await require_migrate.migrate(client, options).catch((e) => {
|
|
588
591
|
console.error(e);
|
|
589
592
|
process.exit(1);
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { a as SqlString, c as setConfig, d as writeCurrentSchema, l as mkDirIfNotExist, o as config, p as writeYmlFile, s as defaultConf } from "../util-BcMcffJ8.mjs";
|
|
3
|
+
import { t as getDbClient } from "../getDbClient-CNcumqpO.mjs";
|
|
4
|
+
import { a as getMigrationFileNames, c as defaultColumnOption, d as DBColumnTypes, f as Console, i as compileMigrationFiles, l as defaultGQLOption, m as capitalizeFirstLetter, n as CodeGen_v2, o as DataStoreHandler, p as camelize, r as createCurrentMigrationDataStore, s as Directory, t as migrate, u as columnTypeToGqlPrimitive } from "../migrate-mh3DLqgw.mjs";
|
|
4
5
|
import * as fs$1 from "node:fs";
|
|
5
6
|
import fs from "node:fs";
|
|
6
7
|
import path, { join } from "node:path";
|
|
7
8
|
import { cac } from "cac";
|
|
8
9
|
//#region src/cli/commands/createMigration.ts
|
|
9
|
-
const getMigrationFile = (className) => `import {
|
|
10
|
+
const getMigrationFile = (className) => `import type { MigrationStore, SasatMigration } from "sasat/migration";
|
|
10
11
|
|
|
11
12
|
export default class ${capitalizeFirstLetter(className)} implements SasatMigration {
|
|
12
13
|
|
|
@@ -14,7 +15,7 @@ export default class ${capitalizeFirstLetter(className)} implements SasatMigrati
|
|
|
14
15
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
down: (store: MigrationStore) => void =
|
|
18
|
+
down: (store: MigrationStore) => void = () => {
|
|
18
19
|
throw new Error('Down is not implemented on ${className}');
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -582,6 +583,8 @@ const migrationBuild = async () => {
|
|
|
582
583
|
const index = cac();
|
|
583
584
|
try {
|
|
584
585
|
index.usage("yarn sasat <command> [options]\n").command("migrate", "execute migration").option("-g, --generateFiles", "migrate with generate files").option("-d, --dry", "dry run").option("-s, --silent", "do not print logs").option("-b, --skipBuild", "skip compile migration files").action(async (options) => {
|
|
586
|
+
const conf = config();
|
|
587
|
+
if (conf.migration.db) setConfig({ db: conf.migration.db });
|
|
585
588
|
const client = getDbClient();
|
|
586
589
|
await migrate(client, options).catch((e) => {
|
|
587
590
|
console.error(e);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { a as SqlString, o as config } from "./util-BcMcffJ8.mjs";
|
|
2
|
+
import { createConnection, createPool } from "mysql2/promise";
|
|
3
|
+
//#region src/db/formatQuery.ts
|
|
4
|
+
const formatQuery = (str, ...params) => {
|
|
5
|
+
let ret = str[0];
|
|
6
|
+
for (let i = 0; i < params.length; i++) {
|
|
7
|
+
if (typeof params[i] === "function") ret += params[i]();
|
|
8
|
+
else if (Array.isArray(params[i])) ret += params[i].map((it) => SqlString.escape(it)).join(", ");
|
|
9
|
+
else ret += SqlString.escape(params[i]);
|
|
10
|
+
ret += str[i + 1];
|
|
11
|
+
}
|
|
12
|
+
return ret;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/db/connectors/dbClient.ts
|
|
16
|
+
const noop = () => {};
|
|
17
|
+
var SQLClient = class {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.logger = noop;
|
|
20
|
+
}
|
|
21
|
+
rawQuery(sql) {
|
|
22
|
+
this.logger(sql);
|
|
23
|
+
return this.execSql(sql);
|
|
24
|
+
}
|
|
25
|
+
rawCommand(sql) {
|
|
26
|
+
this.logger(sql);
|
|
27
|
+
return this.execSql(sql);
|
|
28
|
+
}
|
|
29
|
+
query(templateString, ...params) {
|
|
30
|
+
return this.rawQuery(formatQuery(templateString, ...params));
|
|
31
|
+
}
|
|
32
|
+
command(templateString, ...params) {
|
|
33
|
+
return this.rawCommand(formatQuery(templateString, ...params));
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var SQLTransaction = class extends SQLClient {};
|
|
37
|
+
var DBClient = class extends SQLClient {
|
|
38
|
+
constructor(logger = noop) {
|
|
39
|
+
super();
|
|
40
|
+
this._released = false;
|
|
41
|
+
this.logger = logger;
|
|
42
|
+
}
|
|
43
|
+
isReleased() {
|
|
44
|
+
return this._released;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/db/connectors/mysql/transaction.ts
|
|
49
|
+
var MySqlTransaction = class extends SQLTransaction {
|
|
50
|
+
constructor(connection) {
|
|
51
|
+
super();
|
|
52
|
+
this.connection = connection;
|
|
53
|
+
}
|
|
54
|
+
async commit() {
|
|
55
|
+
const result = await this.connection.commit();
|
|
56
|
+
await this.connection.end();
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
async rollback() {
|
|
60
|
+
await this.connection.rollback();
|
|
61
|
+
await this.connection.end();
|
|
62
|
+
}
|
|
63
|
+
async execSql(sql) {
|
|
64
|
+
return (await this.connection.query(sql))[0];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/db/connectors/mysql/poolClient.ts
|
|
69
|
+
var MysqlPoolClient = class extends DBClient {
|
|
70
|
+
constructor(poolOption, logger) {
|
|
71
|
+
super(logger);
|
|
72
|
+
this.poolOption = poolOption;
|
|
73
|
+
this.pool = createPool({
|
|
74
|
+
dateStrings: true,
|
|
75
|
+
...poolOption
|
|
76
|
+
});
|
|
77
|
+
this.release = this.release.bind(this);
|
|
78
|
+
}
|
|
79
|
+
async transaction() {
|
|
80
|
+
const connection = await createConnection({
|
|
81
|
+
...config().db,
|
|
82
|
+
dateStrings: true,
|
|
83
|
+
...this.poolOption
|
|
84
|
+
});
|
|
85
|
+
await connection.beginTransaction();
|
|
86
|
+
return new MySqlTransaction(connection);
|
|
87
|
+
}
|
|
88
|
+
async release() {
|
|
89
|
+
await this.pool.end();
|
|
90
|
+
this._released = true;
|
|
91
|
+
}
|
|
92
|
+
async execSql(sql) {
|
|
93
|
+
return (await this.pool.query(sql))[0];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/db/getDbClient.ts
|
|
98
|
+
let client;
|
|
99
|
+
const getDbClient = (option, logger) => {
|
|
100
|
+
if (client && !client.isReleased()) return client;
|
|
101
|
+
client = new MysqlPoolClient({
|
|
102
|
+
...config().db,
|
|
103
|
+
...option
|
|
104
|
+
}, logger);
|
|
105
|
+
return client;
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
export { formatQuery as i, MySqlTransaction as n, DBClient as r, getDbClient as t };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const require_util = require("./util-IRlTD1y7.cjs");
|
|
2
|
+
let mysql2_promise = require("mysql2/promise");
|
|
3
|
+
//#region src/db/formatQuery.ts
|
|
4
|
+
const formatQuery = (str, ...params) => {
|
|
5
|
+
let ret = str[0];
|
|
6
|
+
for (let i = 0; i < params.length; i++) {
|
|
7
|
+
if (typeof params[i] === "function") ret += params[i]();
|
|
8
|
+
else if (Array.isArray(params[i])) ret += params[i].map((it) => require_util.SqlString.escape(it)).join(", ");
|
|
9
|
+
else ret += require_util.SqlString.escape(params[i]);
|
|
10
|
+
ret += str[i + 1];
|
|
11
|
+
}
|
|
12
|
+
return ret;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/db/connectors/dbClient.ts
|
|
16
|
+
const noop = () => {};
|
|
17
|
+
var SQLClient = class {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.logger = noop;
|
|
20
|
+
}
|
|
21
|
+
rawQuery(sql) {
|
|
22
|
+
this.logger(sql);
|
|
23
|
+
return this.execSql(sql);
|
|
24
|
+
}
|
|
25
|
+
rawCommand(sql) {
|
|
26
|
+
this.logger(sql);
|
|
27
|
+
return this.execSql(sql);
|
|
28
|
+
}
|
|
29
|
+
query(templateString, ...params) {
|
|
30
|
+
return this.rawQuery(formatQuery(templateString, ...params));
|
|
31
|
+
}
|
|
32
|
+
command(templateString, ...params) {
|
|
33
|
+
return this.rawCommand(formatQuery(templateString, ...params));
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var SQLTransaction = class extends SQLClient {};
|
|
37
|
+
var DBClient = class extends SQLClient {
|
|
38
|
+
constructor(logger = noop) {
|
|
39
|
+
super();
|
|
40
|
+
this._released = false;
|
|
41
|
+
this.logger = logger;
|
|
42
|
+
}
|
|
43
|
+
isReleased() {
|
|
44
|
+
return this._released;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/db/connectors/mysql/transaction.ts
|
|
49
|
+
var MySqlTransaction = class extends SQLTransaction {
|
|
50
|
+
constructor(connection) {
|
|
51
|
+
super();
|
|
52
|
+
this.connection = connection;
|
|
53
|
+
}
|
|
54
|
+
async commit() {
|
|
55
|
+
const result = await this.connection.commit();
|
|
56
|
+
await this.connection.end();
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
async rollback() {
|
|
60
|
+
await this.connection.rollback();
|
|
61
|
+
await this.connection.end();
|
|
62
|
+
}
|
|
63
|
+
async execSql(sql) {
|
|
64
|
+
return (await this.connection.query(sql))[0];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/db/connectors/mysql/poolClient.ts
|
|
69
|
+
var MysqlPoolClient = class extends DBClient {
|
|
70
|
+
constructor(poolOption, logger) {
|
|
71
|
+
super(logger);
|
|
72
|
+
this.poolOption = poolOption;
|
|
73
|
+
this.pool = (0, mysql2_promise.createPool)({
|
|
74
|
+
dateStrings: true,
|
|
75
|
+
...poolOption
|
|
76
|
+
});
|
|
77
|
+
this.release = this.release.bind(this);
|
|
78
|
+
}
|
|
79
|
+
async transaction() {
|
|
80
|
+
const connection = await (0, mysql2_promise.createConnection)({
|
|
81
|
+
...require_util.config().db,
|
|
82
|
+
dateStrings: true,
|
|
83
|
+
...this.poolOption
|
|
84
|
+
});
|
|
85
|
+
await connection.beginTransaction();
|
|
86
|
+
return new MySqlTransaction(connection);
|
|
87
|
+
}
|
|
88
|
+
async release() {
|
|
89
|
+
await this.pool.end();
|
|
90
|
+
this._released = true;
|
|
91
|
+
}
|
|
92
|
+
async execSql(sql) {
|
|
93
|
+
return (await this.pool.query(sql))[0];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/db/getDbClient.ts
|
|
98
|
+
let client;
|
|
99
|
+
const getDbClient = (option, logger) => {
|
|
100
|
+
if (client && !client.isReleased()) return client;
|
|
101
|
+
client = new MysqlPoolClient({
|
|
102
|
+
...require_util.config().db,
|
|
103
|
+
...option
|
|
104
|
+
}, logger);
|
|
105
|
+
return client;
|
|
106
|
+
};
|
|
107
|
+
//#endregion
|
|
108
|
+
Object.defineProperty(exports, "DBClient", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function() {
|
|
111
|
+
return DBClient;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(exports, "MySqlTransaction", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function() {
|
|
117
|
+
return MySqlTransaction;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(exports, "formatQuery", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function() {
|
|
123
|
+
return formatQuery;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(exports, "getDbClient", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function() {
|
|
129
|
+
return getDbClient;
|
|
130
|
+
}
|
|
131
|
+
});
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_util = require("./util-
|
|
2
|
+
const require_util = require("./util-IRlTD1y7.cjs");
|
|
3
|
+
const require_getDbClient = require("./getDbClient-Dnkk-peb.cjs");
|
|
3
4
|
let mysql2_promise = require("mysql2/promise");
|
|
4
5
|
let sqlstring = require("sqlstring");
|
|
5
6
|
sqlstring = require_util.__toESM(sqlstring, 1);
|
|
6
7
|
//#region src/db/connectors/mysql/client.ts
|
|
7
|
-
var MysqlClient = class extends
|
|
8
|
+
var MysqlClient = class extends require_getDbClient.DBClient {
|
|
8
9
|
async release() {}
|
|
9
10
|
constructor(connectionOption, logger) {
|
|
10
11
|
super(logger);
|
|
@@ -19,7 +20,7 @@ var MysqlClient = class extends require_util.DBClient {
|
|
|
19
20
|
async transaction() {
|
|
20
21
|
const connection = await this.getConnection();
|
|
21
22
|
await connection.beginTransaction();
|
|
22
|
-
return new
|
|
23
|
+
return new require_getDbClient.MySqlTransaction(connection);
|
|
23
24
|
}
|
|
24
25
|
async execSql(sql) {
|
|
25
26
|
const connection = await this.getConnection();
|
|
@@ -147,7 +148,7 @@ const getLock = (lock) => {
|
|
|
147
148
|
};
|
|
148
149
|
const queryToSql = (query) => {
|
|
149
150
|
const select = query.select.map(Sql.select).join(", ");
|
|
150
|
-
const join = getJoin(query.from).map(Sql.join).join(" ");
|
|
151
|
+
const join = [...getJoin(query.from), ...query.join ?? []].map(Sql.join).join(" ");
|
|
151
152
|
const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
|
|
152
153
|
const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
|
|
153
154
|
const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
|
|
@@ -668,7 +669,7 @@ const createPagingFieldQuery = ({ baseTableName, fields, queryOption, pagingOpti
|
|
|
668
669
|
//#endregion
|
|
669
670
|
//#region src/runtime/sasatDBDatasource.ts
|
|
670
671
|
var SasatDBDatasource = class {
|
|
671
|
-
constructor(client =
|
|
672
|
+
constructor(client = require_getDbClient.getDbClient()) {
|
|
672
673
|
this.client = client;
|
|
673
674
|
}
|
|
674
675
|
async create(entity, option) {
|
|
@@ -815,11 +816,11 @@ exports.createTypeDef = createTypeDef;
|
|
|
815
816
|
exports.dateOffset = dateOffset;
|
|
816
817
|
exports.dateToDateString = dateToDateString;
|
|
817
818
|
exports.dateToDatetimeString = dateToDatetimeString;
|
|
818
|
-
exports.formatQuery =
|
|
819
|
+
exports.formatQuery = require_getDbClient.formatQuery;
|
|
819
820
|
exports.getCurrentDateTimeString = getCurrentDateTimeString;
|
|
820
821
|
exports.getDayRange = getDayRange;
|
|
821
822
|
exports.getDayRangeQExpr = getDayRangeQExpr;
|
|
822
|
-
exports.getDbClient =
|
|
823
|
+
exports.getDbClient = require_getDbClient.getDbClient;
|
|
823
824
|
exports.getTodayDateString = getTodayDateString;
|
|
824
825
|
exports.getTodayDateTimeString = getTodayDateTimeString;
|
|
825
826
|
exports.gqlResolveInfoToField = gqlResolveInfoToField;
|
package/dist/index.d.cts
CHANGED
|
@@ -53,6 +53,7 @@ type Query = {
|
|
|
53
53
|
limit?: number;
|
|
54
54
|
offset?: number;
|
|
55
55
|
lock?: LockMode;
|
|
56
|
+
join?: Join[];
|
|
56
57
|
};
|
|
57
58
|
type GroupByExpr = {
|
|
58
59
|
kind: QueryNodeKind.GroupBy;
|
|
@@ -262,6 +263,7 @@ type QueryOptions = {
|
|
|
262
263
|
limit?: number;
|
|
263
264
|
offset?: number;
|
|
264
265
|
lock?: LockMode;
|
|
266
|
+
join?: Join[];
|
|
265
267
|
};
|
|
266
268
|
declare abstract class SasatDBDatasource<Entity extends EntityType, Identifiable extends object, Creatable extends EntityType, Updatable extends Identifiable, EntityFields extends Fields<Entity>, QueryResult extends Partial<Entity> & Identifiable> implements Repository<Entity, Identifiable, Creatable, Updatable> {
|
|
267
269
|
protected client: SQLExecutor;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as setConfig, n as ComparisonOperators, t as ComparisonExpression$1 } from "./comparison-
|
|
2
|
-
import { a as SQLExecutor, i as SQLClient, n as DBClient, o as SQLTransaction, r as QueryResponse, s as SqlValueType, t as CommandResponse } from "./dbClient-
|
|
1
|
+
import { i as setConfig, n as ComparisonOperators, t as ComparisonExpression$1 } from "./comparison-CEpYTo3e.mjs";
|
|
2
|
+
import { a as SQLExecutor, i as SQLClient, n as DBClient, o as SQLTransaction, r as QueryResponse, s as SqlValueType, t as CommandResponse } from "./dbClient-TBYnlvTc.mjs";
|
|
3
3
|
import * as _$mysql2_promise0 from "mysql2/promise";
|
|
4
4
|
import { ConnectionOptions, PoolOptions } from "mysql2/promise";
|
|
5
5
|
import pkg from "sqlstring";
|
|
@@ -53,6 +53,7 @@ type Query = {
|
|
|
53
53
|
limit?: number;
|
|
54
54
|
offset?: number;
|
|
55
55
|
lock?: LockMode;
|
|
56
|
+
join?: Join[];
|
|
56
57
|
};
|
|
57
58
|
type GroupByExpr = {
|
|
58
59
|
kind: QueryNodeKind.GroupBy;
|
|
@@ -262,6 +263,7 @@ type QueryOptions = {
|
|
|
262
263
|
limit?: number;
|
|
263
264
|
offset?: number;
|
|
264
265
|
lock?: LockMode;
|
|
266
|
+
join?: Join[];
|
|
265
267
|
};
|
|
266
268
|
declare abstract class SasatDBDatasource<Entity extends EntityType, Identifiable extends object, Creatable extends EntityType, Updatable extends Identifiable, EntityFields extends Fields<Entity>, QueryResult extends Partial<Entity> & Identifiable> implements Repository<Entity, Identifiable, Creatable, Updatable> {
|
|
267
269
|
protected client: SQLExecutor;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as SqlString, c as setConfig, i as SasatError, m as assignDeep, n as pick, r as unique, t as nonNullable } from "./util-BcMcffJ8.mjs";
|
|
2
|
+
import { i as formatQuery, n as MySqlTransaction, r as DBClient, t as getDbClient } from "./getDbClient-CNcumqpO.mjs";
|
|
2
3
|
import { createConnection } from "mysql2/promise";
|
|
3
4
|
import * as SqlString$1 from "sqlstring";
|
|
4
5
|
//#region src/db/connectors/mysql/client.ts
|
|
@@ -145,7 +146,7 @@ const getLock = (lock) => {
|
|
|
145
146
|
};
|
|
146
147
|
const queryToSql = (query) => {
|
|
147
148
|
const select = query.select.map(Sql.select).join(", ");
|
|
148
|
-
const join = getJoin(query.from).map(Sql.join).join(" ");
|
|
149
|
+
const join = [...getJoin(query.from), ...query.join ?? []].map(Sql.join).join(" ");
|
|
149
150
|
const where = query.where ? " WHERE " + Sql.booleanValue(query.where) : "";
|
|
150
151
|
const groupBy = query.groupBy ? " GROUP BY" + query.groupBy.cols.map(Sql.value).join(",") : "";
|
|
151
152
|
const having = query.having ? "HAVING " + Sql.booleanValue(query.having) : "";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_util = require("./util-
|
|
2
|
-
const require_makeCondition = require("./makeCondition-
|
|
1
|
+
const require_util = require("./util-IRlTD1y7.cjs");
|
|
2
|
+
const require_makeCondition = require("./makeCondition-DljWZv_v.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
node_fs = require_util.__toESM(node_fs, 1);
|
|
5
5
|
let node_path = require("node:path");
|
|
@@ -1095,10 +1095,9 @@ const calcRunMigrationFileNames = (records) => {
|
|
|
1095
1095
|
});
|
|
1096
1096
|
return result;
|
|
1097
1097
|
};
|
|
1098
|
-
const getCurrentMigration = async (options) => {
|
|
1098
|
+
const getCurrentMigration = async (client, options) => {
|
|
1099
1099
|
const migrationTable = require_util.SqlString.escapeId(require_util.config().migration.table);
|
|
1100
1100
|
const files = getMigrationFileNames();
|
|
1101
|
-
const client = require_util.getDbClient();
|
|
1102
1101
|
const query = `CREATE TABLE IF NOT EXISTS ${migrationTable} (id int auto_increment primary key , name varchar(100) not null,direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)`;
|
|
1103
1102
|
if (!options.silent) {
|
|
1104
1103
|
Console.log(`creating migration table: ${migrationTable} :: ${Buffer.from(migrationTable).toString("base64")}`);
|
|
@@ -1108,7 +1107,6 @@ const getCurrentMigration = async (options) => {
|
|
|
1108
1107
|
const q = `SELECT name, direction FROM ${migrationTable} ORDER BY id ASC`;
|
|
1109
1108
|
if (!options.silent) Console.debug(q);
|
|
1110
1109
|
const result = await client.rawQuery(q);
|
|
1111
|
-
console.debug(result);
|
|
1112
1110
|
if (!result.length) return;
|
|
1113
1111
|
const runs = calcRunMigrationFileNames(result);
|
|
1114
1112
|
if (runs.length === 0) return;
|
|
@@ -1133,6 +1131,7 @@ const compileMigrationFiles = () => {
|
|
|
1133
1131
|
platform: "node",
|
|
1134
1132
|
format: "esm",
|
|
1135
1133
|
outExtension: { ".js": ".mjs" },
|
|
1134
|
+
external: ["server-only"],
|
|
1136
1135
|
banner: { js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
1137
1136
|
const require = topLevelCreateRequire(import.meta.url);
|
|
1138
1137
|
import { fileURLToPath as __topLevelFileURLToPath } from 'url';
|
|
@@ -3538,7 +3537,7 @@ const runMigration = async (client, store, migrationName, direction, options) =>
|
|
|
3538
3537
|
var MigrationController = class {
|
|
3539
3538
|
async migrate(client, options) {
|
|
3540
3539
|
const fileNames = getMigrationFileNames();
|
|
3541
|
-
const currentMigration = await getCurrentMigration(options);
|
|
3540
|
+
const currentMigration = await getCurrentMigration(client, options);
|
|
3542
3541
|
if (!options.silent) Console.log("--current migration--: " + currentMigration);
|
|
3543
3542
|
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
3544
3543
|
if (store.getUpdateConfig()) require_util.setConfig(store.getUpdateConfig());
|
|
@@ -3562,8 +3561,6 @@ const migrate = async (client, options) => {
|
|
|
3562
3561
|
if (!options.silent) Console.log("--migration started--");
|
|
3563
3562
|
try {
|
|
3564
3563
|
if (!options.skipBuild) await compileMigrationFiles();
|
|
3565
|
-
const conf = require_util.config();
|
|
3566
|
-
if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
|
|
3567
3564
|
const result = await new MigrationController().migrate(client, options);
|
|
3568
3565
|
current = result.currentMigration;
|
|
3569
3566
|
if (options.generateFiles) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { t as Conditions } from "./makeCondition-
|
|
1
|
+
import { a as SqlString, c as setConfig, d as writeCurrentSchema, f as writeFileIfNotExist, i as SasatError, l as mkDirIfNotExist, o as config, r as unique, t as nonNullable, u as readInitialSchema } from "./util-BcMcffJ8.mjs";
|
|
2
|
+
import { t as Conditions } from "./makeCondition-BQj-Av95.mjs";
|
|
3
3
|
import fs, { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import * as path$1 from "node:path";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1092,10 +1092,9 @@ const calcRunMigrationFileNames = (records) => {
|
|
|
1092
1092
|
});
|
|
1093
1093
|
return result;
|
|
1094
1094
|
};
|
|
1095
|
-
const getCurrentMigration = async (options) => {
|
|
1095
|
+
const getCurrentMigration = async (client, options) => {
|
|
1096
1096
|
const migrationTable = SqlString.escapeId(config().migration.table);
|
|
1097
1097
|
const files = getMigrationFileNames();
|
|
1098
|
-
const client = getDbClient();
|
|
1099
1098
|
const query = `CREATE TABLE IF NOT EXISTS ${migrationTable} (id int auto_increment primary key , name varchar(100) not null,direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)`;
|
|
1100
1099
|
if (!options.silent) {
|
|
1101
1100
|
Console.log(`creating migration table: ${migrationTable} :: ${Buffer.from(migrationTable).toString("base64")}`);
|
|
@@ -1105,7 +1104,6 @@ const getCurrentMigration = async (options) => {
|
|
|
1105
1104
|
const q = `SELECT name, direction FROM ${migrationTable} ORDER BY id ASC`;
|
|
1106
1105
|
if (!options.silent) Console.debug(q);
|
|
1107
1106
|
const result = await client.rawQuery(q);
|
|
1108
|
-
console.debug(result);
|
|
1109
1107
|
if (!result.length) return;
|
|
1110
1108
|
const runs = calcRunMigrationFileNames(result);
|
|
1111
1109
|
if (runs.length === 0) return;
|
|
@@ -1130,6 +1128,7 @@ const compileMigrationFiles = () => {
|
|
|
1130
1128
|
platform: "node",
|
|
1131
1129
|
format: "esm",
|
|
1132
1130
|
outExtension: { ".js": ".mjs" },
|
|
1131
|
+
external: ["server-only"],
|
|
1133
1132
|
banner: { js: `import { createRequire as topLevelCreateRequire } from 'module';
|
|
1134
1133
|
const require = topLevelCreateRequire(import.meta.url);
|
|
1135
1134
|
import { fileURLToPath as __topLevelFileURLToPath } from 'url';
|
|
@@ -3535,7 +3534,7 @@ const runMigration = async (client, store, migrationName, direction, options) =>
|
|
|
3535
3534
|
var MigrationController = class {
|
|
3536
3535
|
async migrate(client, options) {
|
|
3537
3536
|
const fileNames = getMigrationFileNames();
|
|
3538
|
-
const currentMigration = await getCurrentMigration(options);
|
|
3537
|
+
const currentMigration = await getCurrentMigration(client, options);
|
|
3539
3538
|
if (!options.silent) Console.log("--current migration--: " + currentMigration);
|
|
3540
3539
|
let store = await createCurrentMigrationDataStore(currentMigration);
|
|
3541
3540
|
if (store.getUpdateConfig()) setConfig(store.getUpdateConfig());
|
|
@@ -3559,8 +3558,6 @@ const migrate = async (client, options) => {
|
|
|
3559
3558
|
if (!options.silent) Console.log("--migration started--");
|
|
3560
3559
|
try {
|
|
3561
3560
|
if (!options.skipBuild) await compileMigrationFiles();
|
|
3562
|
-
const conf = config();
|
|
3563
|
-
if (conf.migration.db) setConfig({ db: conf.migration.db });
|
|
3564
3561
|
const result = await new MigrationController().migrate(client, options);
|
|
3565
3562
|
current = result.currentMigration;
|
|
3566
3563
|
if (options.generateFiles) {
|
package/dist/migration/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_makeCondition = require("../makeCondition-
|
|
2
|
+
const require_makeCondition = require("../makeCondition-DljWZv_v.cjs");
|
|
3
3
|
//#region src/migration/makeMutaion.ts
|
|
4
4
|
const formatSubscription = (subscription) => {
|
|
5
5
|
if (subscription === void 0 || subscription === false) return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as NestedPartial, n as ComparisonOperators, r as SasatConfig } from "../comparison-
|
|
2
|
-
import { s as SqlValueType } from "../dbClient-
|
|
1
|
+
import { a as NestedPartial, n as ComparisonOperators, r as SasatConfig } from "../comparison-CEpYTo3e.mjs";
|
|
2
|
+
import { s as SqlValueType } from "../dbClient-TBYnlvTc.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/migration/data/relation.d.ts
|
|
5
5
|
type Relation = "One" | "OneOrZero" | "Many";
|
package/dist/migration/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Conditions } from "../makeCondition-
|
|
1
|
+
import { t as Conditions } from "../makeCondition-BQj-Av95.mjs";
|
|
2
2
|
//#region src/migration/makeMutaion.ts
|
|
3
3
|
const formatSubscription = (subscription) => {
|
|
4
4
|
if (subscription === void 0 || subscription === false) return {
|
package/dist/testing/index.cjs
CHANGED
package/dist/testing/index.d.mts
CHANGED
package/dist/testing/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as migrate } from "../migrate-
|
|
1
|
+
import { t as migrate } from "../migrate-mh3DLqgw.mjs";
|
|
2
2
|
export { migrate };
|
|
@@ -2,7 +2,6 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import path, { join } from "node:path";
|
|
3
3
|
import { writeFile } from "node:fs/promises";
|
|
4
4
|
import yaml from "js-yaml";
|
|
5
|
-
import { createConnection, createPool } from "mysql2/promise";
|
|
6
5
|
import pkg from "sqlstring";
|
|
7
6
|
//#region src/util/assignDeep.ts
|
|
8
7
|
const assignDeep = (base, ...objects) => {
|
|
@@ -113,111 +112,6 @@ const SqlString = {
|
|
|
113
112
|
escapeId: (name) => escapeId(name)
|
|
114
113
|
};
|
|
115
114
|
//#endregion
|
|
116
|
-
//#region src/db/formatQuery.ts
|
|
117
|
-
const formatQuery = (str, ...params) => {
|
|
118
|
-
let ret = str[0];
|
|
119
|
-
for (let i = 0; i < params.length; i++) {
|
|
120
|
-
if (typeof params[i] === "function") ret += params[i]();
|
|
121
|
-
else if (Array.isArray(params[i])) ret += params[i].map((it) => SqlString.escape(it)).join(", ");
|
|
122
|
-
else ret += SqlString.escape(params[i]);
|
|
123
|
-
ret += str[i + 1];
|
|
124
|
-
}
|
|
125
|
-
return ret;
|
|
126
|
-
};
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region src/db/connectors/dbClient.ts
|
|
129
|
-
const noop = () => {};
|
|
130
|
-
var SQLClient = class {
|
|
131
|
-
constructor() {
|
|
132
|
-
this.logger = noop;
|
|
133
|
-
}
|
|
134
|
-
rawQuery(sql) {
|
|
135
|
-
this.logger(sql);
|
|
136
|
-
return this.execSql(sql);
|
|
137
|
-
}
|
|
138
|
-
rawCommand(sql) {
|
|
139
|
-
this.logger(sql);
|
|
140
|
-
return this.execSql(sql);
|
|
141
|
-
}
|
|
142
|
-
query(templateString, ...params) {
|
|
143
|
-
return this.rawQuery(formatQuery(templateString, ...params));
|
|
144
|
-
}
|
|
145
|
-
command(templateString, ...params) {
|
|
146
|
-
return this.rawCommand(formatQuery(templateString, ...params));
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
var SQLTransaction = class extends SQLClient {};
|
|
150
|
-
var DBClient = class extends SQLClient {
|
|
151
|
-
constructor(logger = noop) {
|
|
152
|
-
super();
|
|
153
|
-
this._released = false;
|
|
154
|
-
this.logger = logger;
|
|
155
|
-
}
|
|
156
|
-
isReleased() {
|
|
157
|
-
return this._released;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/db/connectors/mysql/transaction.ts
|
|
162
|
-
var MySqlTransaction = class extends SQLTransaction {
|
|
163
|
-
constructor(connection) {
|
|
164
|
-
super();
|
|
165
|
-
this.connection = connection;
|
|
166
|
-
}
|
|
167
|
-
async commit() {
|
|
168
|
-
const result = await this.connection.commit();
|
|
169
|
-
await this.connection.end();
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
async rollback() {
|
|
173
|
-
await this.connection.rollback();
|
|
174
|
-
await this.connection.end();
|
|
175
|
-
}
|
|
176
|
-
async execSql(sql) {
|
|
177
|
-
return (await this.connection.query(sql))[0];
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/db/connectors/mysql/poolClient.ts
|
|
182
|
-
var MysqlPoolClient = class extends DBClient {
|
|
183
|
-
constructor(poolOption, logger) {
|
|
184
|
-
super(logger);
|
|
185
|
-
this.poolOption = poolOption;
|
|
186
|
-
this.pool = createPool({
|
|
187
|
-
dateStrings: true,
|
|
188
|
-
...poolOption
|
|
189
|
-
});
|
|
190
|
-
this.release = this.release.bind(this);
|
|
191
|
-
}
|
|
192
|
-
async transaction() {
|
|
193
|
-
const connection = await createConnection({
|
|
194
|
-
...config().db,
|
|
195
|
-
dateStrings: true,
|
|
196
|
-
...this.poolOption
|
|
197
|
-
});
|
|
198
|
-
await connection.beginTransaction();
|
|
199
|
-
return new MySqlTransaction(connection);
|
|
200
|
-
}
|
|
201
|
-
async release() {
|
|
202
|
-
await this.pool.end();
|
|
203
|
-
this._released = true;
|
|
204
|
-
}
|
|
205
|
-
async execSql(sql) {
|
|
206
|
-
return (await this.pool.query(sql))[0];
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region src/db/getDbClient.ts
|
|
211
|
-
let client;
|
|
212
|
-
const getDbClient = (option, logger) => {
|
|
213
|
-
if (client && !client.isReleased()) return client;
|
|
214
|
-
client = new MysqlPoolClient({
|
|
215
|
-
...config().db,
|
|
216
|
-
...option
|
|
217
|
-
}, logger);
|
|
218
|
-
return client;
|
|
219
|
-
};
|
|
220
|
-
//#endregion
|
|
221
115
|
//#region src/error.ts
|
|
222
116
|
var SasatError = class extends Error {
|
|
223
117
|
constructor(message) {
|
|
@@ -236,4 +130,4 @@ const unique = (array) => {
|
|
|
236
130
|
};
|
|
237
131
|
const nonNullable = (value) => value != null;
|
|
238
132
|
//#endregion
|
|
239
|
-
export {
|
|
133
|
+
export { SqlString as a, setConfig as c, writeCurrentSchema as d, writeFileIfNotExist as f, SasatError as i, mkDirIfNotExist as l, assignDeep as m, pick as n, config as o, writeYmlFile as p, unique as r, defaultConf as s, nonNullable as t, readInitialSchema as u };
|
|
@@ -26,7 +26,6 @@ node_path = __toESM(node_path, 1);
|
|
|
26
26
|
let node_fs_promises = require("node:fs/promises");
|
|
27
27
|
let js_yaml = require("js-yaml");
|
|
28
28
|
js_yaml = __toESM(js_yaml, 1);
|
|
29
|
-
let mysql2_promise = require("mysql2/promise");
|
|
30
29
|
let sqlstring = require("sqlstring");
|
|
31
30
|
sqlstring = __toESM(sqlstring, 1);
|
|
32
31
|
//#region src/util/assignDeep.ts
|
|
@@ -138,111 +137,6 @@ const SqlString = {
|
|
|
138
137
|
escapeId: (name) => escapeId(name)
|
|
139
138
|
};
|
|
140
139
|
//#endregion
|
|
141
|
-
//#region src/db/formatQuery.ts
|
|
142
|
-
const formatQuery = (str, ...params) => {
|
|
143
|
-
let ret = str[0];
|
|
144
|
-
for (let i = 0; i < params.length; i++) {
|
|
145
|
-
if (typeof params[i] === "function") ret += params[i]();
|
|
146
|
-
else if (Array.isArray(params[i])) ret += params[i].map((it) => SqlString.escape(it)).join(", ");
|
|
147
|
-
else ret += SqlString.escape(params[i]);
|
|
148
|
-
ret += str[i + 1];
|
|
149
|
-
}
|
|
150
|
-
return ret;
|
|
151
|
-
};
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region src/db/connectors/dbClient.ts
|
|
154
|
-
const noop = () => {};
|
|
155
|
-
var SQLClient = class {
|
|
156
|
-
constructor() {
|
|
157
|
-
this.logger = noop;
|
|
158
|
-
}
|
|
159
|
-
rawQuery(sql) {
|
|
160
|
-
this.logger(sql);
|
|
161
|
-
return this.execSql(sql);
|
|
162
|
-
}
|
|
163
|
-
rawCommand(sql) {
|
|
164
|
-
this.logger(sql);
|
|
165
|
-
return this.execSql(sql);
|
|
166
|
-
}
|
|
167
|
-
query(templateString, ...params) {
|
|
168
|
-
return this.rawQuery(formatQuery(templateString, ...params));
|
|
169
|
-
}
|
|
170
|
-
command(templateString, ...params) {
|
|
171
|
-
return this.rawCommand(formatQuery(templateString, ...params));
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
var SQLTransaction = class extends SQLClient {};
|
|
175
|
-
var DBClient = class extends SQLClient {
|
|
176
|
-
constructor(logger = noop) {
|
|
177
|
-
super();
|
|
178
|
-
this._released = false;
|
|
179
|
-
this.logger = logger;
|
|
180
|
-
}
|
|
181
|
-
isReleased() {
|
|
182
|
-
return this._released;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/db/connectors/mysql/transaction.ts
|
|
187
|
-
var MySqlTransaction = class extends SQLTransaction {
|
|
188
|
-
constructor(connection) {
|
|
189
|
-
super();
|
|
190
|
-
this.connection = connection;
|
|
191
|
-
}
|
|
192
|
-
async commit() {
|
|
193
|
-
const result = await this.connection.commit();
|
|
194
|
-
await this.connection.end();
|
|
195
|
-
return result;
|
|
196
|
-
}
|
|
197
|
-
async rollback() {
|
|
198
|
-
await this.connection.rollback();
|
|
199
|
-
await this.connection.end();
|
|
200
|
-
}
|
|
201
|
-
async execSql(sql) {
|
|
202
|
-
return (await this.connection.query(sql))[0];
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/db/connectors/mysql/poolClient.ts
|
|
207
|
-
var MysqlPoolClient = class extends DBClient {
|
|
208
|
-
constructor(poolOption, logger) {
|
|
209
|
-
super(logger);
|
|
210
|
-
this.poolOption = poolOption;
|
|
211
|
-
this.pool = (0, mysql2_promise.createPool)({
|
|
212
|
-
dateStrings: true,
|
|
213
|
-
...poolOption
|
|
214
|
-
});
|
|
215
|
-
this.release = this.release.bind(this);
|
|
216
|
-
}
|
|
217
|
-
async transaction() {
|
|
218
|
-
const connection = await (0, mysql2_promise.createConnection)({
|
|
219
|
-
...config().db,
|
|
220
|
-
dateStrings: true,
|
|
221
|
-
...this.poolOption
|
|
222
|
-
});
|
|
223
|
-
await connection.beginTransaction();
|
|
224
|
-
return new MySqlTransaction(connection);
|
|
225
|
-
}
|
|
226
|
-
async release() {
|
|
227
|
-
await this.pool.end();
|
|
228
|
-
this._released = true;
|
|
229
|
-
}
|
|
230
|
-
async execSql(sql) {
|
|
231
|
-
return (await this.pool.query(sql))[0];
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region src/db/getDbClient.ts
|
|
236
|
-
let client;
|
|
237
|
-
const getDbClient = (option, logger) => {
|
|
238
|
-
if (client && !client.isReleased()) return client;
|
|
239
|
-
client = new MysqlPoolClient({
|
|
240
|
-
...config().db,
|
|
241
|
-
...option
|
|
242
|
-
}, logger);
|
|
243
|
-
return client;
|
|
244
|
-
};
|
|
245
|
-
//#endregion
|
|
246
140
|
//#region src/error.ts
|
|
247
141
|
var SasatError = class extends Error {
|
|
248
142
|
constructor(message) {
|
|
@@ -261,18 +155,6 @@ const unique = (array) => {
|
|
|
261
155
|
};
|
|
262
156
|
const nonNullable = (value) => value != null;
|
|
263
157
|
//#endregion
|
|
264
|
-
Object.defineProperty(exports, "DBClient", {
|
|
265
|
-
enumerable: true,
|
|
266
|
-
get: function() {
|
|
267
|
-
return DBClient;
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
Object.defineProperty(exports, "MySqlTransaction", {
|
|
271
|
-
enumerable: true,
|
|
272
|
-
get: function() {
|
|
273
|
-
return MySqlTransaction;
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
158
|
Object.defineProperty(exports, "SasatError", {
|
|
277
159
|
enumerable: true,
|
|
278
160
|
get: function() {
|
|
@@ -309,18 +191,6 @@ Object.defineProperty(exports, "defaultConf", {
|
|
|
309
191
|
return defaultConf;
|
|
310
192
|
}
|
|
311
193
|
});
|
|
312
|
-
Object.defineProperty(exports, "formatQuery", {
|
|
313
|
-
enumerable: true,
|
|
314
|
-
get: function() {
|
|
315
|
-
return formatQuery;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
Object.defineProperty(exports, "getDbClient", {
|
|
319
|
-
enumerable: true,
|
|
320
|
-
get: function() {
|
|
321
|
-
return getDbClient;
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
194
|
Object.defineProperty(exports, "mkDirIfNotExist", {
|
|
325
195
|
enumerable: true,
|
|
326
196
|
get: function() {
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|