sasat 0.22.8 → 0.22.9
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 +23 -5
- package/dist/cli/index.mjs +21 -3
- package/dist/comparison-Bkk-qNRi.d.cts +79 -0
- package/dist/comparison-HpKmxsjs.d.mts +79 -0
- package/dist/index-1a8KLRT7.d.mts +495 -0
- package/dist/index-lrk3IfPF.d.cts +495 -0
- package/dist/index.cjs +25 -829
- package/dist/index.d.cts +3 -495
- package/dist/index.d.mts +3 -495
- package/dist/index.mjs +2 -805
- package/dist/{migrate-mh3DLqgw.mjs → migrate-D-XR7Z0F.mjs} +90 -65
- package/dist/{migrate-COeYPag2.cjs → migrate-iJE4FjRh.cjs} +94 -63
- package/dist/migration/index.d.cts +2 -2
- package/dist/migration/index.d.mts +2 -2
- package/dist/src-CdwAbJV0.cjs +926 -0
- package/dist/src-DebKrtYl.mjs +806 -0
- package/dist/testing/index.cjs +70 -1
- package/dist/testing/index.d.cts +19 -2
- package/dist/testing/index.d.mts +19 -2
- package/dist/testing/index.mjs +69 -2
- package/dist/{util-IRlTD1y7.cjs → util-C5Jevn5B.cjs} +130 -0
- package/dist/{util-BcMcffJ8.mjs → util-Dkw5bD7a.mjs} +107 -1
- package/package.json +1 -1
- package/dist/comparison-CEpYTo3e.d.mts +0 -42
- package/dist/comparison-CIb9xu5T.d.cts +0 -42
- package/dist/dbClient-Bnk1JKBU.d.cts +0 -35
- package/dist/dbClient-TBYnlvTc.d.mts +0 -35
- package/dist/getDbClient-CNcumqpO.mjs +0 -108
- package/dist/getDbClient-Dnkk-peb.cjs +0 -131
package/dist/testing/index.cjs
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_util = require("../util-C5Jevn5B.cjs");
|
|
3
|
+
const require_src = require("../src-CdwAbJV0.cjs");
|
|
4
|
+
const require_migrate = require("../migrate-iJE4FjRh.cjs");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_util.__toESM(node_path, 1);
|
|
8
|
+
let node_crypto = require("node:crypto");
|
|
9
|
+
//#region src/testing/readTestMigration.ts
|
|
10
|
+
async function readTestMigration() {
|
|
11
|
+
let d = readTestMigFile();
|
|
12
|
+
if (!d) {
|
|
13
|
+
const conf = require_util.config();
|
|
14
|
+
if (conf.migration.db) require_util.setConfig({ db: conf.migration.db });
|
|
15
|
+
const client = new require_src.MysqlClient({ ...require_util.config().migration.db ?? require_util.config().db });
|
|
16
|
+
await require_migrate.generateTestMigrationFile(client).catch(async (e) => {
|
|
17
|
+
await client.release();
|
|
18
|
+
require_migrate.Console.error(e);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
21
|
+
await client.release();
|
|
22
|
+
d = readTestMigFile();
|
|
23
|
+
}
|
|
24
|
+
return JSON.parse(d.toString());
|
|
25
|
+
}
|
|
26
|
+
function readTestMigFile() {
|
|
27
|
+
return (0, node_fs.readFileSync)(node_path.default.join(require_util.config().migration.dir, "test.migration.json"));
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/testing/testDBClient.ts
|
|
31
|
+
var TestDBClient = class extends require_src.MysqlClient {
|
|
32
|
+
static async create(data, logger) {
|
|
33
|
+
const c = new require_src.MysqlClient({
|
|
34
|
+
host: data.host,
|
|
35
|
+
port: data.port,
|
|
36
|
+
user: data.user
|
|
37
|
+
});
|
|
38
|
+
await c.rawQuery(`CREATE DATABASE ${data.database}`);
|
|
39
|
+
await c.release();
|
|
40
|
+
return new this({
|
|
41
|
+
...data,
|
|
42
|
+
multipleStatements: true
|
|
43
|
+
}, logger);
|
|
44
|
+
}
|
|
45
|
+
constructor(connectionOption, logger) {
|
|
46
|
+
super(connectionOption, logger);
|
|
47
|
+
}
|
|
48
|
+
async release() {
|
|
49
|
+
await this.execSql(`DROP DATABASE ${this.connectionOption.database}`);
|
|
50
|
+
await super.release();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/testing/makeTestDB.ts
|
|
55
|
+
const S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
56
|
+
const N = 8;
|
|
57
|
+
async function makeTestDB(conf) {
|
|
58
|
+
const c = conf ?? require_util.config().db.testing ?? require_util.config().db;
|
|
59
|
+
const client = await TestDBClient.create({
|
|
60
|
+
host: c.host,
|
|
61
|
+
port: +c.port,
|
|
62
|
+
user: c.user,
|
|
63
|
+
password: c.password,
|
|
64
|
+
database: "sasat_test_" + Array.from((0, node_crypto.randomFillSync)(new Uint8Array(N))).map((n) => S[n % 62]).join("")
|
|
65
|
+
});
|
|
66
|
+
const migration = await readTestMigration();
|
|
67
|
+
await client.rawQuery(migration.join(";"));
|
|
68
|
+
return client;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.makeTestDB = makeTestDB;
|
|
3
72
|
exports.migrate = require_migrate.migrate;
|
package/dist/testing/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as SasatDBConfigBase, i as DBClient } from "../comparison-Bkk-qNRi.cjs";
|
|
2
|
+
import { z as MysqlClient } from "../index-lrk3IfPF.cjs";
|
|
2
3
|
|
|
3
4
|
//#region src/cli/commands/migrate.d.ts
|
|
4
5
|
type MigrateCommandOption = {
|
|
@@ -9,4 +10,20 @@ type MigrateCommandOption = {
|
|
|
9
10
|
};
|
|
10
11
|
declare const migrate: (client: DBClient, options: MigrateCommandOption) => Promise<void>;
|
|
11
12
|
//#endregion
|
|
12
|
-
|
|
13
|
+
//#region src/testing/testDBClient.d.ts
|
|
14
|
+
declare class TestDBClient extends MysqlClient {
|
|
15
|
+
static create(data: {
|
|
16
|
+
host: string;
|
|
17
|
+
port: number;
|
|
18
|
+
user: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
database: string;
|
|
21
|
+
}, logger?: (query: string) => void): Promise<TestDBClient>;
|
|
22
|
+
private constructor();
|
|
23
|
+
release(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/testing/makeTestDB.d.ts
|
|
27
|
+
declare function makeTestDB(conf?: SasatDBConfigBase): Promise<TestDBClient>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { makeTestDB, migrate };
|
package/dist/testing/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as SasatDBConfigBase, i as DBClient } from "../comparison-HpKmxsjs.mjs";
|
|
2
|
+
import { z as MysqlClient } from "../index-1a8KLRT7.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/cli/commands/migrate.d.ts
|
|
4
5
|
type MigrateCommandOption = {
|
|
@@ -9,4 +10,20 @@ type MigrateCommandOption = {
|
|
|
9
10
|
};
|
|
10
11
|
declare const migrate: (client: DBClient, options: MigrateCommandOption) => Promise<void>;
|
|
11
12
|
//#endregion
|
|
12
|
-
|
|
13
|
+
//#region src/testing/testDBClient.d.ts
|
|
14
|
+
declare class TestDBClient extends MysqlClient {
|
|
15
|
+
static create(data: {
|
|
16
|
+
host: string;
|
|
17
|
+
port: number;
|
|
18
|
+
user: string;
|
|
19
|
+
password?: string;
|
|
20
|
+
database: string;
|
|
21
|
+
}, logger?: (query: string) => void): Promise<TestDBClient>;
|
|
22
|
+
private constructor();
|
|
23
|
+
release(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/testing/makeTestDB.d.ts
|
|
27
|
+
declare function makeTestDB(conf?: SasatDBConfigBase): Promise<TestDBClient>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { makeTestDB, migrate };
|
package/dist/testing/index.mjs
CHANGED
|
@@ -1,2 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { f as setConfig, u as config } from "../util-Dkw5bD7a.mjs";
|
|
2
|
+
import { b as MysqlClient } from "../src-DebKrtYl.mjs";
|
|
3
|
+
import { p as Console, r as generateTestMigrationFile, t as migrate } from "../migrate-D-XR7Z0F.mjs";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { randomFillSync } from "node:crypto";
|
|
7
|
+
//#region src/testing/readTestMigration.ts
|
|
8
|
+
async function readTestMigration() {
|
|
9
|
+
let d = readTestMigFile();
|
|
10
|
+
if (!d) {
|
|
11
|
+
const conf = config();
|
|
12
|
+
if (conf.migration.db) setConfig({ db: conf.migration.db });
|
|
13
|
+
const client = new MysqlClient({ ...config().migration.db ?? config().db });
|
|
14
|
+
await generateTestMigrationFile(client).catch(async (e) => {
|
|
15
|
+
await client.release();
|
|
16
|
+
Console.error(e);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
|
19
|
+
await client.release();
|
|
20
|
+
d = readTestMigFile();
|
|
21
|
+
}
|
|
22
|
+
return JSON.parse(d.toString());
|
|
23
|
+
}
|
|
24
|
+
function readTestMigFile() {
|
|
25
|
+
return readFileSync(path.join(config().migration.dir, "test.migration.json"));
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/testing/testDBClient.ts
|
|
29
|
+
var TestDBClient = class extends MysqlClient {
|
|
30
|
+
static async create(data, logger) {
|
|
31
|
+
const c = new MysqlClient({
|
|
32
|
+
host: data.host,
|
|
33
|
+
port: data.port,
|
|
34
|
+
user: data.user
|
|
35
|
+
});
|
|
36
|
+
await c.rawQuery(`CREATE DATABASE ${data.database}`);
|
|
37
|
+
await c.release();
|
|
38
|
+
return new this({
|
|
39
|
+
...data,
|
|
40
|
+
multipleStatements: true
|
|
41
|
+
}, logger);
|
|
42
|
+
}
|
|
43
|
+
constructor(connectionOption, logger) {
|
|
44
|
+
super(connectionOption, logger);
|
|
45
|
+
}
|
|
46
|
+
async release() {
|
|
47
|
+
await this.execSql(`DROP DATABASE ${this.connectionOption.database}`);
|
|
48
|
+
await super.release();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/testing/makeTestDB.ts
|
|
53
|
+
const S = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
54
|
+
const N = 8;
|
|
55
|
+
async function makeTestDB(conf) {
|
|
56
|
+
const c = conf ?? config().db.testing ?? config().db;
|
|
57
|
+
const client = await TestDBClient.create({
|
|
58
|
+
host: c.host,
|
|
59
|
+
port: +c.port,
|
|
60
|
+
user: c.user,
|
|
61
|
+
password: c.password,
|
|
62
|
+
database: "sasat_test_" + Array.from(randomFillSync(new Uint8Array(N))).map((n) => S[n % 62]).join("")
|
|
63
|
+
});
|
|
64
|
+
const migration = await readTestMigration();
|
|
65
|
+
await client.rawQuery(migration.join(";"));
|
|
66
|
+
return client;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { makeTestDB, migrate };
|
|
@@ -26,6 +26,7 @@ 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");
|
|
29
30
|
let sqlstring = require("sqlstring");
|
|
30
31
|
sqlstring = __toESM(sqlstring, 1);
|
|
31
32
|
//#region src/util/assignDeep.ts
|
|
@@ -137,6 +138,111 @@ const SqlString = {
|
|
|
137
138
|
escapeId: (name) => escapeId(name)
|
|
138
139
|
};
|
|
139
140
|
//#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
|
|
140
246
|
//#region src/error.ts
|
|
141
247
|
var SasatError = class extends Error {
|
|
142
248
|
constructor(message) {
|
|
@@ -155,6 +261,18 @@ const unique = (array) => {
|
|
|
155
261
|
};
|
|
156
262
|
const nonNullable = (value) => value != null;
|
|
157
263
|
//#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
|
+
});
|
|
158
276
|
Object.defineProperty(exports, "SasatError", {
|
|
159
277
|
enumerable: true,
|
|
160
278
|
get: function() {
|
|
@@ -191,6 +309,18 @@ Object.defineProperty(exports, "defaultConf", {
|
|
|
191
309
|
return defaultConf;
|
|
192
310
|
}
|
|
193
311
|
});
|
|
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
|
+
});
|
|
194
324
|
Object.defineProperty(exports, "mkDirIfNotExist", {
|
|
195
325
|
enumerable: true,
|
|
196
326
|
get: function() {
|
|
@@ -2,6 +2,7 @@ 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";
|
|
5
6
|
import pkg from "sqlstring";
|
|
6
7
|
//#region src/util/assignDeep.ts
|
|
7
8
|
const assignDeep = (base, ...objects) => {
|
|
@@ -112,6 +113,111 @@ const SqlString = {
|
|
|
112
113
|
escapeId: (name) => escapeId(name)
|
|
113
114
|
};
|
|
114
115
|
//#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
|
|
115
221
|
//#region src/error.ts
|
|
116
222
|
var SasatError = class extends Error {
|
|
117
223
|
constructor(message) {
|
|
@@ -130,4 +236,4 @@ const unique = (array) => {
|
|
|
130
236
|
};
|
|
131
237
|
const nonNullable = (value) => value != null;
|
|
132
238
|
//#endregion
|
|
133
|
-
export {
|
|
239
|
+
export { writeYmlFile as _, getDbClient as a, formatQuery as c, defaultConf as d, setConfig as f, writeFileIfNotExist as g, writeCurrentSchema as h, SasatError as i, SqlString as l, readInitialSchema as m, pick as n, MySqlTransaction as o, mkDirIfNotExist as p, unique as r, DBClient as s, nonNullable as t, config as u, assignDeep as v };
|
package/package.json
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//#region src/util/type.d.ts
|
|
2
|
-
type NestedPartial<T> = { [K in keyof T]?: T[K] extends Array<infer R> ? Array<NestedPartial<R>> : NestedPartial<T[K]> };
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/config/config.d.ts
|
|
5
|
-
interface SasatConfigDb {
|
|
6
|
-
host: string;
|
|
7
|
-
port: number;
|
|
8
|
-
user: string;
|
|
9
|
-
password?: string;
|
|
10
|
-
database: string;
|
|
11
|
-
ssl?: {
|
|
12
|
-
ca?: string[];
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
interface SasatConfigMigration {
|
|
16
|
-
table: string;
|
|
17
|
-
dir: string;
|
|
18
|
-
out: string;
|
|
19
|
-
target?: string;
|
|
20
|
-
db?: SasatConfigDb;
|
|
21
|
-
}
|
|
22
|
-
interface SasatConfigGenerator {
|
|
23
|
-
addJsExtToImportStatement: boolean;
|
|
24
|
-
gql: {
|
|
25
|
-
subscription: boolean;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
interface SasatConfig {
|
|
29
|
-
db: SasatConfigDb;
|
|
30
|
-
migration: SasatConfigMigration;
|
|
31
|
-
generator: SasatConfigGenerator;
|
|
32
|
-
}
|
|
33
|
-
declare function setConfig(update: NestedPartial<SasatConfig>): SasatConfig;
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/db/sql/expression/comparison.d.ts
|
|
36
|
-
type ComparisonOperators = "=" | ">" | "<" | ">=" | "<=" | "<>";
|
|
37
|
-
type AndOr = "AND" | "OR";
|
|
38
|
-
type ComparisonExpression<T> = Partial<{ [P in keyof T]: T[P] | [ComparisonOperators | "LIKE" | "NOT LIKE", T[P]] | ["BETWEEN", T[P], T[P]] | ["IN", ...T[P][]] | ["IS NULL"] | ["IS NOT NULL"] }> & {
|
|
39
|
-
__type?: AndOr;
|
|
40
|
-
};
|
|
41
|
-
//#endregion
|
|
42
|
-
export { NestedPartial as a, setConfig as i, ComparisonOperators as n, SasatConfig as r, ComparisonExpression as t };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//#region src/util/type.d.ts
|
|
2
|
-
type NestedPartial<T> = { [K in keyof T]?: T[K] extends Array<infer R> ? Array<NestedPartial<R>> : NestedPartial<T[K]> };
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/config/config.d.ts
|
|
5
|
-
interface SasatConfigDb {
|
|
6
|
-
host: string;
|
|
7
|
-
port: number;
|
|
8
|
-
user: string;
|
|
9
|
-
password?: string;
|
|
10
|
-
database: string;
|
|
11
|
-
ssl?: {
|
|
12
|
-
ca?: string[];
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
interface SasatConfigMigration {
|
|
16
|
-
table: string;
|
|
17
|
-
dir: string;
|
|
18
|
-
out: string;
|
|
19
|
-
target?: string;
|
|
20
|
-
db?: SasatConfigDb;
|
|
21
|
-
}
|
|
22
|
-
interface SasatConfigGenerator {
|
|
23
|
-
addJsExtToImportStatement: boolean;
|
|
24
|
-
gql: {
|
|
25
|
-
subscription: boolean;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
interface SasatConfig {
|
|
29
|
-
db: SasatConfigDb;
|
|
30
|
-
migration: SasatConfigMigration;
|
|
31
|
-
generator: SasatConfigGenerator;
|
|
32
|
-
}
|
|
33
|
-
declare function setConfig(update: NestedPartial<SasatConfig>): SasatConfig;
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/db/sql/expression/comparison.d.ts
|
|
36
|
-
type ComparisonOperators = "=" | ">" | "<" | ">=" | "<=" | "<>";
|
|
37
|
-
type AndOr = "AND" | "OR";
|
|
38
|
-
type ComparisonExpression<T> = Partial<{ [P in keyof T]: T[P] | [ComparisonOperators | "LIKE" | "NOT LIKE", T[P]] | ["BETWEEN", T[P], T[P]] | ["IN", ...T[P][]] | ["IS NULL"] | ["IS NOT NULL"] }> & {
|
|
39
|
-
__type?: AndOr;
|
|
40
|
-
};
|
|
41
|
-
//#endregion
|
|
42
|
-
export { NestedPartial as a, setConfig as i, ComparisonOperators as n, SasatConfig as r, ComparisonExpression as t };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//#region src/db/connectors/dbClient.d.ts
|
|
2
|
-
type QueryResponse = Array<{
|
|
3
|
-
[key: string]: SqlValueType;
|
|
4
|
-
}>;
|
|
5
|
-
interface CommandResponse {
|
|
6
|
-
insertId: number;
|
|
7
|
-
affectedRows: number;
|
|
8
|
-
changedRows: number;
|
|
9
|
-
}
|
|
10
|
-
type SqlValueType = string | number | boolean | null;
|
|
11
|
-
interface SQLExecutor {
|
|
12
|
-
rawQuery(sql: string): Promise<QueryResponse>;
|
|
13
|
-
rawCommand(sql: string): Promise<CommandResponse>;
|
|
14
|
-
}
|
|
15
|
-
declare abstract class SQLClient implements SQLExecutor {
|
|
16
|
-
protected logger: (query: string) => void;
|
|
17
|
-
rawQuery(sql: string): Promise<QueryResponse>;
|
|
18
|
-
rawCommand(sql: string): Promise<CommandResponse>;
|
|
19
|
-
query(templateString: TemplateStringsArray, ...params: any[]): Promise<QueryResponse>;
|
|
20
|
-
command(templateString: TemplateStringsArray, ...params: any[]): Promise<CommandResponse>;
|
|
21
|
-
protected abstract execSql(sql: string): Promise<QueryResponse | CommandResponse>;
|
|
22
|
-
}
|
|
23
|
-
declare abstract class SQLTransaction extends SQLClient {
|
|
24
|
-
abstract commit(): Promise<void>;
|
|
25
|
-
abstract rollback(): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
declare abstract class DBClient extends SQLClient {
|
|
28
|
-
protected _released: boolean;
|
|
29
|
-
protected constructor(logger?: (query: string) => void);
|
|
30
|
-
isReleased(): boolean;
|
|
31
|
-
abstract transaction(): Promise<SQLTransaction>;
|
|
32
|
-
abstract release(): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { SQLExecutor as a, SQLClient as i, DBClient as n, SQLTransaction as o, QueryResponse as r, SqlValueType as s, CommandResponse as t };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//#region src/db/connectors/dbClient.d.ts
|
|
2
|
-
type QueryResponse = Array<{
|
|
3
|
-
[key: string]: SqlValueType;
|
|
4
|
-
}>;
|
|
5
|
-
interface CommandResponse {
|
|
6
|
-
insertId: number;
|
|
7
|
-
affectedRows: number;
|
|
8
|
-
changedRows: number;
|
|
9
|
-
}
|
|
10
|
-
type SqlValueType = string | number | boolean | null;
|
|
11
|
-
interface SQLExecutor {
|
|
12
|
-
rawQuery(sql: string): Promise<QueryResponse>;
|
|
13
|
-
rawCommand(sql: string): Promise<CommandResponse>;
|
|
14
|
-
}
|
|
15
|
-
declare abstract class SQLClient implements SQLExecutor {
|
|
16
|
-
protected logger: (query: string) => void;
|
|
17
|
-
rawQuery(sql: string): Promise<QueryResponse>;
|
|
18
|
-
rawCommand(sql: string): Promise<CommandResponse>;
|
|
19
|
-
query(templateString: TemplateStringsArray, ...params: any[]): Promise<QueryResponse>;
|
|
20
|
-
command(templateString: TemplateStringsArray, ...params: any[]): Promise<CommandResponse>;
|
|
21
|
-
protected abstract execSql(sql: string): Promise<QueryResponse | CommandResponse>;
|
|
22
|
-
}
|
|
23
|
-
declare abstract class SQLTransaction extends SQLClient {
|
|
24
|
-
abstract commit(): Promise<void>;
|
|
25
|
-
abstract rollback(): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
declare abstract class DBClient extends SQLClient {
|
|
28
|
-
protected _released: boolean;
|
|
29
|
-
protected constructor(logger?: (query: string) => void);
|
|
30
|
-
isReleased(): boolean;
|
|
31
|
-
abstract transaction(): Promise<SQLTransaction>;
|
|
32
|
-
abstract release(): Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { SQLExecutor as a, SQLClient as i, DBClient as n, SQLTransaction as o, QueryResponse as r, SqlValueType as s, CommandResponse as t };
|