baja-lite 1.0.4 → 1.0.5
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/cjs/boot-remote.d.ts +2 -0
- package/cjs/boot-remote.js +35 -0
- package/cjs/boot.d.ts +2 -0
- package/cjs/boot.js +152 -0
- package/cjs/code.d.ts +1 -0
- package/cjs/code.js +345 -1
- package/cjs/convert-xml.d.ts +10 -0
- package/cjs/convert-xml.js +413 -0
- package/cjs/enum.d.ts +10 -0
- package/cjs/enum.js +32 -0
- package/cjs/error.js +1 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +2 -0
- package/cjs/object.d.ts +7 -1
- package/cjs/object.js +36 -2
- package/cjs/sql.d.ts +405 -148
- package/cjs/sql.js +1229 -861
- package/cjs/sqlite.d.ts +38 -0
- package/cjs/sqlite.js +194 -0
- package/cjs/test-mysql.d.ts +1 -1
- package/cjs/test-mysql.js +72 -63
- package/cjs/test-sqlite.d.ts +1 -1
- package/cjs/test-sqlite.js +3 -1
- package/cjs/test-xml.d.ts +1 -0
- package/cjs/test-xml.js +75 -0
- package/es/boot-remote.d.ts +2 -0
- package/es/boot-remote.js +31 -0
- package/es/boot.d.ts +2 -0
- package/es/boot.js +125 -0
- package/es/code.d.ts +1 -0
- package/es/code.js +341 -2
- package/es/convert-xml.d.ts +10 -0
- package/es/convert-xml.js +409 -0
- package/es/enum.d.ts +10 -0
- package/es/enum.js +28 -0
- package/es/error.js +1 -1
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/object.d.ts +7 -1
- package/es/object.js +28 -1
- package/es/sql.d.ts +405 -148
- package/es/sql.js +1099 -735
- package/es/sqlite.d.ts +38 -0
- package/es/sqlite.js +164 -0
- package/es/test-mysql.d.ts +1 -1
- package/es/test-mysql.js +72 -63
- package/es/test-sqlite.d.ts +1 -1
- package/es/test-sqlite.js +3 -1
- package/es/test-xml.d.ts +1 -0
- package/es/test-xml.js +70 -0
- package/package.json +10 -7
- package/src/boot-remote.ts +31 -0
- package/src/boot.ts +129 -0
- package/src/code.ts +326 -1
- package/src/convert-xml.ts +461 -0
- package/src/enum.ts +31 -0
- package/src/error.ts +1 -1
- package/src/index.ts +3 -1
- package/src/object.ts +47 -14
- package/src/sql.ts +1145 -787
- package/src/sqlite.ts +161 -0
- package/src/test-mysql.ts +72 -63
- package/src/test-sqlite.ts +3 -1
- package/src/test-xml.ts +70 -0
- package/cjs/constant.d.ts +0 -13
- package/cjs/constant.js +0 -19
- package/cjs/redis.d.ts +0 -0
- package/cjs/redis.js +0 -1
- package/es/constant.d.ts +0 -13
- package/es/constant.js +0 -16
- package/es/redis.d.ts +0 -0
- package/es/redis.js +0 -1
- package/src/constant.ts +0 -14
- package/src/redis.ts +0 -0
package/cjs/sql.js
CHANGED
|
@@ -35,10 +35,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
var _a, _b, _c;
|
|
38
|
-
var _d, _e, _f;
|
|
38
|
+
var _d, _e, _f, _g;
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.
|
|
41
|
-
require("reflect-metadata");
|
|
40
|
+
exports.MethodCache = exports.excuteWithCache = exports.clearMethodCache = exports.MethodLock = exports.excuteWithLock = exports.GetRedisLock = exports.getRedisDB = exports.SqlService = exports.DeclareService = exports.DeclareClass = exports.DB = exports.Field = exports.SqlCache = exports.SqliteRemote = exports.SqliteRemoteConnection = exports.Sqlite = exports.Mysql = exports._defOption = exports.SqliteMemory = exports.ColumnMode = exports.SqlType = exports.SelectResult = exports.TemplateResult = exports.SelectMode = exports.DeleteMode = exports.InsertMode = exports.SyncMode = exports.DBType = exports.logger = exports._fs = exports._path = exports._EventBus = exports._GlobalSqlOption = exports._Hump = exports._primaryDB = exports._dao = exports._sqlCache = void 0;
|
|
42
41
|
const error_1 = require("./error");
|
|
43
42
|
const tslib_1 = __importDefault(require("tslib"));
|
|
44
43
|
const sqlstring_1 = __importDefault(require("sqlstring"));
|
|
@@ -48,9 +47,16 @@ const pino_1 = __importDefault(require("pino"));
|
|
|
48
47
|
const fn_1 = require("./fn");
|
|
49
48
|
const math_1 = require("./math");
|
|
50
49
|
const mustache_1 = __importDefault(require("mustache"));
|
|
50
|
+
const object_1 = require("./object");
|
|
51
|
+
const sql_formatter_1 = require("sql-formatter");
|
|
52
|
+
const html_parse_stringify_1 = __importDefault(require("html-parse-stringify"));
|
|
53
|
+
const convert_xml_1 = require("./convert-xml");
|
|
51
54
|
// #region 常量
|
|
52
55
|
const _daoDBName = Symbol('dbName');
|
|
53
56
|
const _tableName = Symbol('tableName');
|
|
57
|
+
const _className = Symbol('className');
|
|
58
|
+
const _ClassName = Symbol('ClassName');
|
|
59
|
+
const _vueName = Symbol('vueName');
|
|
54
60
|
const _ids = Symbol('ids');
|
|
55
61
|
const _columns = Symbol('columns');
|
|
56
62
|
const _columnsNoId = Symbol('columnsNoId');
|
|
@@ -60,9 +66,9 @@ const _deleteState = Symbol('deleteState');
|
|
|
60
66
|
const _transformer = Symbol('transformer');
|
|
61
67
|
const _index = Symbol('index');
|
|
62
68
|
const _def = Symbol('def');
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
exports._sqlCache = Symbol('sqlMap');
|
|
70
|
+
exports._dao = Symbol('dao');
|
|
71
|
+
exports._primaryDB = Symbol('primaryDB');
|
|
66
72
|
const _dbType = Symbol('dbType');
|
|
67
73
|
const _sqlite_version = Symbol('sqlite_version');
|
|
68
74
|
const _daoConnection = Symbol('daoConnection');
|
|
@@ -70,16 +76,17 @@ const _inTransaction = Symbol('inTransaction');
|
|
|
70
76
|
const _daoDB = Symbol('daoDB');
|
|
71
77
|
const _sqliteRemoteName = Symbol('sqliteRemoteName');
|
|
72
78
|
const _SqlOption = Symbol('SqlOption');
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
exports._Hump = Symbol('Hump');
|
|
80
|
+
exports._GlobalSqlOption = Symbol('GlobalSqlOption');
|
|
81
|
+
exports._EventBus = Symbol('EventBus');
|
|
82
|
+
exports._path = Symbol('path');
|
|
83
|
+
exports._fs = Symbol('fs');
|
|
84
|
+
exports.logger = process.env['NODE_ENV'] !== 'production' ? (0, pino_1.default)({
|
|
78
85
|
name: 'sql',
|
|
79
86
|
transport: {
|
|
80
87
|
target: 'pino-pretty'
|
|
81
88
|
}
|
|
82
|
-
});
|
|
89
|
+
}) : (0, pino_1.default)({ name: 'sql' });
|
|
83
90
|
// #endregion
|
|
84
91
|
// #region 可选配置
|
|
85
92
|
var DBType;
|
|
@@ -216,8 +223,13 @@ var SqlType;
|
|
|
216
223
|
SqlType[SqlType["multipolygon"] = 32] = "multipolygon";
|
|
217
224
|
SqlType[SqlType["geometrycollection"] = 33] = "geometrycollection";
|
|
218
225
|
})(SqlType || (exports.SqlType = SqlType = {}));
|
|
226
|
+
var ColumnMode;
|
|
227
|
+
(function (ColumnMode) {
|
|
228
|
+
ColumnMode[ColumnMode["NONE"] = 0] = "NONE";
|
|
229
|
+
ColumnMode[ColumnMode["HUMP"] = 1] = "HUMP";
|
|
230
|
+
})(ColumnMode || (exports.ColumnMode = ColumnMode = {}));
|
|
219
231
|
exports.SqliteMemory = ':memory:';
|
|
220
|
-
|
|
232
|
+
exports._defOption = {
|
|
221
233
|
maxDeal: 500,
|
|
222
234
|
skipUndefined: true,
|
|
223
235
|
skipNull: true,
|
|
@@ -230,30 +242,30 @@ class MysqlConnection {
|
|
|
230
242
|
this[_daoConnection] = conn;
|
|
231
243
|
}
|
|
232
244
|
execute(sync, sql, params) {
|
|
233
|
-
logger.debug(sql, params ?? '');
|
|
245
|
+
exports.logger.debug(sql, params ?? '');
|
|
234
246
|
if (!sql) {
|
|
235
247
|
return { affectedRows: 0, insertId: 0n };
|
|
236
248
|
}
|
|
237
249
|
;
|
|
238
250
|
if (sync === SyncMode.Sync) {
|
|
239
|
-
logger.warn('MYSQL not suppouted sync mode');
|
|
251
|
+
exports.logger.warn('MYSQL not suppouted sync mode');
|
|
240
252
|
return { affectedRows: 0, insertId: 0n };
|
|
241
253
|
}
|
|
242
254
|
;
|
|
243
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
244
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
255
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
256
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
245
257
|
}
|
|
246
258
|
return new Promise(async (resolve, reject) => {
|
|
247
259
|
try {
|
|
248
260
|
const [_result] = await this[_daoConnection].execute(sql, params);
|
|
249
261
|
const result = _result;
|
|
250
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
251
|
-
logger.trace(result);
|
|
262
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
263
|
+
exports.logger.trace(result);
|
|
252
264
|
}
|
|
253
265
|
resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
|
|
254
266
|
}
|
|
255
267
|
catch (error) {
|
|
256
|
-
logger.error(`
|
|
268
|
+
exports.logger.error(`
|
|
257
269
|
error: ${error},
|
|
258
270
|
sql: ${sql},
|
|
259
271
|
params: ${params}
|
|
@@ -263,18 +275,18 @@ class MysqlConnection {
|
|
|
263
275
|
});
|
|
264
276
|
}
|
|
265
277
|
pluck(sync, sql, params) {
|
|
266
|
-
logger.debug(sql, params ?? '');
|
|
278
|
+
exports.logger.debug(sql, params ?? '');
|
|
267
279
|
if (!sql) {
|
|
268
280
|
return null;
|
|
269
281
|
}
|
|
270
282
|
;
|
|
271
283
|
if (sync === SyncMode.Sync) {
|
|
272
|
-
logger.warn('MYSQL not suppouted sync mode');
|
|
284
|
+
exports.logger.warn('MYSQL not suppouted sync mode');
|
|
273
285
|
return null;
|
|
274
286
|
}
|
|
275
287
|
;
|
|
276
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
277
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
288
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
289
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
278
290
|
}
|
|
279
291
|
return new Promise(async (resolve, reject) => {
|
|
280
292
|
try {
|
|
@@ -289,7 +301,7 @@ class MysqlConnection {
|
|
|
289
301
|
resolve(null);
|
|
290
302
|
}
|
|
291
303
|
catch (error) {
|
|
292
|
-
logger.error(`
|
|
304
|
+
exports.logger.error(`
|
|
293
305
|
error: ${error},
|
|
294
306
|
sql: ${sql},
|
|
295
307
|
params: ${params}
|
|
@@ -299,31 +311,31 @@ class MysqlConnection {
|
|
|
299
311
|
});
|
|
300
312
|
}
|
|
301
313
|
get(sync, sql, params) {
|
|
302
|
-
logger.debug(sql, params ?? '');
|
|
314
|
+
exports.logger.debug(sql, params ?? '');
|
|
303
315
|
if (!sql) {
|
|
304
316
|
return null;
|
|
305
317
|
}
|
|
306
318
|
;
|
|
307
319
|
if (sync === SyncMode.Sync) {
|
|
308
|
-
logger.warn('MYSQL not suppouted sync mode');
|
|
320
|
+
exports.logger.warn('MYSQL not suppouted sync mode');
|
|
309
321
|
return null;
|
|
310
322
|
}
|
|
311
323
|
;
|
|
312
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
313
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
324
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
325
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
314
326
|
}
|
|
315
327
|
return new Promise(async (resolve, reject) => {
|
|
316
328
|
try {
|
|
317
329
|
const [result] = await this[_daoConnection].query(sql, params);
|
|
318
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
319
|
-
logger.trace(result);
|
|
330
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
331
|
+
exports.logger.trace(result);
|
|
320
332
|
}
|
|
321
333
|
if (result && result[0])
|
|
322
334
|
resolve(result[0]);
|
|
323
335
|
resolve(null);
|
|
324
336
|
}
|
|
325
337
|
catch (error) {
|
|
326
|
-
logger.error(`
|
|
338
|
+
exports.logger.error(`
|
|
327
339
|
error: ${error},
|
|
328
340
|
sql: ${sql},
|
|
329
341
|
params: ${params}
|
|
@@ -333,31 +345,31 @@ class MysqlConnection {
|
|
|
333
345
|
});
|
|
334
346
|
}
|
|
335
347
|
raw(sync, sql, params) {
|
|
336
|
-
logger.debug(sql, params ?? '');
|
|
348
|
+
exports.logger.debug(sql, params ?? '');
|
|
337
349
|
if (!sql) {
|
|
338
350
|
return [];
|
|
339
351
|
}
|
|
340
352
|
;
|
|
341
353
|
if (sync === SyncMode.Sync) {
|
|
342
|
-
logger.warn('MYSQL not suppouted sync mode');
|
|
354
|
+
exports.logger.warn('MYSQL not suppouted sync mode');
|
|
343
355
|
return [];
|
|
344
356
|
}
|
|
345
357
|
;
|
|
346
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
347
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
358
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
359
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
348
360
|
}
|
|
349
361
|
return new Promise(async (resolve, reject) => {
|
|
350
362
|
try {
|
|
351
363
|
const [result] = await this[_daoConnection].query(sql, params);
|
|
352
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
353
|
-
logger.trace(result);
|
|
364
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
365
|
+
exports.logger.trace(result);
|
|
354
366
|
}
|
|
355
367
|
if (result)
|
|
356
368
|
resolve(result.map((i) => Object.values(i)[0]));
|
|
357
369
|
resolve([]);
|
|
358
370
|
}
|
|
359
371
|
catch (error) {
|
|
360
|
-
logger.error(`
|
|
372
|
+
exports.logger.error(`
|
|
361
373
|
error: ${error},
|
|
362
374
|
sql: ${sql},
|
|
363
375
|
params: ${params}
|
|
@@ -367,29 +379,29 @@ class MysqlConnection {
|
|
|
367
379
|
});
|
|
368
380
|
}
|
|
369
381
|
query(sync, sql, params) {
|
|
370
|
-
logger.debug(sql, params ?? '');
|
|
382
|
+
exports.logger.debug(sql, params ?? '');
|
|
371
383
|
if (!sql) {
|
|
372
384
|
return [];
|
|
373
385
|
}
|
|
374
386
|
;
|
|
375
387
|
if (sync === SyncMode.Sync) {
|
|
376
|
-
logger.warn('MYSQL not suppouted sync mode');
|
|
388
|
+
exports.logger.warn('MYSQL not suppouted sync mode');
|
|
377
389
|
return [];
|
|
378
390
|
}
|
|
379
391
|
;
|
|
380
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
381
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
392
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
393
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
382
394
|
}
|
|
383
395
|
return new Promise(async (resolve, reject) => {
|
|
384
396
|
try {
|
|
385
397
|
const [result] = await this[_daoConnection].query(sql, params);
|
|
386
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
387
|
-
logger.trace(result);
|
|
398
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
399
|
+
exports.logger.trace(result);
|
|
388
400
|
}
|
|
389
401
|
resolve(result);
|
|
390
402
|
}
|
|
391
403
|
catch (error) {
|
|
392
|
-
logger.error(`
|
|
404
|
+
exports.logger.error(`
|
|
393
405
|
error: ${error},
|
|
394
406
|
sql: ${sql},
|
|
395
407
|
params: ${params}
|
|
@@ -416,14 +428,14 @@ class Mysql {
|
|
|
416
428
|
}
|
|
417
429
|
createConnection(sync) {
|
|
418
430
|
if (sync === SyncMode.Sync) {
|
|
419
|
-
logger.error('MYSQL not suppouted sync mode');
|
|
431
|
+
exports.logger.error('MYSQL not suppouted sync mode');
|
|
420
432
|
return null;
|
|
421
433
|
}
|
|
422
434
|
;
|
|
423
435
|
return new Promise(async (resolve, reject) => {
|
|
424
436
|
try {
|
|
425
437
|
const connection = await this[_daoDB].getConnection();
|
|
426
|
-
logger.debug('create new!');
|
|
438
|
+
exports.logger.debug('create new connection!');
|
|
427
439
|
resolve(new MysqlConnection(connection));
|
|
428
440
|
}
|
|
429
441
|
catch (error) {
|
|
@@ -433,7 +445,7 @@ class Mysql {
|
|
|
433
445
|
}
|
|
434
446
|
transaction(sync, fn, conn) {
|
|
435
447
|
if (sync === SyncMode.Sync) {
|
|
436
|
-
logger.warn('MYSQL not suppouted sync mode');
|
|
448
|
+
exports.logger.warn('MYSQL not suppouted sync mode');
|
|
437
449
|
return null;
|
|
438
450
|
}
|
|
439
451
|
;
|
|
@@ -446,27 +458,27 @@ class Mysql {
|
|
|
446
458
|
}
|
|
447
459
|
if (conn?.[_inTransaction] !== true) {
|
|
448
460
|
needCommit = true;
|
|
449
|
-
logger.debug('beginTransaction begin!');
|
|
461
|
+
exports.logger.debug('beginTransaction begin!');
|
|
450
462
|
await conn[_daoConnection].beginTransaction();
|
|
451
|
-
logger.debug('beginTransaction end!');
|
|
463
|
+
exports.logger.debug('beginTransaction end!');
|
|
452
464
|
}
|
|
453
465
|
conn[_inTransaction] = true;
|
|
454
466
|
try {
|
|
455
467
|
const result = await fn(conn);
|
|
456
468
|
if (needCommit === true) {
|
|
457
|
-
logger.debug('commit begin!');
|
|
469
|
+
exports.logger.debug('commit begin!');
|
|
458
470
|
await conn[_daoConnection].commit();
|
|
459
471
|
conn[_inTransaction] = false;
|
|
460
|
-
logger.debug('commit end!');
|
|
472
|
+
exports.logger.debug('commit end!');
|
|
461
473
|
}
|
|
462
474
|
resolve(result);
|
|
463
475
|
}
|
|
464
476
|
catch (error) {
|
|
465
|
-
logger.debug('rollback begin!');
|
|
477
|
+
exports.logger.debug('rollback begin!');
|
|
466
478
|
await conn[_daoConnection].rollback();
|
|
467
|
-
logger.debug('rollback end!');
|
|
479
|
+
exports.logger.debug('rollback end!');
|
|
468
480
|
conn[_inTransaction] = false;
|
|
469
|
-
logger.error(error);
|
|
481
|
+
exports.logger.error(error);
|
|
470
482
|
reject(error);
|
|
471
483
|
}
|
|
472
484
|
finally {
|
|
@@ -475,9 +487,9 @@ class Mysql {
|
|
|
475
487
|
conn[_inTransaction] = false;
|
|
476
488
|
}
|
|
477
489
|
if (newConn === true) {
|
|
478
|
-
logger.debug('release begin!');
|
|
490
|
+
exports.logger.debug('release begin!');
|
|
479
491
|
conn[_daoConnection].release();
|
|
480
|
-
logger.debug('release end!');
|
|
492
|
+
exports.logger.debug('release end!');
|
|
481
493
|
}
|
|
482
494
|
}
|
|
483
495
|
catch (error) {
|
|
@@ -498,6 +510,7 @@ class Mysql {
|
|
|
498
510
|
restore(sync, name) {
|
|
499
511
|
}
|
|
500
512
|
}
|
|
513
|
+
exports.Mysql = Mysql;
|
|
501
514
|
class SqliteConnection {
|
|
502
515
|
constructor(conn) {
|
|
503
516
|
this[_b] = false;
|
|
@@ -505,28 +518,28 @@ class SqliteConnection {
|
|
|
505
518
|
}
|
|
506
519
|
execute(sync, sql, params) {
|
|
507
520
|
try {
|
|
508
|
-
logger.debug(sql, params ?? '');
|
|
521
|
+
exports.logger.debug(sql, params ?? '');
|
|
509
522
|
if (!sql) {
|
|
510
523
|
return { affectedRows: 0, insertId: 0n };
|
|
511
524
|
}
|
|
512
525
|
;
|
|
513
526
|
if (sync === SyncMode.Async) {
|
|
514
|
-
logger.warn(`SQLITE not suppoted async mode`);
|
|
527
|
+
exports.logger.warn(`SQLITE not suppoted async mode`);
|
|
515
528
|
return { affectedRows: 0, insertId: 0n };
|
|
516
529
|
}
|
|
517
530
|
;
|
|
518
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
519
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
531
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
532
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
520
533
|
}
|
|
521
534
|
const result = this[_daoConnection].prepare(sql).run(params ?? {});
|
|
522
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
523
|
-
logger.trace(result);
|
|
535
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
536
|
+
exports.logger.trace(result);
|
|
524
537
|
}
|
|
525
538
|
const { changes, lastInsertRowid } = result;
|
|
526
539
|
return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
|
|
527
540
|
}
|
|
528
541
|
catch (error) {
|
|
529
|
-
logger.error(`
|
|
542
|
+
exports.logger.error(`
|
|
530
543
|
error: ${error},
|
|
531
544
|
sql: ${sql},
|
|
532
545
|
params: ${params}
|
|
@@ -536,23 +549,23 @@ class SqliteConnection {
|
|
|
536
549
|
}
|
|
537
550
|
pluck(sync, sql, params) {
|
|
538
551
|
try {
|
|
539
|
-
logger.debug(sql, params ?? '');
|
|
552
|
+
exports.logger.debug(sql, params ?? '');
|
|
540
553
|
if (!sql) {
|
|
541
554
|
return null;
|
|
542
555
|
}
|
|
543
556
|
;
|
|
544
557
|
if (sync === SyncMode.Async) {
|
|
545
|
-
logger.warn(`SQLITE not suppoted async mode`);
|
|
558
|
+
exports.logger.warn(`SQLITE not suppoted async mode`);
|
|
546
559
|
return null;
|
|
547
560
|
}
|
|
548
561
|
;
|
|
549
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
550
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
562
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
563
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
551
564
|
}
|
|
552
565
|
return this[_daoConnection].prepare(sql).pluck().get(params ?? {});
|
|
553
566
|
}
|
|
554
567
|
catch (error) {
|
|
555
|
-
logger.error(`
|
|
568
|
+
exports.logger.error(`
|
|
556
569
|
error: ${error},
|
|
557
570
|
sql: ${sql},
|
|
558
571
|
params: ${params}
|
|
@@ -562,7 +575,7 @@ class SqliteConnection {
|
|
|
562
575
|
}
|
|
563
576
|
get(sync, sql, params) {
|
|
564
577
|
try {
|
|
565
|
-
logger.debug(sql, params ?? '');
|
|
578
|
+
exports.logger.debug(sql, params ?? '');
|
|
566
579
|
if (!sql) {
|
|
567
580
|
return null;
|
|
568
581
|
}
|
|
@@ -571,13 +584,13 @@ class SqliteConnection {
|
|
|
571
584
|
return null;
|
|
572
585
|
}
|
|
573
586
|
;
|
|
574
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
575
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
587
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
588
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
576
589
|
}
|
|
577
590
|
return this[_daoConnection].prepare(sql).get(params ?? {});
|
|
578
591
|
}
|
|
579
592
|
catch (error) {
|
|
580
|
-
logger.error(`
|
|
593
|
+
exports.logger.error(`
|
|
581
594
|
error: ${error},
|
|
582
595
|
sql: ${sql},
|
|
583
596
|
params: ${params}
|
|
@@ -587,23 +600,23 @@ class SqliteConnection {
|
|
|
587
600
|
}
|
|
588
601
|
raw(sync, sql, params) {
|
|
589
602
|
try {
|
|
590
|
-
logger.debug(sql, params ?? '');
|
|
603
|
+
exports.logger.debug(sql, params ?? '');
|
|
591
604
|
if (!sql) {
|
|
592
605
|
return [];
|
|
593
606
|
}
|
|
594
607
|
;
|
|
595
608
|
if (sync === SyncMode.Async) {
|
|
596
|
-
logger.warn(`SQLITE not suppoted async mode`);
|
|
609
|
+
exports.logger.warn(`SQLITE not suppoted async mode`);
|
|
597
610
|
return [];
|
|
598
611
|
}
|
|
599
612
|
;
|
|
600
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
601
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
613
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
614
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
602
615
|
}
|
|
603
616
|
return this[_daoConnection].prepare(sql).raw().all(params ?? {});
|
|
604
617
|
}
|
|
605
618
|
catch (error) {
|
|
606
|
-
logger.error(`
|
|
619
|
+
exports.logger.error(`
|
|
607
620
|
error: ${error},
|
|
608
621
|
sql: ${sql},
|
|
609
622
|
params: ${params}
|
|
@@ -613,23 +626,23 @@ class SqliteConnection {
|
|
|
613
626
|
}
|
|
614
627
|
query(sync, sql, params) {
|
|
615
628
|
try {
|
|
616
|
-
logger.debug(sql, params ?? '');
|
|
629
|
+
exports.logger.debug(sql, params ?? '');
|
|
617
630
|
if (!sql) {
|
|
618
631
|
return [];
|
|
619
632
|
}
|
|
620
633
|
;
|
|
621
634
|
if (sync === SyncMode.Async) {
|
|
622
|
-
logger.warn(`SQLITE not suppoted async mode`);
|
|
635
|
+
exports.logger.warn(`SQLITE not suppoted async mode`);
|
|
623
636
|
return [];
|
|
624
637
|
}
|
|
625
638
|
;
|
|
626
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
627
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
639
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
640
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
628
641
|
}
|
|
629
642
|
return this[_daoConnection].prepare(sql).all(params ?? {});
|
|
630
643
|
}
|
|
631
644
|
catch (error) {
|
|
632
|
-
logger.error(`
|
|
645
|
+
exports.logger.error(`
|
|
633
646
|
error: ${error},
|
|
634
647
|
sql: ${sql},
|
|
635
648
|
params: ${params}
|
|
@@ -658,7 +671,7 @@ class Sqlite {
|
|
|
658
671
|
}
|
|
659
672
|
createConnection(sync) {
|
|
660
673
|
if (sync === SyncMode.Async) {
|
|
661
|
-
logger.error(`SQLITE not suppoted async mode`);
|
|
674
|
+
exports.logger.error(`SQLITE not suppoted async mode`);
|
|
662
675
|
return null;
|
|
663
676
|
}
|
|
664
677
|
;
|
|
@@ -666,7 +679,7 @@ class Sqlite {
|
|
|
666
679
|
}
|
|
667
680
|
transaction(sync, fn, conn) {
|
|
668
681
|
if (sync === SyncMode.Async) {
|
|
669
|
-
logger.warn(`SQLITE not suppoted async mode`);
|
|
682
|
+
exports.logger.warn(`SQLITE not suppoted async mode`);
|
|
670
683
|
return null;
|
|
671
684
|
}
|
|
672
685
|
;
|
|
@@ -703,6 +716,7 @@ class Sqlite {
|
|
|
703
716
|
restore(sync, name) {
|
|
704
717
|
}
|
|
705
718
|
}
|
|
719
|
+
exports.Sqlite = Sqlite;
|
|
706
720
|
class SqliteRemoteConnection {
|
|
707
721
|
constructor(conn, name) {
|
|
708
722
|
this[_c] = false;
|
|
@@ -710,18 +724,18 @@ class SqliteRemoteConnection {
|
|
|
710
724
|
this[_sqliteRemoteName] = name;
|
|
711
725
|
}
|
|
712
726
|
execute(sync, sql, params) {
|
|
713
|
-
logger.debug(sql, params ?? '');
|
|
727
|
+
exports.logger.debug(sql, params ?? '');
|
|
714
728
|
if (!sql) {
|
|
715
729
|
return { affectedRows: 0, insertId: 0n };
|
|
716
730
|
}
|
|
717
731
|
;
|
|
718
732
|
if (sync === SyncMode.Sync) {
|
|
719
|
-
logger.warn('SqliteRemote not suppouted sync mode');
|
|
733
|
+
exports.logger.warn('SqliteRemote not suppouted sync mode');
|
|
720
734
|
return { affectedRows: 0, insertId: 0n };
|
|
721
735
|
}
|
|
722
736
|
;
|
|
723
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
724
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
737
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
738
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
725
739
|
}
|
|
726
740
|
return new Promise(async (resolve, reject) => {
|
|
727
741
|
try {
|
|
@@ -729,7 +743,7 @@ class SqliteRemoteConnection {
|
|
|
729
743
|
resolve({ affectedRows, insertId: insertId ? BigInt(insertId) : 0n });
|
|
730
744
|
}
|
|
731
745
|
catch (error) {
|
|
732
|
-
logger.error(`
|
|
746
|
+
exports.logger.error(`
|
|
733
747
|
error: ${error},
|
|
734
748
|
sql: ${sql},
|
|
735
749
|
params: ${params}
|
|
@@ -739,18 +753,18 @@ class SqliteRemoteConnection {
|
|
|
739
753
|
});
|
|
740
754
|
}
|
|
741
755
|
pluck(sync, sql, params) {
|
|
742
|
-
logger.debug(sql, params ?? '');
|
|
756
|
+
exports.logger.debug(sql, params ?? '');
|
|
743
757
|
if (!sql) {
|
|
744
758
|
return null;
|
|
745
759
|
}
|
|
746
760
|
;
|
|
747
761
|
if (sync === SyncMode.Sync) {
|
|
748
|
-
logger.warn('SqliteRemote not suppouted sync mode');
|
|
762
|
+
exports.logger.warn('SqliteRemote not suppouted sync mode');
|
|
749
763
|
return null;
|
|
750
764
|
}
|
|
751
765
|
;
|
|
752
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
753
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
766
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
767
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
754
768
|
}
|
|
755
769
|
return new Promise(async (resolve, reject) => {
|
|
756
770
|
try {
|
|
@@ -758,7 +772,7 @@ class SqliteRemoteConnection {
|
|
|
758
772
|
resolve(r);
|
|
759
773
|
}
|
|
760
774
|
catch (error) {
|
|
761
|
-
logger.error(`
|
|
775
|
+
exports.logger.error(`
|
|
762
776
|
error: ${error},
|
|
763
777
|
sql: ${sql},
|
|
764
778
|
params: ${params}
|
|
@@ -768,18 +782,18 @@ class SqliteRemoteConnection {
|
|
|
768
782
|
});
|
|
769
783
|
}
|
|
770
784
|
get(sync, sql, params) {
|
|
771
|
-
logger.debug(sql, params ?? '');
|
|
785
|
+
exports.logger.debug(sql, params ?? '');
|
|
772
786
|
if (!sql) {
|
|
773
787
|
return null;
|
|
774
788
|
}
|
|
775
789
|
;
|
|
776
790
|
if (sync === SyncMode.Sync) {
|
|
777
|
-
logger.warn('SqliteRemote not suppouted sync mode');
|
|
791
|
+
exports.logger.warn('SqliteRemote not suppouted sync mode');
|
|
778
792
|
return null;
|
|
779
793
|
}
|
|
780
794
|
;
|
|
781
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
782
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
795
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
796
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
783
797
|
}
|
|
784
798
|
return new Promise(async (resolve, reject) => {
|
|
785
799
|
try {
|
|
@@ -787,7 +801,7 @@ class SqliteRemoteConnection {
|
|
|
787
801
|
resolve(r);
|
|
788
802
|
}
|
|
789
803
|
catch (error) {
|
|
790
|
-
logger.error(`
|
|
804
|
+
exports.logger.error(`
|
|
791
805
|
error: ${error},
|
|
792
806
|
sql: ${sql},
|
|
793
807
|
params: ${params}
|
|
@@ -797,18 +811,18 @@ class SqliteRemoteConnection {
|
|
|
797
811
|
});
|
|
798
812
|
}
|
|
799
813
|
raw(sync, sql, params) {
|
|
800
|
-
logger.debug(sql, params ?? '');
|
|
814
|
+
exports.logger.debug(sql, params ?? '');
|
|
801
815
|
if (!sql) {
|
|
802
816
|
return [];
|
|
803
817
|
}
|
|
804
818
|
;
|
|
805
819
|
if (sync === SyncMode.Sync) {
|
|
806
|
-
logger.warn('SqliteRemote not suppouted sync mode');
|
|
820
|
+
exports.logger.warn('SqliteRemote not suppouted sync mode');
|
|
807
821
|
return [];
|
|
808
822
|
}
|
|
809
823
|
;
|
|
810
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
811
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
824
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
825
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
812
826
|
}
|
|
813
827
|
return new Promise(async (resolve, reject) => {
|
|
814
828
|
try {
|
|
@@ -816,7 +830,7 @@ class SqliteRemoteConnection {
|
|
|
816
830
|
resolve(r);
|
|
817
831
|
}
|
|
818
832
|
catch (error) {
|
|
819
|
-
logger.error(`
|
|
833
|
+
exports.logger.error(`
|
|
820
834
|
error: ${error},
|
|
821
835
|
sql: ${sql},
|
|
822
836
|
params: ${params}
|
|
@@ -826,18 +840,18 @@ class SqliteRemoteConnection {
|
|
|
826
840
|
});
|
|
827
841
|
}
|
|
828
842
|
query(sync, sql, params) {
|
|
829
|
-
logger.debug(sql, params ?? '');
|
|
843
|
+
exports.logger.debug(sql, params ?? '');
|
|
830
844
|
if (!sql) {
|
|
831
845
|
return [];
|
|
832
846
|
}
|
|
833
847
|
;
|
|
834
848
|
if (sync === SyncMode.Sync) {
|
|
835
|
-
logger.warn('SqliteRemote not suppouted sync mode');
|
|
849
|
+
exports.logger.warn('SqliteRemote not suppouted sync mode');
|
|
836
850
|
return [];
|
|
837
851
|
}
|
|
838
852
|
;
|
|
839
|
-
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
840
|
-
logger.trace(sqlstring_1.default.format(sql, params));
|
|
853
|
+
if (globalThis[exports._GlobalSqlOption].log === 'trace') {
|
|
854
|
+
exports.logger.trace(sqlstring_1.default.format(sql, params));
|
|
841
855
|
}
|
|
842
856
|
return new Promise(async (resolve, reject) => {
|
|
843
857
|
try {
|
|
@@ -845,7 +859,7 @@ class SqliteRemoteConnection {
|
|
|
845
859
|
resolve(r);
|
|
846
860
|
}
|
|
847
861
|
catch (error) {
|
|
848
|
-
logger.error(`
|
|
862
|
+
exports.logger.error(`
|
|
849
863
|
error: ${error},
|
|
850
864
|
sql: ${sql},
|
|
851
865
|
params: ${params}
|
|
@@ -857,6 +871,7 @@ class SqliteRemoteConnection {
|
|
|
857
871
|
realse(sync) {
|
|
858
872
|
}
|
|
859
873
|
}
|
|
874
|
+
exports.SqliteRemoteConnection = SqliteRemoteConnection;
|
|
860
875
|
_c = _inTransaction;
|
|
861
876
|
class SqliteRemote {
|
|
862
877
|
constructor(db, name) {
|
|
@@ -865,51 +880,77 @@ class SqliteRemote {
|
|
|
865
880
|
}
|
|
866
881
|
createConnection(sync) {
|
|
867
882
|
if (sync === SyncMode.Sync) {
|
|
868
|
-
logger.error('SQLITEREMOTE not suppouted sync mode');
|
|
883
|
+
exports.logger.error('SQLITEREMOTE not suppouted sync mode');
|
|
869
884
|
return null;
|
|
870
885
|
}
|
|
871
886
|
;
|
|
872
|
-
return new Promise(async (resolve) => {
|
|
873
|
-
|
|
887
|
+
return new Promise(async (resolve, reject) => {
|
|
888
|
+
try {
|
|
889
|
+
resolve(new SqliteRemoteConnection(this[_daoDB], this[_sqliteRemoteName]));
|
|
890
|
+
}
|
|
891
|
+
catch (error) {
|
|
892
|
+
reject(error);
|
|
893
|
+
}
|
|
874
894
|
});
|
|
875
895
|
}
|
|
876
896
|
transaction(sync, fn, conn) {
|
|
877
|
-
logger.warn(`SQLITEREMOTE not suppoted transaction`);
|
|
897
|
+
exports.logger.warn(`SQLITEREMOTE not suppoted transaction`);
|
|
878
898
|
return null;
|
|
879
899
|
}
|
|
880
900
|
close(sync) {
|
|
881
901
|
if (sync === SyncMode.Async) {
|
|
882
|
-
return new Promise(async () => {
|
|
883
|
-
|
|
902
|
+
return new Promise(async (resolve, reject) => {
|
|
903
|
+
try {
|
|
904
|
+
await this[_daoConnection].close();
|
|
905
|
+
}
|
|
906
|
+
catch (error) {
|
|
907
|
+
reject(error);
|
|
908
|
+
}
|
|
884
909
|
});
|
|
885
910
|
}
|
|
886
911
|
;
|
|
887
912
|
}
|
|
888
913
|
backup(sync, name) {
|
|
889
914
|
if (sync === SyncMode.Async) {
|
|
890
|
-
return new Promise(async () => {
|
|
891
|
-
|
|
915
|
+
return new Promise(async (resolve, reject) => {
|
|
916
|
+
try {
|
|
917
|
+
await this[_daoConnection].backup(this[_sqliteRemoteName], name);
|
|
918
|
+
}
|
|
919
|
+
catch (error) {
|
|
920
|
+
reject(error);
|
|
921
|
+
}
|
|
892
922
|
});
|
|
893
923
|
}
|
|
894
924
|
;
|
|
895
925
|
}
|
|
896
926
|
remove(sync) {
|
|
897
927
|
if (sync === SyncMode.Async) {
|
|
898
|
-
return new Promise(async () => {
|
|
899
|
-
|
|
928
|
+
return new Promise(async (resolve, reject) => {
|
|
929
|
+
try {
|
|
930
|
+
await this[_daoConnection].remove();
|
|
931
|
+
}
|
|
932
|
+
catch (error) {
|
|
933
|
+
reject(error);
|
|
934
|
+
}
|
|
900
935
|
});
|
|
901
936
|
}
|
|
902
937
|
;
|
|
903
938
|
}
|
|
904
939
|
restore(sync, name) {
|
|
905
940
|
if (sync === SyncMode.Async) {
|
|
906
|
-
return new Promise(async () => {
|
|
907
|
-
|
|
941
|
+
return new Promise(async (resolve, reject) => {
|
|
942
|
+
try {
|
|
943
|
+
await this[_daoConnection].restore(this[_sqliteRemoteName], name);
|
|
944
|
+
}
|
|
945
|
+
catch (error) {
|
|
946
|
+
reject(error);
|
|
947
|
+
}
|
|
908
948
|
});
|
|
909
949
|
}
|
|
910
950
|
;
|
|
911
951
|
}
|
|
912
952
|
}
|
|
953
|
+
exports.SqliteRemote = SqliteRemote;
|
|
913
954
|
class Build {
|
|
914
955
|
/**
|
|
915
956
|
*
|
|
@@ -929,7 +970,7 @@ class Build {
|
|
|
929
970
|
* @returns
|
|
930
971
|
* @memberof Build
|
|
931
972
|
*/
|
|
932
|
-
|
|
973
|
+
page() {
|
|
933
974
|
return (text, render) => {
|
|
934
975
|
if (this.isCount === true) {
|
|
935
976
|
return Build.page;
|
|
@@ -941,11 +982,11 @@ class Build {
|
|
|
941
982
|
}
|
|
942
983
|
/**
|
|
943
984
|
*
|
|
944
|
-
*
|
|
985
|
+
* 包含的内容只在汇总查询时有效,否则是空白
|
|
945
986
|
* @returns
|
|
946
987
|
* @memberof Build
|
|
947
988
|
*/
|
|
948
|
-
|
|
989
|
+
sum() {
|
|
949
990
|
return (text, render) => {
|
|
950
991
|
if (this.isSum !== true) {
|
|
951
992
|
return '';
|
|
@@ -961,7 +1002,7 @@ class Build {
|
|
|
961
1002
|
* @returns
|
|
962
1003
|
* @memberof Build
|
|
963
1004
|
*/
|
|
964
|
-
|
|
1005
|
+
notPage() {
|
|
965
1006
|
return (text, render) => {
|
|
966
1007
|
if (this.isCount === true || this.isSum === true) {
|
|
967
1008
|
return '';
|
|
@@ -986,8 +1027,7 @@ class Build {
|
|
|
986
1027
|
*/
|
|
987
1028
|
where() {
|
|
988
1029
|
return (text, render) => {
|
|
989
|
-
let data = render(text);
|
|
990
|
-
data = data.trim();
|
|
1030
|
+
let data = render(text).trim();
|
|
991
1031
|
if (data) {
|
|
992
1032
|
data = data.replace(/and|or/i, '');
|
|
993
1033
|
return ` WHERE ${data} `;
|
|
@@ -997,6 +1037,33 @@ class Build {
|
|
|
997
1037
|
}
|
|
998
1038
|
};
|
|
999
1039
|
}
|
|
1040
|
+
/**
|
|
1041
|
+
* ```
|
|
1042
|
+
* SELECT
|
|
1043
|
+
* {{#hump}}
|
|
1044
|
+
* a.event_id, a.event_name eventName
|
|
1045
|
+
* {{/hump}}
|
|
1046
|
+
* FROM...
|
|
1047
|
+
* ```
|
|
1048
|
+
* 编译后:
|
|
1049
|
+
* ```
|
|
1050
|
+
* SELECT
|
|
1051
|
+
* a.event_id eventId, a.event_name eventName
|
|
1052
|
+
* FROM...
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
hump() {
|
|
1056
|
+
return (text, render) => {
|
|
1057
|
+
let data = render(text).trim();
|
|
1058
|
+
const datas = data.split(',');
|
|
1059
|
+
for (let i = 0; i < datas.length; i++) {
|
|
1060
|
+
if (datas[i]?.match(/\s|\t/) === null) {
|
|
1061
|
+
datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b, c) => b.toUpperCase())}`;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
return datas.join(',');
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1000
1067
|
/**
|
|
1001
1068
|
* 删除第一个and、or
|
|
1002
1069
|
* 删除最后一个,
|
|
@@ -1020,13 +1087,13 @@ class Build {
|
|
|
1020
1087
|
* 分页时将排序部分代码用此函数包起来,可以自动拼接order by
|
|
1021
1088
|
* 查询条数时,自动忽略此部分
|
|
1022
1089
|
* etc
|
|
1023
|
-
* {{#
|
|
1090
|
+
* {{#order}} name desc, age asc {{/order}}
|
|
1024
1091
|
* ===
|
|
1025
1092
|
* ORDER BY name desc, age asc
|
|
1026
1093
|
* @returns
|
|
1027
1094
|
* @memberof Build
|
|
1028
1095
|
*/
|
|
1029
|
-
|
|
1096
|
+
order() {
|
|
1030
1097
|
return (text, render) => {
|
|
1031
1098
|
if (this.isCount === true || this.isSum === true) {
|
|
1032
1099
|
return '';
|
|
@@ -1042,7 +1109,7 @@ class Build {
|
|
|
1042
1109
|
}
|
|
1043
1110
|
};
|
|
1044
1111
|
}
|
|
1045
|
-
|
|
1112
|
+
limit() {
|
|
1046
1113
|
return (text, render) => {
|
|
1047
1114
|
if (this.isCount === true || this.isSum === true) {
|
|
1048
1115
|
return '';
|
|
@@ -1063,13 +1130,13 @@ class Build {
|
|
|
1063
1130
|
* 分页时将分组部分代码用此函数包起来,可以自动拼接GROUP BY
|
|
1064
1131
|
* 当分页时、汇总时,自动忽略此部分
|
|
1065
1132
|
* etc
|
|
1066
|
-
* {{#
|
|
1133
|
+
* {{#between}} name, age {{/between}}
|
|
1067
1134
|
* ===
|
|
1068
1135
|
* group by name.age
|
|
1069
1136
|
* @returns
|
|
1070
1137
|
* @memberof Build
|
|
1071
1138
|
*/
|
|
1072
|
-
|
|
1139
|
+
group() {
|
|
1073
1140
|
return (text, render) => {
|
|
1074
1141
|
if (this.isCount === true || this.isSum === true) {
|
|
1075
1142
|
return '';
|
|
@@ -1114,15 +1181,15 @@ class Build {
|
|
|
1114
1181
|
*
|
|
1115
1182
|
* 距离计算,单位米
|
|
1116
1183
|
* etc
|
|
1117
|
-
* {{#
|
|
1184
|
+
* {{#distance}} (t.longitude, t.latitude), ({{longitude}}, {{latitude}}) {{/distance}}
|
|
1118
1185
|
* ===
|
|
1119
1186
|
* ROUND(ST_DISTANCE(POINT(longitude1, latitude1), POINT({{longitude}}, {{latitude}}))*111195, 2)
|
|
1120
1187
|
* 可根据需求自行将数据转换为千米,例如
|
|
1121
|
-
* {{#
|
|
1188
|
+
* {{#distance}} (t.longitude, t.latitude), ({{longitude}}, {{latitude}}) {{/distance}} / 1000
|
|
1122
1189
|
* @returns
|
|
1123
1190
|
* @memberof Build
|
|
1124
1191
|
*/
|
|
1125
|
-
|
|
1192
|
+
distance() {
|
|
1126
1193
|
return (text, render) => {
|
|
1127
1194
|
const result = render(text);
|
|
1128
1195
|
if (/\(([^()]+)\)/.exec(result)) {
|
|
@@ -1150,6 +1217,23 @@ class Build {
|
|
|
1150
1217
|
}
|
|
1151
1218
|
}
|
|
1152
1219
|
Build.page = 'COUNT(1) zccw1986 ';
|
|
1220
|
+
function replaceCdata(rawText) {
|
|
1221
|
+
var cdataRegex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
|
|
1222
|
+
var matches = rawText.match(cdataRegex);
|
|
1223
|
+
if (matches != null && matches.length > 0) {
|
|
1224
|
+
for (var z = 0; z < matches.length; z++) {
|
|
1225
|
+
var regex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
|
|
1226
|
+
var m = regex.exec(matches[z]);
|
|
1227
|
+
var cdataText = m[2];
|
|
1228
|
+
cdataText = cdataText.replace(/\&/g, '&');
|
|
1229
|
+
cdataText = cdataText.replace(/\</g, '<');
|
|
1230
|
+
cdataText = cdataText.replace(/\>/g, '>');
|
|
1231
|
+
cdataText = cdataText.replace(/\"/g, '"');
|
|
1232
|
+
rawText = rawText.replace(m[0], cdataText);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
return rawText;
|
|
1236
|
+
}
|
|
1153
1237
|
class SqlCache {
|
|
1154
1238
|
constructor() {
|
|
1155
1239
|
this.sqlMap = {};
|
|
@@ -1159,54 +1243,98 @@ class SqlCache {
|
|
|
1159
1243
|
if (options.sqlMap) {
|
|
1160
1244
|
this.sqlMap = options.sqlMap;
|
|
1161
1245
|
}
|
|
1246
|
+
const queryTypes = ['sql', 'select', 'insert', 'update', 'delete'];
|
|
1162
1247
|
if (options.sqlDir) {
|
|
1163
|
-
const sqlFis = globalThis[_fs].readdirSync(options.sqlDir);
|
|
1248
|
+
const sqlFis = globalThis[exports._fs].readdirSync(options.sqlDir);
|
|
1164
1249
|
for (const modeName of sqlFis) {
|
|
1165
|
-
|
|
1166
|
-
const
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
1250
|
+
exports.logger.debug(`sql: ${modeName} start explain!`);
|
|
1251
|
+
const extname = globalThis[exports._path].extname(modeName);
|
|
1252
|
+
const name = globalThis[exports._path].basename(modeName, extname);
|
|
1253
|
+
const file = globalThis[exports._path].join(options.sqlDir, modeName);
|
|
1254
|
+
let ct = 0;
|
|
1255
|
+
if (extname === '.mu') {
|
|
1256
|
+
const parser = new MUParser(name, globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString());
|
|
1170
1257
|
let source = parser.next();
|
|
1171
1258
|
while (source != null) {
|
|
1259
|
+
ct++;
|
|
1172
1260
|
this.sqlMap[source[0]] = source[1];
|
|
1173
|
-
logger.debug(`sql: ${source[0]} found!`);
|
|
1261
|
+
exports.logger.debug(`sql: ${source[0]} found!`);
|
|
1174
1262
|
source = parser.next();
|
|
1175
1263
|
}
|
|
1176
1264
|
}
|
|
1177
1265
|
else if (extname === '.js') {
|
|
1178
|
-
const obj = (await Promise.resolve(`${globalThis[_path].join(options.sqlDir, modeName)}`).then(s => __importStar(require(s)))).default;
|
|
1266
|
+
const obj = (await Promise.resolve(`${globalThis[exports._path].join(options.sqlDir, modeName)}`).then(s => __importStar(require(s)))).default;
|
|
1179
1267
|
for (const [key, fn] of Object.entries(obj)) {
|
|
1268
|
+
ct++;
|
|
1180
1269
|
this.sqlMap[`${name}.${String(key)}`] = fn;
|
|
1181
1270
|
}
|
|
1182
1271
|
}
|
|
1272
|
+
else if (extname === '.xml') {
|
|
1273
|
+
const root = html_parse_stringify_1.default.parse(replaceCdata(globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString()))[0];
|
|
1274
|
+
if (root) {
|
|
1275
|
+
const mappers = root.children;
|
|
1276
|
+
for (const mapper of mappers) {
|
|
1277
|
+
console.log(mapper);
|
|
1278
|
+
if (mapper.type === 'tag' && mapper.name === 'mapper') {
|
|
1279
|
+
for (const am of mapper.children) {
|
|
1280
|
+
if (am.type === 'tag') {
|
|
1281
|
+
error_1.Throw.if(!queryTypes.includes(am.name), `${name}错误,${am.name}不支持!`);
|
|
1282
|
+
am.id = am.attrs['id'];
|
|
1283
|
+
error_1.Throw.if(!am.id, `${name}错误,没有为此块设置id:${am}`);
|
|
1284
|
+
this.sqlMap[`${name}.${am.id}`] = am.children;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
exports.logger.debug(`sql: ${modeName} explain over[${ct}]!`);
|
|
1183
1292
|
}
|
|
1184
1293
|
}
|
|
1185
1294
|
if (options.sqlFNMap) {
|
|
1186
1295
|
this.sqlFNMap = options.sqlFNMap;
|
|
1187
1296
|
}
|
|
1188
1297
|
if (options.sqlFNDir) {
|
|
1189
|
-
const sqlFis = globalThis[_fs].readdirSync(options.sqlDir);
|
|
1298
|
+
const sqlFis = globalThis[exports._fs].readdirSync(options.sqlDir);
|
|
1190
1299
|
for (const modeName of sqlFis) {
|
|
1191
|
-
const extname = globalThis[_path].extname(modeName);
|
|
1192
|
-
const name = globalThis[_path].basename(modeName, extname);
|
|
1193
|
-
const file = globalThis[_path].join(options.sqlDir, modeName);
|
|
1300
|
+
const extname = globalThis[exports._path].extname(modeName);
|
|
1301
|
+
const name = globalThis[exports._path].basename(modeName, extname);
|
|
1302
|
+
const file = globalThis[exports._path].join(options.sqlDir, modeName);
|
|
1194
1303
|
if (extname === 'mu') {
|
|
1195
|
-
this.sqlFNMap[name] = globalThis[_fs].readFileSync(file, { encoding: 'utf-8' }).toString();
|
|
1304
|
+
this.sqlFNMap[name] = globalThis[exports._fs].readFileSync(file, { encoding: 'utf-8' }).toString();
|
|
1196
1305
|
}
|
|
1197
1306
|
}
|
|
1198
1307
|
}
|
|
1199
1308
|
}
|
|
1200
|
-
load(
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1309
|
+
load(sqlids, options) {
|
|
1310
|
+
let sqlSource;
|
|
1311
|
+
for (const sqlid of sqlids) {
|
|
1312
|
+
sqlSource = this.sqlMap[sqlid];
|
|
1313
|
+
if (sqlSource) {
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
const matchSqlid = sqlids.map(i => i.split('.')[0]);
|
|
1318
|
+
error_1.Throw.if(!sqlSource, `指定的语句${sqlids.join('|')}不存在!`);
|
|
1319
|
+
if (typeof sqlSource === 'function') {
|
|
1320
|
+
const _sql = sqlSource(options);
|
|
1321
|
+
const buildParam = new Build(options.isCount === true, options.isSum === true, options);
|
|
1322
|
+
const sql = mustache_1.default.render(_sql, buildParam, this.sqlFNMap);
|
|
1323
|
+
return (0, sql_formatter_1.format)(sql);
|
|
1324
|
+
}
|
|
1325
|
+
else if (typeof sqlSource === 'string') {
|
|
1326
|
+
const buildParam = new Build(options.isCount === true, options.isSum === true, options);
|
|
1327
|
+
const sql = mustache_1.default.render(sqlSource, buildParam, this.sqlFNMap);
|
|
1328
|
+
return (0, sql_formatter_1.format)(sql);
|
|
1329
|
+
}
|
|
1330
|
+
else if (typeof sqlSource === 'object') {
|
|
1331
|
+
const sql = (0, convert_xml_1.convert)(sqlSource, options, matchSqlid, this.sqlMap);
|
|
1332
|
+
return (0, sql_formatter_1.format)(sql);
|
|
1333
|
+
}
|
|
1334
|
+
return '';
|
|
1208
1335
|
}
|
|
1209
1336
|
}
|
|
1337
|
+
exports.SqlCache = SqlCache;
|
|
1210
1338
|
// #endregion
|
|
1211
1339
|
/**
|
|
1212
1340
|
|
|
@@ -1230,10 +1358,12 @@ function P(skipConn = false) {
|
|
|
1230
1358
|
let needRealseConn = true;
|
|
1231
1359
|
const startTime = +new Date();
|
|
1232
1360
|
// option
|
|
1233
|
-
const option = args[0] = Object.assign({}, globalThis[_GlobalSqlOption], this[_SqlOption], args[0]);
|
|
1361
|
+
const option = args[0] = Object.assign({}, globalThis[exports._GlobalSqlOption], this[_SqlOption], args[0]);
|
|
1234
1362
|
option.sync ?? (option.sync = SyncMode.Async);
|
|
1235
|
-
const dbName = option?.dbName ?? this[_daoDBName] ?? _primaryDB;
|
|
1236
|
-
|
|
1363
|
+
const dbName = option?.dbName ?? this[_daoDBName] ?? exports._primaryDB;
|
|
1364
|
+
const dddx = this[_dbType];
|
|
1365
|
+
exports.logger.info(dddx);
|
|
1366
|
+
option.dao = globalThis[exports._dao][this[_dbType]][dbName];
|
|
1237
1367
|
error_1.Throw.if(!option.dao, `not found db:${String(dbName)}(${this[_dbType]})`);
|
|
1238
1368
|
option.tableName = option?.tableName ?? this[_tableName];
|
|
1239
1369
|
const tableES = sqlstring_1.default.escapeId(option.tableName);
|
|
@@ -1256,7 +1386,7 @@ function P(skipConn = false) {
|
|
|
1256
1386
|
if (tableVersion && tableVersion < lastVersion) { // 发现需要升级的版本
|
|
1257
1387
|
// 更新版本
|
|
1258
1388
|
const columns = (0, iterare_1.default)(option.conn.query(SyncMode.Sync, `PRAGMA table_info(${tableES})`))
|
|
1259
|
-
.filter(c => this[_fields].hasOwnProperty(c.name))
|
|
1389
|
+
.filter(c => this[_fields].hasOwnProperty((0, object_1.C2P)(c.name, globalThis[exports._Hump])))
|
|
1260
1390
|
.map(c => sqlstring_1.default.escapeId(c.name))
|
|
1261
1391
|
.join(',');
|
|
1262
1392
|
const rtable = sqlstring_1.default.escapeId(`${option.tableName}_${tableVersion.replace(/\./, '_')}`);
|
|
@@ -1264,13 +1394,13 @@ function P(skipConn = false) {
|
|
|
1264
1394
|
option.conn.execute(SyncMode.Sync, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
|
|
1265
1395
|
option.conn.execute(SyncMode.Sync, `
|
|
1266
1396
|
CREATE TABLE IF NOT EXISTS ${tableES}(
|
|
1267
|
-
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]).join(',')}
|
|
1268
|
-
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.
|
|
1397
|
+
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
|
|
1398
|
+
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
|
|
1269
1399
|
);
|
|
1270
1400
|
`);
|
|
1271
1401
|
if (this[_index] && this[_index].length) {
|
|
1272
1402
|
for (const index of this[_index]) {
|
|
1273
|
-
option.conn.execute(SyncMode.Sync, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableES} ("${index}");`);
|
|
1403
|
+
option.conn.execute(SyncMode.Sync, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
|
|
1274
1404
|
}
|
|
1275
1405
|
}
|
|
1276
1406
|
option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
|
|
@@ -1287,14 +1417,14 @@ function P(skipConn = false) {
|
|
|
1287
1417
|
// 创建表
|
|
1288
1418
|
option.conn.execute(SyncMode.Sync, `
|
|
1289
1419
|
CREATE TABLE IF NOT EXISTS ${tableES} (
|
|
1290
|
-
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]).join(',')}
|
|
1291
|
-
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.
|
|
1420
|
+
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
|
|
1421
|
+
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
|
|
1292
1422
|
|
|
1293
1423
|
);
|
|
1294
1424
|
`);
|
|
1295
1425
|
if (this[_index] && this[_index].length) {
|
|
1296
1426
|
for (const index of this[_index]) {
|
|
1297
|
-
option.conn.execute(SyncMode.Sync, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableES} ("${index}");`);
|
|
1427
|
+
option.conn.execute(SyncMode.Sync, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
|
|
1298
1428
|
}
|
|
1299
1429
|
}
|
|
1300
1430
|
option.conn.execute(SyncMode.Sync, 'INSERT OR REPLACE INTO TABLE_VERSION (______tableName, ______version ) VALUES ( ?, ? )', [option.tableName, lastVersion]);
|
|
@@ -1302,7 +1432,7 @@ function P(skipConn = false) {
|
|
|
1302
1432
|
}
|
|
1303
1433
|
try {
|
|
1304
1434
|
const result = fn.call(this, ...args);
|
|
1305
|
-
logger.info(`${propertyKey}:${option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1435
|
+
exports.logger.info(`${propertyKey}:${option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1306
1436
|
return result;
|
|
1307
1437
|
}
|
|
1308
1438
|
catch (error) {
|
|
@@ -1343,7 +1473,7 @@ function P(skipConn = false) {
|
|
|
1343
1473
|
if (tableVersion && tableVersion < lastVersion) { // 发现需要升级的版本
|
|
1344
1474
|
// 更新版本
|
|
1345
1475
|
const columns = (0, iterare_1.default)(await option.conn.query(SyncMode.Async, `PRAGMA table_info(${tableES})`))
|
|
1346
|
-
.filter(c => this[_fields].hasOwnProperty(c.name))
|
|
1476
|
+
.filter(c => this[_fields].hasOwnProperty((0, object_1.C2P)(c.name, globalThis[exports._Hump])))
|
|
1347
1477
|
.map(c => sqlstring_1.default.escapeId(c.name))
|
|
1348
1478
|
.join(',');
|
|
1349
1479
|
const rtable = `${option.tableName}_${tableVersion.replace(/\./, '_')}`;
|
|
@@ -1351,13 +1481,13 @@ function P(skipConn = false) {
|
|
|
1351
1481
|
await option.conn.execute(SyncMode.Async, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
|
|
1352
1482
|
await option.conn.execute(SyncMode.Async, `
|
|
1353
1483
|
CREATE TABLE IF NOT EXISTS ${tableES}(
|
|
1354
|
-
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]).join(',')}
|
|
1355
|
-
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.
|
|
1484
|
+
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
|
|
1485
|
+
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
|
|
1356
1486
|
);
|
|
1357
1487
|
`);
|
|
1358
1488
|
if (this[_index] && this[_index].length) {
|
|
1359
1489
|
for (const index of this[_index]) {
|
|
1360
|
-
await option.conn.execute(SyncMode.Async, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableES} ("${index}");`);
|
|
1490
|
+
await option.conn.execute(SyncMode.Async, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
|
|
1361
1491
|
}
|
|
1362
1492
|
}
|
|
1363
1493
|
await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
|
|
@@ -1374,13 +1504,13 @@ function P(skipConn = false) {
|
|
|
1374
1504
|
// 创建表
|
|
1375
1505
|
await option.conn.execute(SyncMode.Async, `
|
|
1376
1506
|
CREATE TABLE IF NOT EXISTS ${tableES}(
|
|
1377
|
-
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]).join(',')}
|
|
1378
|
-
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.
|
|
1507
|
+
${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
|
|
1508
|
+
${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
|
|
1379
1509
|
);
|
|
1380
1510
|
`);
|
|
1381
1511
|
if (this[_index] && this[_index].length) {
|
|
1382
1512
|
for (const index of this[_index]) {
|
|
1383
|
-
await option.conn.execute(SyncMode.Async, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${sqlstring_1.default.escapeId(option.tableName)} ("${index}");`);
|
|
1513
|
+
await option.conn.execute(SyncMode.Async, `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${sqlstring_1.default.escapeId(option.tableName)} ("${this[_fields][index]?.C2()}");`);
|
|
1384
1514
|
}
|
|
1385
1515
|
}
|
|
1386
1516
|
await option.conn.execute(SyncMode.Async, 'INSERT OR REPLACE INTO TABLE_VERSION (______tableName, ______version ) VALUES ( ?, ? )', [option.tableName, lastVersion]);
|
|
@@ -1388,7 +1518,7 @@ function P(skipConn = false) {
|
|
|
1388
1518
|
}
|
|
1389
1519
|
try {
|
|
1390
1520
|
const result = await fn.call(this, ...args);
|
|
1391
|
-
logger.info(`${propertyKey}:${option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1521
|
+
exports.logger.info(`${propertyKey}:${option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1392
1522
|
resolve(result);
|
|
1393
1523
|
}
|
|
1394
1524
|
catch (error) {
|
|
@@ -1417,7 +1547,7 @@ function P(skipConn = false) {
|
|
|
1417
1547
|
needRealseConn = false;
|
|
1418
1548
|
}
|
|
1419
1549
|
const result = await fn.call(this, ...args);
|
|
1420
|
-
logger.info(`${propertyKey}:${option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1550
|
+
exports.logger.info(`${propertyKey}:${option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1421
1551
|
resolve(result);
|
|
1422
1552
|
}
|
|
1423
1553
|
catch (error) {
|
|
@@ -1438,28 +1568,44 @@ function P(skipConn = false) {
|
|
|
1438
1568
|
};
|
|
1439
1569
|
};
|
|
1440
1570
|
}
|
|
1441
|
-
const FieldFilter = (K, V, def, option) => {
|
|
1571
|
+
const FieldFilter = (K, V, def, uuidColumn, option) => {
|
|
1442
1572
|
let ret = 0;
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1573
|
+
// 如果是插入操作且字段是UUID,则不进行空值检查
|
|
1574
|
+
// 只有在非插入或者非UUID时,进行空置检查
|
|
1575
|
+
if (option?.insert === true && uuidColumn === true) {
|
|
1576
|
+
ret = 1;
|
|
1577
|
+
if (V === undefined) {
|
|
1578
|
+
V = null;
|
|
1447
1579
|
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
if (option?.skipUndefined !== true) {
|
|
1451
|
-
ret = 1;
|
|
1452
|
-
V = option?.def === true && def && def.hasOwnProperty(K) ? def[K] : null;
|
|
1580
|
+
else if ((0, string_1.emptyString)(`${V ?? ''}`)) {
|
|
1581
|
+
V = '';
|
|
1453
1582
|
}
|
|
1454
|
-
|
|
1455
|
-
else if ((0, string_1.emptyString)(`${V ?? ''}`)) {
|
|
1456
|
-
if (option?.skipEmptyString !== true) {
|
|
1583
|
+
else {
|
|
1457
1584
|
ret = 1;
|
|
1458
|
-
V = option?.def === true && def && def.hasOwnProperty(K) ? def[K] : '';
|
|
1459
1585
|
}
|
|
1460
1586
|
}
|
|
1461
1587
|
else {
|
|
1462
|
-
|
|
1588
|
+
if (V === null) {
|
|
1589
|
+
if (option?.skipNull !== true) {
|
|
1590
|
+
ret = 1;
|
|
1591
|
+
V = option?.insert === true && def && def.hasOwnProperty(K) ? def[K] : null;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
else if (V === undefined) {
|
|
1595
|
+
if (option?.skipUndefined !== true) {
|
|
1596
|
+
ret = 1;
|
|
1597
|
+
V = option?.insert === true && def && def.hasOwnProperty(K) ? def[K] : null;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
else if ((0, string_1.emptyString)(`${V ?? ''}`)) {
|
|
1601
|
+
if (option?.skipEmptyString !== true) {
|
|
1602
|
+
ret = 1;
|
|
1603
|
+
V = option?.insert === true && def && def.hasOwnProperty(K) ? def[K] : '';
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
ret = 1;
|
|
1608
|
+
}
|
|
1463
1609
|
}
|
|
1464
1610
|
if (ret === 1) {
|
|
1465
1611
|
option?.finalColumns?.add(K);
|
|
@@ -1472,193 +1618,195 @@ const Field = (config) => {
|
|
|
1472
1618
|
config.type ?? (config.type = SqlType.varchar);
|
|
1473
1619
|
return (object, propertyName) => {
|
|
1474
1620
|
const field = config;
|
|
1475
|
-
field.
|
|
1476
|
-
field.
|
|
1621
|
+
field.P = propertyName;
|
|
1622
|
+
field.C = () => (0, object_1.P2C)(propertyName, globalThis[exports._Hump]);
|
|
1623
|
+
field.C2 = () => sqlstring_1.default.escapeId((0, object_1.P2C)(propertyName, globalThis[exports._Hump]));
|
|
1624
|
+
field.C3 = () => `${sqlstring_1.default.escapeId((0, object_1.P2C)(propertyName, globalThis[exports._Hump]))} ${propertyName}`;
|
|
1477
1625
|
const hasDef = field.hasOwnProperty('def') === true;
|
|
1478
1626
|
switch (field.type) {
|
|
1479
1627
|
case SqlType.tinyint: {
|
|
1480
|
-
field[DBType.Mysql] = `${field.
|
|
1481
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1628
|
+
field[DBType.Mysql] = () => `${field.C2()} tinyint ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1629
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
|
|
1482
1630
|
break;
|
|
1483
1631
|
}
|
|
1484
1632
|
case SqlType.smallint: {
|
|
1485
|
-
field[DBType.Mysql] = `${field.
|
|
1486
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1633
|
+
field[DBType.Mysql] = () => `${field.C2()} smallint ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1634
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
|
|
1487
1635
|
break;
|
|
1488
1636
|
}
|
|
1489
1637
|
case SqlType.mediumint: {
|
|
1490
|
-
field[DBType.Mysql] = `${field.
|
|
1491
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1638
|
+
field[DBType.Mysql] = () => `${field.C2()} smallint ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1639
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
|
|
1492
1640
|
break;
|
|
1493
1641
|
}
|
|
1494
1642
|
case SqlType.int: {
|
|
1495
|
-
field[DBType.Mysql] = `${field.
|
|
1496
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1643
|
+
field[DBType.Mysql] = () => `${field.C2()} int ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1644
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
|
|
1497
1645
|
break;
|
|
1498
1646
|
}
|
|
1499
1647
|
case SqlType.bigint: {
|
|
1500
|
-
field[DBType.Mysql] = `${field.
|
|
1501
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1648
|
+
field[DBType.Mysql] = () => `${field.C2()} bigint ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1649
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
|
|
1502
1650
|
break;
|
|
1503
1651
|
}
|
|
1504
1652
|
case SqlType.float: {
|
|
1505
|
-
field[DBType.Mysql] = `${field.
|
|
1506
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1653
|
+
field[DBType.Mysql] = () => `${field.C2()} float(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
|
|
1654
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} real`;
|
|
1507
1655
|
break;
|
|
1508
1656
|
}
|
|
1509
1657
|
case SqlType.double: {
|
|
1510
|
-
field[DBType.Mysql] = `${field.
|
|
1511
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1658
|
+
field[DBType.Mysql] = () => `${field.C2()} double(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
|
|
1659
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} real`;
|
|
1512
1660
|
break;
|
|
1513
1661
|
}
|
|
1514
1662
|
case SqlType.decimal: {
|
|
1515
|
-
field[DBType.Mysql] = `${field.
|
|
1516
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1663
|
+
field[DBType.Mysql] = () => `${field.C2()} decimal(${config.length ?? 1}, ${config.scale ?? 2}) ${config.notNull === true ? 'NOT NULL' : ''} ${hasDef ? `DEFAULT '${field.def}'` : ''} `;
|
|
1664
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} real`;
|
|
1517
1665
|
break;
|
|
1518
1666
|
}
|
|
1519
1667
|
case SqlType.longtext: {
|
|
1520
|
-
field[DBType.Mysql] = `${field.
|
|
1521
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1668
|
+
field[DBType.Mysql] = () => `${field.C2()} longtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1669
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1522
1670
|
break;
|
|
1523
1671
|
}
|
|
1524
1672
|
case SqlType.mediumtext: {
|
|
1525
|
-
field[DBType.Mysql] = `${field.
|
|
1526
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1673
|
+
field[DBType.Mysql] = () => `${field.C2()} mediumtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1674
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1527
1675
|
break;
|
|
1528
1676
|
}
|
|
1529
1677
|
case SqlType.text: {
|
|
1530
|
-
field[DBType.Mysql] = `${field.
|
|
1531
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1678
|
+
field[DBType.Mysql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1679
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1532
1680
|
break;
|
|
1533
1681
|
}
|
|
1534
1682
|
case SqlType.date: {
|
|
1535
|
-
field[DBType.Mysql] = `${field.
|
|
1536
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1683
|
+
field[DBType.Mysql] = () => `${field.C2()} date ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1684
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1537
1685
|
break;
|
|
1538
1686
|
}
|
|
1539
1687
|
case SqlType.time: {
|
|
1540
|
-
field[DBType.Mysql] = `${field.
|
|
1541
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1688
|
+
field[DBType.Mysql] = () => `${field.C2()} time ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1689
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1542
1690
|
break;
|
|
1543
1691
|
}
|
|
1544
1692
|
case SqlType.year: {
|
|
1545
|
-
field[DBType.Mysql] = `${field.
|
|
1546
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1693
|
+
field[DBType.Mysql] = () => `${field.C2()} year ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1694
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1547
1695
|
break;
|
|
1548
1696
|
}
|
|
1549
1697
|
case SqlType.datetime: {
|
|
1550
|
-
field[DBType.Mysql] = `${field.
|
|
1551
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1698
|
+
field[DBType.Mysql] = () => `${field.C2()} datetime ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1699
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1552
1700
|
break;
|
|
1553
1701
|
}
|
|
1554
1702
|
case SqlType.timestamp: {
|
|
1555
|
-
field[DBType.Mysql] = `${field.
|
|
1556
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1703
|
+
field[DBType.Mysql] = () => `${field.C2()} timestamp ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1704
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} integer`;
|
|
1557
1705
|
break;
|
|
1558
1706
|
}
|
|
1559
1707
|
case SqlType.char: {
|
|
1560
|
-
field[DBType.Mysql] = `${field.
|
|
1561
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1708
|
+
field[DBType.Mysql] = () => `${field.C2()} char(${config.length ?? 1}) ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1709
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1562
1710
|
break;
|
|
1563
1711
|
}
|
|
1564
1712
|
case SqlType.varchar: {
|
|
1565
|
-
field[DBType.Mysql] = `${field.
|
|
1566
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1713
|
+
field[DBType.Mysql] = () => `${field.C2()} varchar(${config.length ?? 1}) ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1714
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1567
1715
|
break;
|
|
1568
1716
|
}
|
|
1569
1717
|
case SqlType.tinyblob: {
|
|
1570
|
-
field[DBType.Mysql] = `${field.
|
|
1571
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1718
|
+
field[DBType.Mysql] = () => `${field.C2()} tinyblob ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1719
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1572
1720
|
break;
|
|
1573
1721
|
}
|
|
1574
1722
|
case SqlType.tinytext: {
|
|
1575
|
-
field[DBType.Mysql] = `${field.
|
|
1576
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1723
|
+
field[DBType.Mysql] = () => `${field.C2()} tinytext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1724
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1577
1725
|
break;
|
|
1578
1726
|
}
|
|
1579
1727
|
case SqlType.blob: {
|
|
1580
|
-
field[DBType.Mysql] = `${field.
|
|
1581
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1728
|
+
field[DBType.Mysql] = () => `${field.C2()} binary ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1729
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1582
1730
|
break;
|
|
1583
1731
|
}
|
|
1584
1732
|
case SqlType.text: {
|
|
1585
|
-
field[DBType.Mysql] = `${field.
|
|
1586
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1733
|
+
field[DBType.Mysql] = () => `${field.C2()} text ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1734
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1587
1735
|
break;
|
|
1588
1736
|
}
|
|
1589
1737
|
case SqlType.mediumblob: {
|
|
1590
|
-
field[DBType.Mysql] = `${field.
|
|
1591
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1738
|
+
field[DBType.Mysql] = () => `${field.C2()} mediumblob ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1739
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1592
1740
|
break;
|
|
1593
1741
|
}
|
|
1594
1742
|
case SqlType.mediumtext: {
|
|
1595
|
-
field[DBType.Mysql] = `${field.
|
|
1596
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1743
|
+
field[DBType.Mysql] = () => `${field.C2()} mediumtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1744
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1597
1745
|
break;
|
|
1598
1746
|
}
|
|
1599
1747
|
case SqlType.longblob: {
|
|
1600
|
-
field[DBType.Mysql] = `${field.
|
|
1601
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1748
|
+
field[DBType.Mysql] = () => `${field.C2()} longblob ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1749
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1602
1750
|
break;
|
|
1603
1751
|
}
|
|
1604
1752
|
case SqlType.longtext: {
|
|
1605
|
-
field[DBType.Mysql] = `${field.
|
|
1606
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1753
|
+
field[DBType.Mysql] = () => `${field.C2()} longtext ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1754
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1607
1755
|
break;
|
|
1608
1756
|
}
|
|
1609
1757
|
case SqlType.set: {
|
|
1610
|
-
field[DBType.Mysql] = `${field.
|
|
1611
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1758
|
+
field[DBType.Mysql] = () => `${field.C2()} set ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1759
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1612
1760
|
break;
|
|
1613
1761
|
}
|
|
1614
1762
|
case SqlType.enum: {
|
|
1615
|
-
field[DBType.Mysql] = `${field.
|
|
1616
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1763
|
+
field[DBType.Mysql] = () => `${field.C2()} enum ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1764
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1617
1765
|
break;
|
|
1618
1766
|
}
|
|
1619
1767
|
case SqlType.json: {
|
|
1620
|
-
field[DBType.Mysql] = `${field.
|
|
1621
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1768
|
+
field[DBType.Mysql] = () => `${field.C2()} json ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1769
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1622
1770
|
break;
|
|
1623
1771
|
}
|
|
1624
1772
|
case SqlType.geometry: {
|
|
1625
|
-
field[DBType.Mysql] = `${field.
|
|
1626
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1773
|
+
field[DBType.Mysql] = () => `${field.C2()} geometry ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1774
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1627
1775
|
break;
|
|
1628
1776
|
}
|
|
1629
1777
|
case SqlType.point: {
|
|
1630
|
-
field[DBType.Mysql] = `${field.
|
|
1631
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1778
|
+
field[DBType.Mysql] = () => `${field.C2()} point ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1779
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1632
1780
|
break;
|
|
1633
1781
|
}
|
|
1634
1782
|
case SqlType.linestring: {
|
|
1635
|
-
field[DBType.Mysql] = `${field.
|
|
1636
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1783
|
+
field[DBType.Mysql] = () => `${field.C2()} linestring ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1784
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1637
1785
|
break;
|
|
1638
1786
|
}
|
|
1639
1787
|
case SqlType.polygon: {
|
|
1640
|
-
field[DBType.Mysql] = `${field.
|
|
1641
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1788
|
+
field[DBType.Mysql] = () => `${field.C2()} polygon ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1789
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1642
1790
|
break;
|
|
1643
1791
|
}
|
|
1644
1792
|
case SqlType.multipoint: {
|
|
1645
|
-
field[DBType.Mysql] = `${field.
|
|
1646
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1793
|
+
field[DBType.Mysql] = () => `${field.C2()} multipoint ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1794
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1647
1795
|
break;
|
|
1648
1796
|
}
|
|
1649
1797
|
case SqlType.multilinestring: {
|
|
1650
|
-
field[DBType.Mysql] = `${field.
|
|
1651
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1798
|
+
field[DBType.Mysql] = () => `${field.C2()} multilinestring ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1799
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1652
1800
|
break;
|
|
1653
1801
|
}
|
|
1654
1802
|
case SqlType.multipolygon: {
|
|
1655
|
-
field[DBType.Mysql] = `${field.
|
|
1656
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1803
|
+
field[DBType.Mysql] = () => `${field.C2()} multipolygon ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1804
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1657
1805
|
break;
|
|
1658
1806
|
}
|
|
1659
1807
|
case SqlType.geometrycollection: {
|
|
1660
|
-
field[DBType.Mysql] = `${field.
|
|
1661
|
-
field[DBType.SqliteRemote] = field[DBType.Sqlite] = `${field.
|
|
1808
|
+
field[DBType.Mysql] = () => `${field.C2()} geometrycollection ${config.notNull === true ? 'NOT NULL' : ''} ${MYSQLCHARSET} ${hasDef ? `DEFAULT '${field.def}'` : ''}`;
|
|
1809
|
+
field[DBType.SqliteRemote] = field[DBType.Sqlite] = () => `${field.C2()} text`;
|
|
1662
1810
|
break;
|
|
1663
1811
|
}
|
|
1664
1812
|
}
|
|
@@ -1706,7 +1854,7 @@ const Field = (config) => {
|
|
|
1706
1854
|
exports.Field = Field;
|
|
1707
1855
|
const DB = (config) => {
|
|
1708
1856
|
return function (constructor) {
|
|
1709
|
-
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
1857
|
+
var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
1710
1858
|
const __ids = Reflect.getMetadata(_ids, config.clz.prototype) || new Array;
|
|
1711
1859
|
const __fields = Reflect.getMetadata(_fields, config.clz.prototype);
|
|
1712
1860
|
const __columns = Reflect.getMetadata(_columns, config.clz.prototype);
|
|
@@ -1715,25 +1863,31 @@ const DB = (config) => {
|
|
|
1715
1863
|
const __deleteState = Reflect.getMetadata(_deleteState, config.clz.prototype);
|
|
1716
1864
|
const __index = Reflect.getMetadata(_index, config.clz.prototype);
|
|
1717
1865
|
const __def = Reflect.getMetadata(_def, config.clz.prototype);
|
|
1718
|
-
|
|
1866
|
+
const className = config.tableName?.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
1867
|
+
const ClassName = className?.replace(/\w/, (v) => v.toUpperCase());
|
|
1868
|
+
const vueName = config.tableName?.replace(/_/g, '-');
|
|
1869
|
+
return _w = class extends constructor {
|
|
1719
1870
|
constructor() {
|
|
1720
1871
|
super(...arguments);
|
|
1721
1872
|
this[_d] = config.tableName;
|
|
1722
|
-
this[_e] =
|
|
1723
|
-
this[_f] =
|
|
1724
|
-
this[_g] =
|
|
1725
|
-
this[_h] =
|
|
1726
|
-
this[_j] =
|
|
1727
|
-
this[_k] =
|
|
1728
|
-
this[_l] =
|
|
1729
|
-
this[_m] =
|
|
1730
|
-
this[_o] =
|
|
1731
|
-
this[_p] =
|
|
1732
|
-
this[_q] =
|
|
1733
|
-
this[_r] =
|
|
1734
|
-
this[_s] =
|
|
1873
|
+
this[_e] = className;
|
|
1874
|
+
this[_f] = ClassName;
|
|
1875
|
+
this[_g] = vueName;
|
|
1876
|
+
this[_h] = config.dbName;
|
|
1877
|
+
this[_j] = config.dbType ?? DBType.Mysql;
|
|
1878
|
+
this[_k] = config.sqliteVersion;
|
|
1879
|
+
this[_l] = Object.assign({}, exports._defOption, config);
|
|
1880
|
+
this[_m] = __ids;
|
|
1881
|
+
this[_o] = __fields;
|
|
1882
|
+
this[_p] = __columns;
|
|
1883
|
+
this[_q] = __columnsNoId;
|
|
1884
|
+
this[_r] = __index;
|
|
1885
|
+
this[_s] = __def;
|
|
1886
|
+
this[_t] = __stateFileName;
|
|
1887
|
+
this[_u] = __deleteState;
|
|
1888
|
+
this[_v] = (data, option) => {
|
|
1735
1889
|
return Object.fromEntries((0, iterare_1.default)(option?.skipId === true ? __columnsNoId : __columns)
|
|
1736
|
-
.map(K => [K, FieldFilter(K, data[K], __def, option)])
|
|
1890
|
+
.map(K => [K, FieldFilter(K, data[K], __def, __fields[K].uuid === true || __fields[K].uuidShort === true, option)])
|
|
1737
1891
|
.filter(data => {
|
|
1738
1892
|
if (data[1][0] === 1) {
|
|
1739
1893
|
if (option?.onFieldExists) {
|
|
@@ -1751,20 +1905,23 @@ const DB = (config) => {
|
|
|
1751
1905
|
}
|
|
1752
1906
|
},
|
|
1753
1907
|
_d = _tableName,
|
|
1754
|
-
_e =
|
|
1755
|
-
_f =
|
|
1756
|
-
_g =
|
|
1757
|
-
_h =
|
|
1758
|
-
_j =
|
|
1759
|
-
_k =
|
|
1760
|
-
_l =
|
|
1761
|
-
_m =
|
|
1762
|
-
_o =
|
|
1763
|
-
_p =
|
|
1764
|
-
_q =
|
|
1765
|
-
_r =
|
|
1766
|
-
_s =
|
|
1767
|
-
_t
|
|
1908
|
+
_e = _className,
|
|
1909
|
+
_f = _ClassName,
|
|
1910
|
+
_g = _vueName,
|
|
1911
|
+
_h = _daoDBName,
|
|
1912
|
+
_j = _dbType,
|
|
1913
|
+
_k = _sqlite_version,
|
|
1914
|
+
_l = _SqlOption,
|
|
1915
|
+
_m = _ids,
|
|
1916
|
+
_o = _fields,
|
|
1917
|
+
_p = _columns,
|
|
1918
|
+
_q = _columnsNoId,
|
|
1919
|
+
_r = _index,
|
|
1920
|
+
_s = _def,
|
|
1921
|
+
_t = _stateFileName,
|
|
1922
|
+
_u = _deleteState,
|
|
1923
|
+
_v = _transformer,
|
|
1924
|
+
_w;
|
|
1768
1925
|
};
|
|
1769
1926
|
};
|
|
1770
1927
|
exports.DB = DB;
|
|
@@ -1782,7 +1939,7 @@ exports.DB = DB;
|
|
|
1782
1939
|
*/
|
|
1783
1940
|
function DeclareClass(clz, FieldOptions) {
|
|
1784
1941
|
for (const item of FieldOptions) {
|
|
1785
|
-
tslib_1.default.__decorate([(0, exports.Field)(item)], clz.prototype, item.
|
|
1942
|
+
tslib_1.default.__decorate([(0, exports.Field)(item)], clz.prototype, item.P, void 0);
|
|
1786
1943
|
}
|
|
1787
1944
|
}
|
|
1788
1945
|
exports.DeclareClass = DeclareClass;
|
|
@@ -1821,135 +1978,194 @@ class SqlService {
|
|
|
1821
1978
|
const conditions = option.existConditionOtherThanIds || this[_ids];
|
|
1822
1979
|
error_1.Throw.if(!conditions, 'not found where condition for insertIfNotExists!');
|
|
1823
1980
|
error_1.Throw.if(conditions.length === 0, 'insertIfNotExists must have not null where!');
|
|
1824
|
-
const where = (0, iterare_1.default)(conditions).map(c => `${this[_fields][c]?.
|
|
1981
|
+
const where = (0, iterare_1.default)(conditions).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ');
|
|
1825
1982
|
const finalColumns = new Set();
|
|
1826
1983
|
const whereColumns = conditions;
|
|
1827
|
-
const params =
|
|
1828
|
-
|
|
1829
|
-
.
|
|
1830
|
-
|
|
1984
|
+
const params = [];
|
|
1985
|
+
const questMarks = datas
|
|
1986
|
+
.map(data => this[_transformer](data, { ...option, finalColumns, insert: true }))
|
|
1987
|
+
.map(data => {
|
|
1831
1988
|
const questMark = new Array();
|
|
1832
1989
|
for (const column of finalColumns) {
|
|
1833
|
-
|
|
1834
|
-
result.push(data.hasOwnProperty(column)
|
|
1990
|
+
const V = data.hasOwnProperty(column)
|
|
1835
1991
|
? data[column]
|
|
1836
1992
|
: this[_def] && this[_def].hasOwnProperty(column)
|
|
1837
1993
|
? this[_def][column]
|
|
1838
|
-
: null
|
|
1994
|
+
: null;
|
|
1995
|
+
if (V === null) {
|
|
1996
|
+
const field = this[_fields][column];
|
|
1997
|
+
if (field?.uuid) {
|
|
1998
|
+
questMark.push('UUID()');
|
|
1999
|
+
}
|
|
2000
|
+
else if (field?.uuidShort && this[_dbType] === DBType.Mysql) {
|
|
2001
|
+
questMark.push('UUID_SHORT()');
|
|
2002
|
+
}
|
|
2003
|
+
else {
|
|
2004
|
+
questMark.push('?');
|
|
2005
|
+
params.push(V);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
else {
|
|
2009
|
+
questMark.push('?');
|
|
2010
|
+
params.push(V);
|
|
2011
|
+
}
|
|
1839
2012
|
}
|
|
1840
2013
|
for (const column of whereColumns) {
|
|
1841
|
-
|
|
1842
|
-
result.push(data.hasOwnProperty(column)
|
|
2014
|
+
params.push(data.hasOwnProperty(column)
|
|
1843
2015
|
? data[column]
|
|
1844
2016
|
: this[_def] && this[_def].hasOwnProperty(column)
|
|
1845
2017
|
? this[_def][column]
|
|
1846
2018
|
: null);
|
|
1847
2019
|
}
|
|
1848
|
-
return
|
|
2020
|
+
return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
|
|
1849
2021
|
});
|
|
1850
|
-
const
|
|
1851
|
-
const
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
(${columnNames})
|
|
1856
|
-
${selects};`;
|
|
2022
|
+
const columnNames = (0, iterare_1.default)(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2023
|
+
const sql = (0, sql_formatter_1.format)(`INSERT INTO
|
|
2024
|
+
${tableName}
|
|
2025
|
+
(${columnNames})
|
|
2026
|
+
${questMarks.join(' UNION ALL ')};`);
|
|
1857
2027
|
sqls.push({ sql, params });
|
|
2028
|
+
break;
|
|
1858
2029
|
}
|
|
1859
2030
|
case InsertMode.Replace: {
|
|
1860
2031
|
const finalColumns = new Set();
|
|
1861
|
-
const params =
|
|
1862
|
-
|
|
1863
|
-
.
|
|
1864
|
-
|
|
2032
|
+
const params = [];
|
|
2033
|
+
const questMarks = datas
|
|
2034
|
+
.map(data => this[_transformer](data, { ...option, finalColumns, insert: true }))
|
|
2035
|
+
.map(data => {
|
|
1865
2036
|
const questMark = new Array();
|
|
1866
2037
|
for (const column of finalColumns) {
|
|
1867
|
-
|
|
1868
|
-
result.push(data.hasOwnProperty(column)
|
|
2038
|
+
const V = data.hasOwnProperty(column)
|
|
1869
2039
|
? data[column]
|
|
1870
2040
|
: this[_def] && this[_def].hasOwnProperty(column)
|
|
1871
2041
|
? this[_def][column]
|
|
1872
|
-
: null
|
|
2042
|
+
: null;
|
|
2043
|
+
if (V === null) {
|
|
2044
|
+
const field = this[_fields][column];
|
|
2045
|
+
if (field?.uuid) {
|
|
2046
|
+
questMark.push('UUID()');
|
|
2047
|
+
}
|
|
2048
|
+
else if (field?.uuidShort && this[_dbType] === DBType.Mysql) {
|
|
2049
|
+
questMark.push('UUID_SHORT()');
|
|
2050
|
+
}
|
|
2051
|
+
else {
|
|
2052
|
+
questMark.push('?');
|
|
2053
|
+
params.push(V);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
else {
|
|
2057
|
+
questMark.push('?');
|
|
2058
|
+
params.push(V);
|
|
2059
|
+
}
|
|
1873
2060
|
}
|
|
1874
|
-
return
|
|
2061
|
+
return `(${questMark.join(',')})`;
|
|
1875
2062
|
});
|
|
1876
|
-
const
|
|
1877
|
-
const
|
|
1878
|
-
const questMarks = (0, iterare_1.default)(new Array(datas.length)).map(() => `(${quests})`).join(',');
|
|
1879
|
-
const sql = `
|
|
2063
|
+
const columnNames = (0, iterare_1.default)(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2064
|
+
const sql = (0, sql_formatter_1.format)(`
|
|
1880
2065
|
${this[_dbType] === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
|
|
1881
2066
|
${tableName}
|
|
1882
2067
|
(${columnNames})
|
|
1883
2068
|
VALUES ${questMarks};
|
|
1884
|
-
|
|
2069
|
+
`);
|
|
1885
2070
|
sqls.push({ sql, params });
|
|
2071
|
+
break;
|
|
1886
2072
|
}
|
|
1887
2073
|
case InsertMode.Insert: {
|
|
1888
2074
|
const finalColumns = new Set();
|
|
1889
|
-
const params =
|
|
1890
|
-
|
|
1891
|
-
.
|
|
1892
|
-
|
|
2075
|
+
const params = [];
|
|
2076
|
+
const questMarks = datas
|
|
2077
|
+
.map(data => this[_transformer](data, { ...option, finalColumns, insert: true }))
|
|
2078
|
+
.map(data => {
|
|
1893
2079
|
const questMark = new Array();
|
|
1894
2080
|
for (const column of finalColumns) {
|
|
1895
|
-
|
|
1896
|
-
result.push(data.hasOwnProperty(column)
|
|
2081
|
+
const V = data.hasOwnProperty(column)
|
|
1897
2082
|
? data[column]
|
|
1898
2083
|
: this[_def] && this[_def].hasOwnProperty(column)
|
|
1899
2084
|
? this[_def][column]
|
|
1900
|
-
: null
|
|
2085
|
+
: null;
|
|
2086
|
+
if (V === null) {
|
|
2087
|
+
const field = this[_fields][column];
|
|
2088
|
+
if (field?.uuid) {
|
|
2089
|
+
questMark.push('UUID()');
|
|
2090
|
+
}
|
|
2091
|
+
else if (field?.uuidShort && this[_dbType] === DBType.Mysql) {
|
|
2092
|
+
questMark.push('UUID_SHORT()');
|
|
2093
|
+
}
|
|
2094
|
+
else {
|
|
2095
|
+
questMark.push('?');
|
|
2096
|
+
params.push(V);
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
else {
|
|
2100
|
+
questMark.push('?');
|
|
2101
|
+
params.push(V);
|
|
2102
|
+
}
|
|
1901
2103
|
}
|
|
1902
|
-
return
|
|
2104
|
+
return `(${questMark.join(',')})`;
|
|
1903
2105
|
});
|
|
1904
|
-
const
|
|
1905
|
-
const
|
|
1906
|
-
const questMarks = (0, iterare_1.default)(new Array(datas.length)).map(() => `(${quests})`).join(',');
|
|
1907
|
-
const sql = `
|
|
2106
|
+
const columnNames = (0, iterare_1.default)(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
2107
|
+
const sql = (0, sql_formatter_1.format)(`
|
|
1908
2108
|
INSERT INTO
|
|
1909
2109
|
${tableName}
|
|
1910
2110
|
(${columnNames})
|
|
1911
2111
|
VALUES ${questMarks};
|
|
1912
|
-
|
|
2112
|
+
`);
|
|
1913
2113
|
sqls.push({ sql, params });
|
|
2114
|
+
break;
|
|
1914
2115
|
}
|
|
1915
2116
|
case InsertMode.InsertWithTempTable: {
|
|
1916
2117
|
const tableTemp = `${option?.tableName}_${Math.random()}`.replace(/\./, '');
|
|
1917
2118
|
const tableTempESC = sqlstring_1.default.escapeId(tableTemp);
|
|
1918
2119
|
sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
|
|
1919
2120
|
const finalColumns = new Set();
|
|
1920
|
-
const params =
|
|
1921
|
-
|
|
1922
|
-
.
|
|
1923
|
-
|
|
2121
|
+
const params = [];
|
|
2122
|
+
const questMarks = datas
|
|
2123
|
+
.map(data => this[_transformer](data, { ...option, finalColumns, insert: true }))
|
|
2124
|
+
.map(data => {
|
|
1924
2125
|
const questMark = new Array();
|
|
1925
2126
|
for (const column of finalColumns) {
|
|
1926
|
-
|
|
1927
|
-
result.push(data.hasOwnProperty(column)
|
|
2127
|
+
const V = data.hasOwnProperty(column)
|
|
1928
2128
|
? data[column]
|
|
1929
2129
|
: this[_def] && this[_def].hasOwnProperty(column)
|
|
1930
2130
|
? this[_def][column]
|
|
1931
|
-
: null
|
|
2131
|
+
: null;
|
|
2132
|
+
if (V === null) {
|
|
2133
|
+
const field = this[_fields][column];
|
|
2134
|
+
if (field?.uuid) {
|
|
2135
|
+
questMark.push('UUID()');
|
|
2136
|
+
}
|
|
2137
|
+
else if (field?.uuidShort && this[_dbType] === DBType.Mysql) {
|
|
2138
|
+
questMark.push('UUID_SHORT()');
|
|
2139
|
+
}
|
|
2140
|
+
else {
|
|
2141
|
+
questMark.push('?');
|
|
2142
|
+
params.push(V);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
else {
|
|
2146
|
+
questMark.push('?');
|
|
2147
|
+
params.push(V);
|
|
2148
|
+
}
|
|
1932
2149
|
}
|
|
1933
|
-
return
|
|
2150
|
+
return `(${questMark.join(',')})`;
|
|
1934
2151
|
});
|
|
1935
2152
|
const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: Array.from(finalColumns) });
|
|
1936
2153
|
sqls.push(..._sqls);
|
|
1937
|
-
const
|
|
1938
|
-
const columnNames = (0, iterare_1.default)(finalColumns).map(i => this[_fields][i]?.esName).join(',');
|
|
1939
|
-
const questMarks = (0, iterare_1.default)(new Array(datas.length)).map(() => `(${quests})`).join(',');
|
|
2154
|
+
const columnNames = (0, iterare_1.default)(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
|
|
1940
2155
|
sqls.push({
|
|
1941
|
-
sql: `
|
|
2156
|
+
sql: (0, sql_formatter_1.format)(`
|
|
1942
2157
|
INSERT INTO
|
|
1943
2158
|
${tableTemp}
|
|
1944
2159
|
(${columnNames})
|
|
1945
2160
|
VALUES ${questMarks};
|
|
1946
|
-
|
|
2161
|
+
`), params
|
|
1947
2162
|
});
|
|
1948
2163
|
sqls.push({
|
|
1949
|
-
sql: `INSERT INTO ${sqlstring_1.default.escapeId(option.tableName)} (${columnNames})
|
|
1950
|
-
SELECT ${columnNames} FROM ${tableTemp};`
|
|
2164
|
+
sql: (0, sql_formatter_1.format)(`INSERT INTO ${sqlstring_1.default.escapeId(option.tableName)} (${columnNames})
|
|
2165
|
+
SELECT ${columnNames} FROM ${tableTemp};`)
|
|
1951
2166
|
});
|
|
1952
2167
|
sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
|
|
2168
|
+
break;
|
|
1953
2169
|
}
|
|
1954
2170
|
}
|
|
1955
2171
|
return sqls;
|
|
@@ -1976,7 +2192,7 @@ class SqlService {
|
|
|
1976
2192
|
else
|
|
1977
2193
|
return result[0];
|
|
1978
2194
|
};
|
|
1979
|
-
if (option?.conn?.[_inTransaction] === true) {
|
|
2195
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
1980
2196
|
return fn();
|
|
1981
2197
|
}
|
|
1982
2198
|
else {
|
|
@@ -2000,12 +2216,17 @@ class SqlService {
|
|
|
2000
2216
|
return result;
|
|
2001
2217
|
}, option?.conn);
|
|
2002
2218
|
};
|
|
2003
|
-
return new Promise(async (resolve) => {
|
|
2004
|
-
|
|
2005
|
-
|
|
2219
|
+
return new Promise(async (resolve, reject) => {
|
|
2220
|
+
try {
|
|
2221
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2222
|
+
resolve((await fn()));
|
|
2223
|
+
}
|
|
2224
|
+
else {
|
|
2225
|
+
await option?.dao?.transaction(SyncMode.Async, async () => resolve((await fn())), option?.conn);
|
|
2226
|
+
}
|
|
2006
2227
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2228
|
+
catch (error) {
|
|
2229
|
+
reject(error);
|
|
2009
2230
|
}
|
|
2010
2231
|
});
|
|
2011
2232
|
}
|
|
@@ -2024,12 +2245,17 @@ class SqlService {
|
|
|
2024
2245
|
}, { everyLength: 1 });
|
|
2025
2246
|
return result[0];
|
|
2026
2247
|
};
|
|
2027
|
-
return new Promise(async (resolve) => {
|
|
2028
|
-
|
|
2029
|
-
|
|
2248
|
+
return new Promise(async (resolve, reject) => {
|
|
2249
|
+
try {
|
|
2250
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2251
|
+
resolve((await fn()));
|
|
2252
|
+
}
|
|
2253
|
+
else {
|
|
2254
|
+
await option?.dao?.transaction(SyncMode.Async, async () => resolve((await fn())), option?.conn);
|
|
2255
|
+
}
|
|
2030
2256
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2257
|
+
catch (error) {
|
|
2258
|
+
reject(error);
|
|
2033
2259
|
}
|
|
2034
2260
|
});
|
|
2035
2261
|
}
|
|
@@ -2037,7 +2263,7 @@ class SqlService {
|
|
|
2037
2263
|
_update(datas, option) {
|
|
2038
2264
|
const sqls = [];
|
|
2039
2265
|
const tableName = sqlstring_1.default.escapeId(option?.tableName);
|
|
2040
|
-
const where = `WHEN ${(0, iterare_1.default)(this[_ids]).map(c => `${this[_fields][c]?.
|
|
2266
|
+
const where = `WHEN ${(0, iterare_1.default)(this[_ids]).map(c => `${this[_fields][c]?.C2()} = ?`).join(' AND ')} THEN ?`;
|
|
2041
2267
|
const columnMaps = Object.fromEntries(this[_columnsNoId].map(c => [c, {
|
|
2042
2268
|
where: new Array(),
|
|
2043
2269
|
params: []
|
|
@@ -2057,13 +2283,13 @@ class SqlService {
|
|
|
2057
2283
|
}
|
|
2058
2284
|
});
|
|
2059
2285
|
}
|
|
2060
|
-
const sql = `UPDATE ${tableName} SET ${(0, iterare_1.default)(this[_columnsNoId])
|
|
2286
|
+
const sql = (0, sql_formatter_1.format)(`UPDATE ${tableName} SET ${(0, iterare_1.default)(this[_columnsNoId])
|
|
2061
2287
|
.filter(K => columnMaps[K].where.length > 0)
|
|
2062
2288
|
.map(K => {
|
|
2063
2289
|
params.push(...columnMaps[K].params);
|
|
2064
|
-
return `${this[_fields][K]?.
|
|
2290
|
+
return `${this[_fields][K]?.C2()} = CASE ${columnMaps[K].where.join(' ')} ELSE ${this[_fields][K]?.C2()} END`;
|
|
2065
2291
|
})
|
|
2066
|
-
.join(',')}
|
|
2292
|
+
.join(',')};`);
|
|
2067
2293
|
sqls.push({ sql, params });
|
|
2068
2294
|
return sqls;
|
|
2069
2295
|
}
|
|
@@ -2085,7 +2311,7 @@ class SqlService {
|
|
|
2085
2311
|
}, { everyLength: option?.maxDeal });
|
|
2086
2312
|
return result.reduce((a, b) => a + b);
|
|
2087
2313
|
};
|
|
2088
|
-
if (option?.conn?.[_inTransaction] === true) {
|
|
2314
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2089
2315
|
return fn();
|
|
2090
2316
|
}
|
|
2091
2317
|
else {
|
|
@@ -2107,12 +2333,17 @@ class SqlService {
|
|
|
2107
2333
|
}, { everyLength: option?.maxDeal });
|
|
2108
2334
|
return result.reduce((a, b) => a + b);
|
|
2109
2335
|
};
|
|
2110
|
-
return new Promise(async (resolve) => {
|
|
2111
|
-
|
|
2112
|
-
|
|
2336
|
+
return new Promise(async (resolve, reject) => {
|
|
2337
|
+
try {
|
|
2338
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2339
|
+
resolve((await fn()));
|
|
2340
|
+
}
|
|
2341
|
+
else {
|
|
2342
|
+
await option?.dao?.transaction(SyncMode.Async, async () => resolve((await fn())), option?.conn);
|
|
2343
|
+
}
|
|
2113
2344
|
}
|
|
2114
|
-
|
|
2115
|
-
|
|
2345
|
+
catch (error) {
|
|
2346
|
+
reject(error);
|
|
2116
2347
|
}
|
|
2117
2348
|
});
|
|
2118
2349
|
}
|
|
@@ -2140,20 +2371,20 @@ class SqlService {
|
|
|
2140
2371
|
return `(
|
|
2141
2372
|
${Object.entries(where).map(([K, V]) => {
|
|
2142
2373
|
params.push(V);
|
|
2143
|
-
return `${K} = ?`;
|
|
2374
|
+
return `${this[_fields][K]?.C2()} = ?`;
|
|
2144
2375
|
}).join(' AND ')}
|
|
2145
2376
|
)`;
|
|
2146
2377
|
}).join(' OR ');
|
|
2147
2378
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2148
2379
|
sqls.push({
|
|
2149
|
-
sql: `
|
|
2150
|
-
UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.
|
|
2380
|
+
sql: (0, sql_formatter_1.format)(`
|
|
2381
|
+
UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ${sqlstring_1.default.escape(this[_deleteState])}
|
|
2151
2382
|
WHERE ${whereSql};
|
|
2152
|
-
|
|
2383
|
+
`), params
|
|
2153
2384
|
});
|
|
2154
2385
|
}
|
|
2155
2386
|
else {
|
|
2156
|
-
sqls.push({ sql: `DELETE FROM ${tableNameESC} WHERE ${whereSql}
|
|
2387
|
+
sqls.push({ sql: (0, sql_formatter_1.format)(`DELETE FROM ${tableNameESC} WHERE ${whereSql};`), params });
|
|
2157
2388
|
}
|
|
2158
2389
|
}
|
|
2159
2390
|
else {
|
|
@@ -2165,28 +2396,30 @@ class SqlService {
|
|
|
2165
2396
|
case DBType.Mysql: {
|
|
2166
2397
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2167
2398
|
sqls.push({
|
|
2168
|
-
sql: `UPDATE ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.
|
|
2169
|
-
SET a.${this[_fields][this[_stateFileName]]?.
|
|
2399
|
+
sql: (0, sql_formatter_1.format)(`UPDATE ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')}
|
|
2400
|
+
SET a.${this[_fields][this[_stateFileName]]?.C2()} = ${sqlstring_1.default.escape(this[_deleteState])};`)
|
|
2170
2401
|
});
|
|
2171
2402
|
}
|
|
2172
2403
|
else {
|
|
2173
2404
|
sqls.push({
|
|
2174
|
-
sql: `DELETE a.* FROM ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.
|
|
2405
|
+
sql: (0, sql_formatter_1.format)(`DELETE a.* FROM ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')};`)
|
|
2175
2406
|
});
|
|
2176
2407
|
}
|
|
2408
|
+
break;
|
|
2177
2409
|
}
|
|
2178
2410
|
case DBType.Sqlite:
|
|
2179
2411
|
case DBType.SqliteRemote: {
|
|
2180
|
-
const columnNames = (0, iterare_1.default)(delWhere).map(K => this[_fields][K]?.
|
|
2412
|
+
const columnNames = (0, iterare_1.default)(delWhere).map(K => this[_fields][K]?.C2()).join(',');
|
|
2181
2413
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2182
2414
|
sqls.push({
|
|
2183
|
-
sql: `UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.
|
|
2184
|
-
WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`
|
|
2415
|
+
sql: (0, sql_formatter_1.format)(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ${sqlstring_1.default.escape(this[_deleteState])}
|
|
2416
|
+
WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`)
|
|
2185
2417
|
});
|
|
2186
2418
|
}
|
|
2187
2419
|
else {
|
|
2188
|
-
sqls.push({ sql: `DELETE FROM ${tableNameESC} WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});` });
|
|
2420
|
+
sqls.push({ sql: (0, sql_formatter_1.format)(`DELETE FROM ${tableNameESC} WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`) });
|
|
2189
2421
|
}
|
|
2422
|
+
break;
|
|
2190
2423
|
}
|
|
2191
2424
|
}
|
|
2192
2425
|
sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
|
|
@@ -2200,7 +2433,7 @@ class SqlService {
|
|
|
2200
2433
|
}
|
|
2201
2434
|
return result;
|
|
2202
2435
|
};
|
|
2203
|
-
if (option?.conn?.[_inTransaction] === true) {
|
|
2436
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2204
2437
|
return fn();
|
|
2205
2438
|
}
|
|
2206
2439
|
else {
|
|
@@ -2216,12 +2449,17 @@ class SqlService {
|
|
|
2216
2449
|
}
|
|
2217
2450
|
return result;
|
|
2218
2451
|
};
|
|
2219
|
-
return new Promise(async (resolve) => {
|
|
2220
|
-
|
|
2221
|
-
|
|
2452
|
+
return new Promise(async (resolve, reject) => {
|
|
2453
|
+
try {
|
|
2454
|
+
if (this[_dbType] === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
|
|
2455
|
+
resolve((await fn()));
|
|
2456
|
+
}
|
|
2457
|
+
else {
|
|
2458
|
+
await option?.dao?.transaction(SyncMode.Async, async () => resolve((await fn())), option?.conn);
|
|
2459
|
+
}
|
|
2222
2460
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2461
|
+
catch (error) {
|
|
2462
|
+
reject(error);
|
|
2225
2463
|
}
|
|
2226
2464
|
});
|
|
2227
2465
|
}
|
|
@@ -2261,19 +2499,19 @@ class SqlService {
|
|
|
2261
2499
|
const ids = option.id instanceof Array ? option.id : [option.id];
|
|
2262
2500
|
option.where = ids.map(i => ({ [idName]: i }));
|
|
2263
2501
|
}
|
|
2264
|
-
const columns = option.templateResult === TemplateResult.Count ? 'COUNT(1) ct' : (0, iterare_1.default)((option.columns ?? this[_columns])).map((K) => `a.${this[_fields][K]?.
|
|
2502
|
+
const columns = option.templateResult === TemplateResult.Count ? 'COUNT(1) ct' : (0, iterare_1.default)((option.columns ?? this[_columns])).map((K) => `a.${this[_fields][K]?.C3()}`).join(',');
|
|
2265
2503
|
const wheres = option.where instanceof Array ? option.where : [option.where];
|
|
2266
2504
|
const sqls = [];
|
|
2267
2505
|
let resultIndex = -1;
|
|
2268
2506
|
if (option.mode === SelectMode.Common) {
|
|
2269
2507
|
const params = new Array();
|
|
2270
|
-
const whereSql = (0, iterare_1.default)(wheres).map(where => {
|
|
2508
|
+
const whereSql = (0, sql_formatter_1.format)((0, iterare_1.default)(wheres).map(where => this[_transformer](where, option)).map(where => {
|
|
2271
2509
|
return `SELECT ${columns} FROM ${tableNameESC} a WHERE
|
|
2272
2510
|
${Object.entries(where).map(([K, V]) => {
|
|
2273
2511
|
params.push(V);
|
|
2274
|
-
return `${K} = ?`;
|
|
2512
|
+
return `${this[_fields][K]?.C2()} = ?`;
|
|
2275
2513
|
}).join(' AND ')}`;
|
|
2276
|
-
}).join(' UNION ALL ');
|
|
2514
|
+
}).join(' UNION ALL '));
|
|
2277
2515
|
sqls.push({ sql: whereSql, params });
|
|
2278
2516
|
resultIndex = 0;
|
|
2279
2517
|
}
|
|
@@ -2283,7 +2521,7 @@ class SqlService {
|
|
|
2283
2521
|
const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: delWhere, data: wheres, index: 'all', id: 'none' });
|
|
2284
2522
|
sqls.push(..._sqls);
|
|
2285
2523
|
resultIndex = sqls.length;
|
|
2286
|
-
sqls.push({ sql: `SELECT ${columns} FROM ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.
|
|
2524
|
+
sqls.push({ sql: (0, sql_formatter_1.format)(`SELECT ${columns} FROM ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')};`) });
|
|
2287
2525
|
sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
|
|
2288
2526
|
}
|
|
2289
2527
|
if (option.sync === SyncMode.Sync) {
|
|
@@ -2299,21 +2537,26 @@ class SqlService {
|
|
|
2299
2537
|
return this._template(option.templateResult, result, option.error);
|
|
2300
2538
|
}
|
|
2301
2539
|
else {
|
|
2302
|
-
return new Promise(async (resolve) => {
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2540
|
+
return new Promise(async (resolve, reject) => {
|
|
2541
|
+
try {
|
|
2542
|
+
let result;
|
|
2543
|
+
for (let i = 0; i < sqls.length; i++) {
|
|
2544
|
+
if (i === resultIndex) {
|
|
2545
|
+
result = await option.conn.query(SyncMode.Async, sqls[i]?.sql, sqls[i]?.params);
|
|
2546
|
+
}
|
|
2547
|
+
else {
|
|
2548
|
+
await option.conn.execute(SyncMode.Async, sqls[i]?.sql, sqls[i]?.params);
|
|
2549
|
+
}
|
|
2310
2550
|
}
|
|
2551
|
+
resolve(this._template(option.templateResult, result, option.error));
|
|
2552
|
+
}
|
|
2553
|
+
catch (error) {
|
|
2554
|
+
reject(error);
|
|
2311
2555
|
}
|
|
2312
|
-
resolve(this._template(option.templateResult, result, option.error));
|
|
2313
2556
|
});
|
|
2314
2557
|
}
|
|
2315
2558
|
}
|
|
2316
|
-
_select(templateResult, result, def, errorMsg, multiple) {
|
|
2559
|
+
_select(templateResult, result, def, errorMsg, multiple, hump) {
|
|
2317
2560
|
if (multiple === true) {
|
|
2318
2561
|
switch (templateResult) {
|
|
2319
2562
|
case SelectResult.One_Row_One_Column_NotSure: {
|
|
@@ -2332,6 +2575,9 @@ class SqlService {
|
|
|
2332
2575
|
}
|
|
2333
2576
|
case SelectResult.One_Row_Many_Column_NotSure: {
|
|
2334
2577
|
try {
|
|
2578
|
+
if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
|
|
2579
|
+
return result.map((r) => (0, object_1.C2P2)(r[0]));
|
|
2580
|
+
}
|
|
2335
2581
|
return result.map((r) => r[0]);
|
|
2336
2582
|
}
|
|
2337
2583
|
catch (error) {
|
|
@@ -2339,6 +2585,9 @@ class SqlService {
|
|
|
2339
2585
|
}
|
|
2340
2586
|
case SelectResult.One_Row_Many_Column_Assert: {
|
|
2341
2587
|
try {
|
|
2588
|
+
if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
|
|
2589
|
+
return (0, iterare_1.default)(result).map((r) => (0, object_1.C2P2)(r[0])).filter((r) => r !== null).toArray();
|
|
2590
|
+
}
|
|
2342
2591
|
return (0, iterare_1.default)(result).map((r) => r[0]).filter((r) => r !== null).toArray();
|
|
2343
2592
|
}
|
|
2344
2593
|
catch (error) {
|
|
@@ -2352,7 +2601,12 @@ class SqlService {
|
|
|
2352
2601
|
}
|
|
2353
2602
|
}
|
|
2354
2603
|
case SelectResult.Many_Row_Many_Column: {
|
|
2355
|
-
|
|
2604
|
+
if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
|
|
2605
|
+
return (0, iterare_1.default)(result).map((r) => r.map((rr) => (0, object_1.C2P2)(rr))).toArray();
|
|
2606
|
+
}
|
|
2607
|
+
else {
|
|
2608
|
+
return result;
|
|
2609
|
+
}
|
|
2356
2610
|
}
|
|
2357
2611
|
}
|
|
2358
2612
|
}
|
|
@@ -2377,12 +2631,22 @@ class SqlService {
|
|
|
2377
2631
|
}
|
|
2378
2632
|
}
|
|
2379
2633
|
case SelectResult.One_Row_Many_Column_NotSure: {
|
|
2380
|
-
|
|
2634
|
+
if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
|
|
2635
|
+
return (0, object_1.C2P2)(result[0]) ?? null;
|
|
2636
|
+
}
|
|
2637
|
+
else {
|
|
2638
|
+
return result[0] ?? null;
|
|
2639
|
+
}
|
|
2381
2640
|
}
|
|
2382
2641
|
case SelectResult.One_Row_Many_Column_Assert: {
|
|
2383
2642
|
const data = result[0];
|
|
2384
|
-
error_1.Throw.if(data === null, errorMsg ?? 'not found data!');
|
|
2385
|
-
|
|
2643
|
+
error_1.Throw.if(data === null || data === undefined, errorMsg ?? 'not found data!');
|
|
2644
|
+
if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
|
|
2645
|
+
return (0, object_1.C2P2)(data) ?? null;
|
|
2646
|
+
}
|
|
2647
|
+
else {
|
|
2648
|
+
return data ?? null;
|
|
2649
|
+
}
|
|
2386
2650
|
}
|
|
2387
2651
|
case SelectResult.Many_Row_One_Column: {
|
|
2388
2652
|
try {
|
|
@@ -2393,7 +2657,12 @@ class SqlService {
|
|
|
2393
2657
|
}
|
|
2394
2658
|
}
|
|
2395
2659
|
case SelectResult.Many_Row_Many_Column: {
|
|
2396
|
-
|
|
2660
|
+
if (hump === true || (hump === undefined && globalThis[exports._Hump] === true)) {
|
|
2661
|
+
return (0, iterare_1.default)(result).map((r) => (0, object_1.C2P2)(r)).toArray();
|
|
2662
|
+
}
|
|
2663
|
+
else {
|
|
2664
|
+
return result;
|
|
2665
|
+
}
|
|
2397
2666
|
}
|
|
2398
2667
|
}
|
|
2399
2668
|
}
|
|
@@ -2403,8 +2672,7 @@ class SqlService {
|
|
|
2403
2672
|
option.selectResult ?? (option.selectResult = SelectResult.Many_Row_Many_Column);
|
|
2404
2673
|
option.defValue ?? (option.defValue = null);
|
|
2405
2674
|
const _params = Object.assign({}, option.context, option.params);
|
|
2406
|
-
option.sql ?? (option.sql = globalThis[_sqlCache].load(option.sqlId, { ctx: option.context, isCount: option.isCount, ..._params }));
|
|
2407
|
-
logger.debug(option.sql);
|
|
2675
|
+
option.sql ?? (option.sql = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: option.isCount, ..._params }));
|
|
2408
2676
|
const params = [];
|
|
2409
2677
|
const sql = option.sql?.replace(/\:(\w+)/g, (txt, key) => {
|
|
2410
2678
|
if (_params.hasOwnProperty(key)) {
|
|
@@ -2412,24 +2680,40 @@ class SqlService {
|
|
|
2412
2680
|
params.push(V);
|
|
2413
2681
|
return sqlstring_1.default.escape(_params[key]);
|
|
2414
2682
|
}
|
|
2683
|
+
const _key = (0, object_1.C2P)(key);
|
|
2684
|
+
if (_params.hasOwnProperty(_key)) {
|
|
2685
|
+
const V = _params[_key];
|
|
2686
|
+
params.push(V);
|
|
2687
|
+
return sqlstring_1.default.escape(_params[_key]);
|
|
2688
|
+
}
|
|
2689
|
+
const __key = (0, object_1.P2C)(key);
|
|
2690
|
+
if (_params.hasOwnProperty(__key)) {
|
|
2691
|
+
const V = _params[__key];
|
|
2692
|
+
params.push(V);
|
|
2693
|
+
return sqlstring_1.default.escape(_params[__key]);
|
|
2694
|
+
}
|
|
2415
2695
|
return txt;
|
|
2416
2696
|
});
|
|
2417
2697
|
if (option.sync === SyncMode.Sync) {
|
|
2418
2698
|
const result = option.conn.query(SyncMode.Sync, sql, params);
|
|
2419
|
-
return this._select(option.selectResult, result, option.defValue, option.errorMsg, option.multiple);
|
|
2699
|
+
return this._select(option.selectResult, result, option.defValue, option.errorMsg, option.multiple, option.hump);
|
|
2420
2700
|
}
|
|
2421
2701
|
else {
|
|
2422
|
-
return new Promise(async (resolve) => {
|
|
2423
|
-
|
|
2424
|
-
|
|
2702
|
+
return new Promise(async (resolve, reject) => {
|
|
2703
|
+
try {
|
|
2704
|
+
const result = await option.conn.query(SyncMode.Async, sql, params);
|
|
2705
|
+
resolve(this._select(option.selectResult, result, option.defValue, option.errorMsg, option.multiple));
|
|
2706
|
+
}
|
|
2707
|
+
catch (error) {
|
|
2708
|
+
reject(error);
|
|
2709
|
+
}
|
|
2425
2710
|
});
|
|
2426
2711
|
}
|
|
2427
2712
|
}
|
|
2428
2713
|
excute(option) {
|
|
2429
2714
|
error_1.Throw.if(!option.sqlId && !option.sql, 'not found sql!');
|
|
2430
2715
|
const _params = Object.assign({}, option.context, option.params);
|
|
2431
|
-
option.sql ?? (option.sql = globalThis[_sqlCache].load(option.sqlId, { ctx: option.context, ..._params }));
|
|
2432
|
-
logger.debug(option.sql);
|
|
2716
|
+
option.sql ?? (option.sql = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, ..._params }));
|
|
2433
2717
|
const params = [];
|
|
2434
2718
|
const sql = option.sql?.replace(/\:(\w+)/g, (txt, key) => {
|
|
2435
2719
|
if (_params.hasOwnProperty(key)) {
|
|
@@ -2437,6 +2721,18 @@ class SqlService {
|
|
|
2437
2721
|
params.push(V);
|
|
2438
2722
|
return sqlstring_1.default.escape(_params[key]);
|
|
2439
2723
|
}
|
|
2724
|
+
const _key = (0, object_1.C2P)(key);
|
|
2725
|
+
if (_params.hasOwnProperty(_key)) {
|
|
2726
|
+
const V = _params[_key];
|
|
2727
|
+
params.push(V);
|
|
2728
|
+
return sqlstring_1.default.escape(_params[_key]);
|
|
2729
|
+
}
|
|
2730
|
+
const __key = (0, object_1.P2C)(key);
|
|
2731
|
+
if (_params.hasOwnProperty(__key)) {
|
|
2732
|
+
const V = _params[__key];
|
|
2733
|
+
params.push(V);
|
|
2734
|
+
return sqlstring_1.default.escape(_params[__key]);
|
|
2735
|
+
}
|
|
2440
2736
|
return txt;
|
|
2441
2737
|
});
|
|
2442
2738
|
if (option.sync === SyncMode.Sync) {
|
|
@@ -2444,9 +2740,14 @@ class SqlService {
|
|
|
2444
2740
|
return result.affectedRows;
|
|
2445
2741
|
}
|
|
2446
2742
|
else {
|
|
2447
|
-
return new Promise(async (resolve) => {
|
|
2448
|
-
|
|
2449
|
-
|
|
2743
|
+
return new Promise(async (resolve, reject) => {
|
|
2744
|
+
try {
|
|
2745
|
+
const result = await option.conn.execute(SyncMode.Async, sql, params);
|
|
2746
|
+
resolve(result.affectedRows);
|
|
2747
|
+
}
|
|
2748
|
+
catch (error) {
|
|
2749
|
+
reject(error);
|
|
2750
|
+
}
|
|
2450
2751
|
});
|
|
2451
2752
|
}
|
|
2452
2753
|
}
|
|
@@ -2455,14 +2756,127 @@ class SqlService {
|
|
|
2455
2756
|
return option.dao.transaction(SyncMode.Sync, option.fn);
|
|
2456
2757
|
}
|
|
2457
2758
|
else {
|
|
2458
|
-
return new Promise(async (resolve) => {
|
|
2459
|
-
|
|
2460
|
-
|
|
2759
|
+
return new Promise(async (resolve, reject) => {
|
|
2760
|
+
try {
|
|
2761
|
+
const rt = await option.dao.transaction(SyncMode.Async, option.fn);
|
|
2762
|
+
resolve(rt);
|
|
2763
|
+
}
|
|
2764
|
+
catch (error) {
|
|
2765
|
+
reject(error);
|
|
2766
|
+
}
|
|
2461
2767
|
});
|
|
2462
2768
|
}
|
|
2463
2769
|
}
|
|
2464
2770
|
stream(option) {
|
|
2465
|
-
return new StreamQuery(option?.tableName ?? this[_tableName], this);
|
|
2771
|
+
return new StreamQuery(option?.tableName ?? this[_tableName], this, this[_fields], this[_columns]);
|
|
2772
|
+
}
|
|
2773
|
+
page(option) {
|
|
2774
|
+
const result = {
|
|
2775
|
+
sum: {},
|
|
2776
|
+
records: [],
|
|
2777
|
+
size: 0,
|
|
2778
|
+
total: 0
|
|
2779
|
+
};
|
|
2780
|
+
Object.assign(option.params, {
|
|
2781
|
+
limitStart: (0, math_1.calc)(option.pageNumber).sub(1).mul(option.pageSize).over(),
|
|
2782
|
+
limitEnd: (0, math_1.calc)(option.pageSize).over(),
|
|
2783
|
+
orderBy: option.orderBy
|
|
2784
|
+
});
|
|
2785
|
+
let sql = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, ...option.params });
|
|
2786
|
+
let sqlSum = '';
|
|
2787
|
+
let sqlCount = '';
|
|
2788
|
+
if (option.sumSelf === true) {
|
|
2789
|
+
sqlSum = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, isSum: true, ...option.params });
|
|
2790
|
+
}
|
|
2791
|
+
if (option.limitSelf !== true) {
|
|
2792
|
+
if (option.countSelf !== true) {
|
|
2793
|
+
}
|
|
2794
|
+
if (option.orderBy) {
|
|
2795
|
+
sql = `${sql} ORDER BY ${option.orderBy}`;
|
|
2796
|
+
}
|
|
2797
|
+
if (option.pageSize > 0) {
|
|
2798
|
+
sql = `${sql} LIMIT ${option.params['limitStart']}, ${option.pageSize}`;
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
if (option.pageSize > 0) {
|
|
2802
|
+
if (option.countSelf === true) {
|
|
2803
|
+
sqlCount = globalThis[exports._sqlCache].load(this._matchSqlid(`${option.sqlId}_count`), { ctx: option.context, isCount: true, isSum: false, ...option.params });
|
|
2804
|
+
}
|
|
2805
|
+
else {
|
|
2806
|
+
sqlCount = globalThis[exports._sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: true, isSum: false, ...option.params });
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
if (option.sync === SyncMode.Sync) {
|
|
2810
|
+
if (sqlCount) {
|
|
2811
|
+
result.total = this.select({
|
|
2812
|
+
...option,
|
|
2813
|
+
sql: sqlCount,
|
|
2814
|
+
sync: SyncMode.Sync,
|
|
2815
|
+
selectResult: SelectResult.One_Row_One_Column_Assert
|
|
2816
|
+
});
|
|
2817
|
+
result.size = (0, math_1.calc)(result.total)
|
|
2818
|
+
.add(option.pageSize - 1)
|
|
2819
|
+
.div(option.pageSize)
|
|
2820
|
+
.round(0, 2)
|
|
2821
|
+
.over();
|
|
2822
|
+
}
|
|
2823
|
+
if (sqlSum) {
|
|
2824
|
+
result.sum = this.select({
|
|
2825
|
+
...option,
|
|
2826
|
+
sql: sqlSum,
|
|
2827
|
+
sync: SyncMode.Sync,
|
|
2828
|
+
selectResult: SelectResult.One_Row_Many_Column_Assert
|
|
2829
|
+
});
|
|
2830
|
+
}
|
|
2831
|
+
if (sql) {
|
|
2832
|
+
result.records = this.select({
|
|
2833
|
+
...option,
|
|
2834
|
+
sql,
|
|
2835
|
+
sync: SyncMode.Sync,
|
|
2836
|
+
selectResult: SelectResult.Many_Row_Many_Column
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
return result;
|
|
2840
|
+
}
|
|
2841
|
+
else {
|
|
2842
|
+
return new Promise(async (resolve, reject) => {
|
|
2843
|
+
try {
|
|
2844
|
+
if (sqlCount) {
|
|
2845
|
+
result.total = await this.select({
|
|
2846
|
+
...option,
|
|
2847
|
+
sql: sqlCount,
|
|
2848
|
+
sync: SyncMode.Async,
|
|
2849
|
+
selectResult: SelectResult.One_Row_One_Column_Assert
|
|
2850
|
+
});
|
|
2851
|
+
result.size = (0, math_1.calc)(result.total)
|
|
2852
|
+
.add(option.pageSize - 1)
|
|
2853
|
+
.div(option.pageSize)
|
|
2854
|
+
.round(0, 2)
|
|
2855
|
+
.over();
|
|
2856
|
+
}
|
|
2857
|
+
if (sqlSum) {
|
|
2858
|
+
result.sum = await this.select({
|
|
2859
|
+
...option,
|
|
2860
|
+
sql: sqlSum,
|
|
2861
|
+
sync: SyncMode.Async,
|
|
2862
|
+
selectResult: SelectResult.One_Row_Many_Column_Assert
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
if (sql) {
|
|
2866
|
+
result.records = await this.select({
|
|
2867
|
+
...option,
|
|
2868
|
+
sql,
|
|
2869
|
+
sync: SyncMode.Async,
|
|
2870
|
+
selectResult: SelectResult.Many_Row_Many_Column
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
resolve(result);
|
|
2874
|
+
}
|
|
2875
|
+
catch (error) {
|
|
2876
|
+
reject(error);
|
|
2877
|
+
}
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2466
2880
|
}
|
|
2467
2881
|
/**
|
|
2468
2882
|
#创建表
|
|
@@ -2508,59 +2922,67 @@ class SqlService {
|
|
|
2508
2922
|
tableName = sqlstring_1.default.escapeId(tableName ?? this[_tableName]);
|
|
2509
2923
|
switch (this[_dbType]) {
|
|
2510
2924
|
case DBType.Mysql: {
|
|
2511
|
-
let sql = `CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
|
|
2512
|
-
${columns.map(K => this[_fields][K][DBType.Mysql]).join(',')}
|
|
2513
|
-
${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.
|
|
2514
|
-
${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.
|
|
2515
|
-
) ENGINE=MEMORY
|
|
2925
|
+
let sql = (0, sql_formatter_1.format)(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
|
|
2926
|
+
${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
|
|
2927
|
+
${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
|
|
2928
|
+
${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
|
|
2929
|
+
) ENGINE=MEMORY;`);
|
|
2516
2930
|
sqls.push({ sql });
|
|
2517
2931
|
if (data && data.length > 0) {
|
|
2518
2932
|
const params = [];
|
|
2519
2933
|
let first = true;
|
|
2520
|
-
sql = `INSERT INTO ${tableName} (${columns.map(c =>
|
|
2934
|
+
sql = (0, sql_formatter_1.format)(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
|
|
2521
2935
|
${(data).map(d => {
|
|
2522
2936
|
const r = `SELECT ${Object.entries(d).map(([K, V]) => {
|
|
2523
2937
|
params.push(V);
|
|
2524
|
-
return `? ${first ? this[_fields][K]?.
|
|
2938
|
+
return `? ${first ? this[_fields][K]?.C2() : ''}`;
|
|
2525
2939
|
}).join(',')}`;
|
|
2526
2940
|
first = false;
|
|
2527
2941
|
return r;
|
|
2528
|
-
}).join(' UNION ALL ')}
|
|
2942
|
+
}).join(' UNION ALL ')}`);
|
|
2529
2943
|
sqls.push({ sql, params });
|
|
2530
2944
|
}
|
|
2531
2945
|
break;
|
|
2532
2946
|
}
|
|
2533
2947
|
case DBType.Sqlite:
|
|
2534
2948
|
case DBType.SqliteRemote: {
|
|
2535
|
-
let sql = `CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
|
|
2536
|
-
${columns.map(K => this[_fields][K][DBType.Sqlite]).join(',')}
|
|
2537
|
-
${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.
|
|
2538
|
-
)
|
|
2949
|
+
let sql = (0, sql_formatter_1.format)(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
|
|
2950
|
+
${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
|
|
2951
|
+
${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
|
|
2952
|
+
);`);
|
|
2539
2953
|
sqls.push({ sql });
|
|
2540
2954
|
if (indexs) {
|
|
2541
2955
|
for (const index of indexs) {
|
|
2542
|
-
sql = `CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableName} (${this[_fields][index]?.
|
|
2956
|
+
sql = (0, sql_formatter_1.format)(`CREATE INDEX ${sqlstring_1.default.escapeId(`${index}_${Math.random()}`.replace(/\./, ''))} ON ${tableName} (${this[_fields][index]?.C2()});`);
|
|
2543
2957
|
sqls.push({ sql });
|
|
2544
2958
|
}
|
|
2545
2959
|
}
|
|
2546
2960
|
if (data && data.length > 0) {
|
|
2547
2961
|
const params = [];
|
|
2548
2962
|
let first = true;
|
|
2549
|
-
sql = `INSERT INTO ${tableName} (${columns.map(c =>
|
|
2963
|
+
sql = (0, sql_formatter_1.format)(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
|
|
2550
2964
|
${(data).map(d => {
|
|
2551
2965
|
const r = `SELECT ${Object.entries(d).map(([K, V]) => {
|
|
2552
2966
|
params.push(V);
|
|
2553
|
-
return `? ${first ? this[_fields][K]?.
|
|
2967
|
+
return `? ${first ? this[_fields][K]?.C2() : ''}`;
|
|
2554
2968
|
}).join(',')}`;
|
|
2555
2969
|
first = false;
|
|
2556
2970
|
return r;
|
|
2557
|
-
}).join(' UNION ALL ')}
|
|
2971
|
+
}).join(' UNION ALL ')}`);
|
|
2558
2972
|
sqls.push({ sql, params });
|
|
2559
2973
|
}
|
|
2974
|
+
break;
|
|
2560
2975
|
}
|
|
2561
2976
|
}
|
|
2562
2977
|
return sqls;
|
|
2563
2978
|
}
|
|
2979
|
+
_matchSqlid(sqlid) {
|
|
2980
|
+
sqlid ?? (sqlid = '');
|
|
2981
|
+
if (sqlid.includes('.'))
|
|
2982
|
+
return [sqlid];
|
|
2983
|
+
else
|
|
2984
|
+
return [`${this[_tableName]}.${sqlid}`, `${this[_className]}.${sqlid}`, `${this[_ClassName]}.${sqlid}`, `${this[_vueName]}.${sqlid}`];
|
|
2985
|
+
}
|
|
2564
2986
|
}
|
|
2565
2987
|
exports.SqlService = SqlService;
|
|
2566
2988
|
__decorate([
|
|
@@ -2605,6 +3027,12 @@ __decorate([
|
|
|
2605
3027
|
__metadata("design:paramtypes", [Object]),
|
|
2606
3028
|
__metadata("design:returntype", Object)
|
|
2607
3029
|
], SqlService.prototype, "transaction", null);
|
|
3030
|
+
__decorate([
|
|
3031
|
+
P(),
|
|
3032
|
+
__metadata("design:type", Function),
|
|
3033
|
+
__metadata("design:paramtypes", [Object]),
|
|
3034
|
+
__metadata("design:returntype", Object)
|
|
3035
|
+
], SqlService.prototype, "page", null);
|
|
2608
3036
|
/** 是否进行下一个动作 */
|
|
2609
3037
|
const IF_PROCEED = function () {
|
|
2610
3038
|
return function (_target, _propertyKey, descriptor) {
|
|
@@ -2638,8 +3066,8 @@ const IF_EXEC = function (def) {
|
|
|
2638
3066
|
};
|
|
2639
3067
|
};
|
|
2640
3068
|
};
|
|
2641
|
-
class
|
|
2642
|
-
constructor() {
|
|
3069
|
+
class StreamQuery {
|
|
3070
|
+
constructor(table, service, __fields, __columns) {
|
|
2643
3071
|
this._prefix = 0;
|
|
2644
3072
|
this._index = 0;
|
|
2645
3073
|
this._wheres = [];
|
|
@@ -2649,7 +3077,18 @@ class StreamCondition {
|
|
|
2649
3077
|
this._param = {};
|
|
2650
3078
|
this.if_proceed = true;
|
|
2651
3079
|
this.if_exec = true;
|
|
3080
|
+
this._distinct = false;
|
|
3081
|
+
this._columns = [];
|
|
3082
|
+
this._updateColumns = [];
|
|
3083
|
+
this._groups = [];
|
|
3084
|
+
this._orders = [];
|
|
3085
|
+
this._startRow = 0;
|
|
3086
|
+
this._pageSize = 0;
|
|
2652
3087
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3088
|
+
this._table = table;
|
|
3089
|
+
this._service = service;
|
|
3090
|
+
this[_fields] = __fields;
|
|
3091
|
+
this[_columns] = __columns;
|
|
2653
3092
|
}
|
|
2654
3093
|
/** 将当前stream重置 */
|
|
2655
3094
|
reset() {
|
|
@@ -2657,8 +3096,15 @@ class StreamCondition {
|
|
|
2657
3096
|
this._wheres.length = 0;
|
|
2658
3097
|
this._param = {};
|
|
2659
3098
|
this._paramKeys = {};
|
|
3099
|
+
this._pageSize = 0;
|
|
3100
|
+
this._startRow = 0;
|
|
3101
|
+
this._orders.length = 0;
|
|
3102
|
+
this._groups.length = 0;
|
|
3103
|
+
this._columns.length = 0;
|
|
3104
|
+
this._updateColumns.length = 0;
|
|
2660
3105
|
return this;
|
|
2661
3106
|
}
|
|
3107
|
+
// #region 条件
|
|
2662
3108
|
/** 为下次链条执行提供条件判断:非异步方法跳过,异步方法不执行并返回默认值 */
|
|
2663
3109
|
if(condition) {
|
|
2664
3110
|
this.if_proceed = condition;
|
|
@@ -2666,23 +3112,33 @@ class StreamCondition {
|
|
|
2666
3112
|
}
|
|
2667
3113
|
eq(key, value, { name } = {}) { return this._(key, value, '=', { name }); }
|
|
2668
3114
|
eqT(t, { name } = {}) {
|
|
2669
|
-
if (
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
const
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
3115
|
+
if (t) {
|
|
3116
|
+
t = this._service[_transformer](t, {
|
|
3117
|
+
skipNull: true,
|
|
3118
|
+
skipUndefined: true,
|
|
3119
|
+
skipEmptyString: true
|
|
3120
|
+
});
|
|
3121
|
+
const keys = Object.keys(t);
|
|
3122
|
+
if (keys.length > 0) {
|
|
3123
|
+
if (name && this._paramKeys[name]) {
|
|
3124
|
+
for (const [key, pname] of Object.entries(this._paramKeys[name])) {
|
|
3125
|
+
this._param[pname] = t[key];
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
else {
|
|
3129
|
+
const paramKeys = {};
|
|
3130
|
+
for (const [key, value] of Object.entries(t)) {
|
|
3131
|
+
const pkey = `p${this._prefix}${this._index++}`;
|
|
3132
|
+
this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} = :${pkey} `);
|
|
3133
|
+
this._param[pkey] = value;
|
|
3134
|
+
if (name) {
|
|
3135
|
+
paramKeys[key] = pkey;
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
if (name) {
|
|
3139
|
+
this._paramKeys[name] = paramKeys;
|
|
3140
|
+
}
|
|
2682
3141
|
}
|
|
2683
|
-
}
|
|
2684
|
-
if (name) {
|
|
2685
|
-
this._paramKeys[name] = paramKeys;
|
|
2686
3142
|
}
|
|
2687
3143
|
}
|
|
2688
3144
|
return this;
|
|
@@ -2712,14 +3168,14 @@ class StreamCondition {
|
|
|
2712
3168
|
notRightLike(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', not: 'NOT', force }); }
|
|
2713
3169
|
PreciseLike(key, value, { name, force } = {}) { return this._like(key, value, { name, force }); }
|
|
2714
3170
|
notPreciseLike(key, value, { name, force } = {}) { return this._like(key, value, { name, not: 'NOT', force }); }
|
|
2715
|
-
glob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', force, op: '
|
|
2716
|
-
notGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', not: 'NOT', force, op: '
|
|
2717
|
-
leftGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', force, op: '
|
|
2718
|
-
notLeftGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', not: 'NOT', force, op: '
|
|
2719
|
-
rightGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', force, op: '
|
|
2720
|
-
notRightGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', not: 'NOT', force, op: '
|
|
2721
|
-
PreciseGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, force, op: '
|
|
2722
|
-
notPreciseGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, not: 'NOT', force, op: '
|
|
3171
|
+
glob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', force, op: 'GLOB' }); }
|
|
3172
|
+
notGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', right: '%', not: 'NOT', force, op: 'GLOB' }); }
|
|
3173
|
+
leftGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', force, op: 'GLOB' }); }
|
|
3174
|
+
notLeftGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, left: '%', not: 'NOT', force, op: 'GLOB' }); }
|
|
3175
|
+
rightGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', force, op: 'GLOB' }); }
|
|
3176
|
+
notRightGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, right: '%', not: 'NOT', force, op: 'GLOB' }); }
|
|
3177
|
+
PreciseGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, force, op: 'GLOB' }); }
|
|
3178
|
+
notPreciseGlob(key, value, { name, force } = {}) { return this._like(key, value, { name, not: 'NOT', force, op: 'GLOB' }); }
|
|
2723
3179
|
in(key, value, { name, force } = {}) { return this._in(key, value, { name, force }); }
|
|
2724
3180
|
notIn(key, value, { name, force } = {}) { return this._in(key, value, { name, not: 'NOT', force }); }
|
|
2725
3181
|
isNULL(key) { return this._null(key); }
|
|
@@ -2744,21 +3200,154 @@ class StreamCondition {
|
|
|
2744
3200
|
notMatchQuery(value, keys, { name } = {}) { return this._match(value, keys, { name, not: 'NOT', append: 'WITH QUERY EXPANSION' }); }
|
|
2745
3201
|
includes(key, value, { name } = {}) { return this._includes(key, value, { name }); }
|
|
2746
3202
|
notIncludes(key, value, { name } = {}) { return this._includes(key, value, { name, not: 'NOT' }); }
|
|
2747
|
-
and(fn) {
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
3203
|
+
and(fn) {
|
|
3204
|
+
if (fn instanceof StreamQuery) {
|
|
3205
|
+
this._andQuerys.push(fn);
|
|
3206
|
+
}
|
|
3207
|
+
else {
|
|
3208
|
+
const stream = new StreamQuery(this._table, this._service, this[_fields], this[_columns]);
|
|
3209
|
+
const ret = fn(stream);
|
|
3210
|
+
if (ret !== false) {
|
|
3211
|
+
this._andQuerys.push(stream);
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
return this;
|
|
3215
|
+
}
|
|
3216
|
+
or(fn) {
|
|
3217
|
+
if (fn instanceof StreamQuery) {
|
|
3218
|
+
this._andQuerys.push(fn);
|
|
3219
|
+
}
|
|
3220
|
+
else {
|
|
3221
|
+
const stream = new StreamQuery(this._table, this._service, this[_fields], this[_columns]);
|
|
3222
|
+
const ret = fn(stream);
|
|
3223
|
+
if (ret !== false) {
|
|
3224
|
+
this._orQuerys.push(stream);
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
return this;
|
|
3228
|
+
}
|
|
3229
|
+
groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
|
|
3230
|
+
groupBy2(...keys) { this._groups.push(...keys); return this; }
|
|
3231
|
+
asc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
|
|
3232
|
+
asc2(...keys) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
|
|
3233
|
+
desc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`)); return this; }
|
|
3234
|
+
desc2(...keys) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
|
|
3235
|
+
limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
|
|
3236
|
+
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3237
|
+
table(_table) { this._table = _table; return this; }
|
|
3238
|
+
distinct(on = true) { this._distinct = on; return this; }
|
|
3239
|
+
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3240
|
+
count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
|
|
3241
|
+
sum(key, legName, distinct) { this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3242
|
+
avg(key, legName, distinct) { this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3243
|
+
max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3244
|
+
min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3245
|
+
groupConcat(key, param) {
|
|
3246
|
+
this._columns.push(`GROUP_CONCAT(
|
|
3247
|
+
${param && param.distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}
|
|
3248
|
+
${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `${this[_fields][String(i)]?.C2()} ASC`)} ` : ''}
|
|
3249
|
+
${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `${this[_fields][String(i)]?.C2()} DESC`)} ` : ''}
|
|
3250
|
+
SEPARATOR '${param && param.separator || ','}'
|
|
3251
|
+
) ${param && param.groupName || `${this[_fields][String(key)]?.C2()}`}`);
|
|
3252
|
+
return this;
|
|
3253
|
+
}
|
|
3254
|
+
select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
|
|
3255
|
+
select2(sql, param) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
|
|
3256
|
+
update(key, value) { this._updates ?? (this._updates = {}); this._updates[key] = value; return this; }
|
|
3257
|
+
update2(sql, param) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
|
|
3258
|
+
updateT(t) { this._updates ?? (this._updates = {}); Object.assign(this._updates, t); return this; }
|
|
3259
|
+
replace(key, valueToFind, valueToReplace) {
|
|
3260
|
+
const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
|
|
3261
|
+
this._updateColumns.push(` ${this[_fields][String(key)]?.C2()} = REPLACE(${this[_fields][String(key)]?.C2()}, :${pkey1}, :${pkey2}) `);
|
|
3262
|
+
this._param[pkey1] = valueToFind;
|
|
3263
|
+
this._param[pkey2] = valueToReplace;
|
|
3264
|
+
return this;
|
|
3265
|
+
}
|
|
3266
|
+
excuteSelect(option) {
|
|
3267
|
+
option ?? (option = {});
|
|
3268
|
+
option.sync ?? (option.sync = SyncMode.Async);
|
|
3269
|
+
option.selectResult ?? (option.selectResult = SelectResult.Many_Row_Many_Column);
|
|
3270
|
+
const { where, params } = this._where();
|
|
3271
|
+
let sql = `
|
|
3272
|
+
SELECT
|
|
3273
|
+
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3274
|
+
FROM ${this._table}
|
|
3275
|
+
${where ? ' WHERE ' : ''}
|
|
3276
|
+
${where}
|
|
3277
|
+
`;
|
|
3278
|
+
if (this._startRow && this._pageSize) {
|
|
3279
|
+
sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
|
|
3280
|
+
}
|
|
3281
|
+
else if (this._startRow) {
|
|
3282
|
+
sql += `LIMIT ${this._startRow}`;
|
|
3283
|
+
}
|
|
3284
|
+
if (option.sync === SyncMode.Async) {
|
|
3285
|
+
switch (option.selectResult) {
|
|
3286
|
+
case SelectResult.Many_Row_Many_Column: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.Many_Row_Many_Column, errorMsg: option.errorMsg, sql, params });
|
|
3287
|
+
case SelectResult.Many_Row_One_Column: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.Many_Row_One_Column, errorMsg: option.errorMsg, sql, params });
|
|
3288
|
+
case SelectResult.One_Row_Many_Column_Assert: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_Many_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3289
|
+
case SelectResult.One_Row_One_Column_Assert: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_One_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3290
|
+
case SelectResult.One_Row_Many_Column_NotSure: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_Many_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3291
|
+
case SelectResult.One_Row_One_Column_NotSure: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_One_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
else {
|
|
3295
|
+
switch (option.selectResult) {
|
|
3296
|
+
case SelectResult.Many_Row_Many_Column: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.Many_Row_Many_Column, errorMsg: option.errorMsg, sql, params });
|
|
3297
|
+
case SelectResult.Many_Row_One_Column: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.Many_Row_One_Column, errorMsg: option.errorMsg, sql, params });
|
|
3298
|
+
case SelectResult.One_Row_Many_Column_Assert: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_Many_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3299
|
+
case SelectResult.One_Row_One_Column_Assert: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_One_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3300
|
+
case SelectResult.One_Row_Many_Column_NotSure: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_Many_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3301
|
+
case SelectResult.One_Row_One_Column_NotSure: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_One_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
excuteUpdate(option) {
|
|
3306
|
+
option ?? (option = {});
|
|
3307
|
+
option.sync ?? (option.sync = SyncMode.Async);
|
|
3308
|
+
const { where, params } = this._where();
|
|
3309
|
+
const sets = new Array(...this._updateColumns);
|
|
3310
|
+
if (this._updates) {
|
|
3311
|
+
for (const [K, V] of Object.entries(this._updates)) {
|
|
3312
|
+
const pkey = `p${this._prefix}${this._index++}`;
|
|
3313
|
+
sets.push(` ${K} = :${pkey} `);
|
|
3314
|
+
params[pkey] = V;
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
if (sets.length > 0) {
|
|
3318
|
+
const sql = `UPDATE ${this._table} SET ${sets.join(',')} ${where}`;
|
|
3319
|
+
if (option.sync === SyncMode.Async) {
|
|
3320
|
+
return this._service.excute({ sync: SyncMode.Async, sql, params });
|
|
3321
|
+
}
|
|
3322
|
+
else {
|
|
3323
|
+
return this._service.excute({ sync: SyncMode.Sync, sql, params });
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
else {
|
|
3327
|
+
return 0;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
excuteDelete(option) {
|
|
3331
|
+
option ?? (option = {});
|
|
3332
|
+
option.sync ?? (option.sync = SyncMode.Async);
|
|
3333
|
+
const { where, params } = this._where();
|
|
3334
|
+
const sql = `DELETE FROM ${this._table} ${where}`;
|
|
3335
|
+
if (option.sync === SyncMode.Async) {
|
|
3336
|
+
return this._service.excute({ sync: SyncMode.Async, sql, params });
|
|
3337
|
+
}
|
|
3338
|
+
else {
|
|
3339
|
+
return this._service.excute({ sync: SyncMode.Sync, sql, params });
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
_where() {
|
|
2754
3343
|
const wheres = new Array();
|
|
2755
3344
|
const sql = this._wheres.join(' ');
|
|
2756
3345
|
if (sql) {
|
|
2757
|
-
wheres.push(`(${sql})`);
|
|
3346
|
+
wheres.push(`(${sql.replace(/^and|^or/i, '')})`);
|
|
2758
3347
|
}
|
|
2759
3348
|
if (this._orQuerys.length > 0) {
|
|
2760
3349
|
for (const query of this._orQuerys) {
|
|
2761
|
-
const { where, params } = query.
|
|
3350
|
+
const { where, params } = query._where();
|
|
2762
3351
|
if (where) {
|
|
2763
3352
|
wheres.push(` OR (${where}) `);
|
|
2764
3353
|
}
|
|
@@ -2767,7 +3356,7 @@ class StreamCondition {
|
|
|
2767
3356
|
}
|
|
2768
3357
|
if (this._andQuerys.length > 0) {
|
|
2769
3358
|
for (const query of this._andQuerys) {
|
|
2770
|
-
const { where, params } = query.
|
|
3359
|
+
const { where, params } = query._where();
|
|
2771
3360
|
if (where) {
|
|
2772
3361
|
wheres.push(` AND (${where}) `);
|
|
2773
3362
|
}
|
|
@@ -2782,7 +3371,7 @@ class StreamCondition {
|
|
|
2782
3371
|
}
|
|
2783
3372
|
else {
|
|
2784
3373
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2785
|
-
this._wheres.push(`AND ${String(key)} ${not} ${op} :${pkey} `);
|
|
3374
|
+
this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} ${op} :${pkey} `);
|
|
2786
3375
|
this._param[pkey] = value;
|
|
2787
3376
|
if (name) {
|
|
2788
3377
|
this._paramKeys[name] = pkey;
|
|
@@ -2791,11 +3380,11 @@ class StreamCondition {
|
|
|
2791
3380
|
return this;
|
|
2792
3381
|
}
|
|
2793
3382
|
_null(key, not = '') {
|
|
2794
|
-
this._wheres.push(`AND ${String(key)}
|
|
3383
|
+
this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} IS ${not} NULL`);
|
|
2795
3384
|
return this;
|
|
2796
3385
|
}
|
|
2797
3386
|
_key(key1, key2, op, not = '') {
|
|
2798
|
-
this._wheres.push(`AND ${String(key1)} ${not} ${op} ${String(key2)} `);
|
|
3387
|
+
this._wheres.push(`AND ${this[_fields][String(key1)]?.C2()} ${not} ${op} ${this[_fields][String(key2)]?.C2()} `);
|
|
2799
3388
|
return this;
|
|
2800
3389
|
}
|
|
2801
3390
|
_between(key, value1, value2, { not = '', name = '' } = {}) {
|
|
@@ -2805,7 +3394,7 @@ class StreamCondition {
|
|
|
2805
3394
|
}
|
|
2806
3395
|
else {
|
|
2807
3396
|
const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
|
|
2808
|
-
this._wheres.push(`AND ${String(key)} ${not} BETWEEN :${pkey1} AND :${pkey2}`);
|
|
3397
|
+
this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} BETWEEN :${pkey1} AND :${pkey2}`);
|
|
2809
3398
|
this._param[pkey1] = value1;
|
|
2810
3399
|
this._param[pkey2] = value2;
|
|
2811
3400
|
if (name) {
|
|
@@ -2821,7 +3410,7 @@ class StreamCondition {
|
|
|
2821
3410
|
}
|
|
2822
3411
|
else {
|
|
2823
3412
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2824
|
-
this._wheres.push(`AND ${String(key)} ${not} IN (:${pkey}) `);
|
|
3413
|
+
this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} IN (:${pkey}) `);
|
|
2825
3414
|
this._param[pkey] = value;
|
|
2826
3415
|
if (name) {
|
|
2827
3416
|
this._paramKeys[name] = pkey;
|
|
@@ -2839,7 +3428,7 @@ class StreamCondition {
|
|
|
2839
3428
|
}
|
|
2840
3429
|
else {
|
|
2841
3430
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2842
|
-
this._wheres.push(`AND (${String(key1)} << 8) + ${String(key2)} ${not} ${op} :${pkey} `);
|
|
3431
|
+
this._wheres.push(`AND (${this[_fields][String(key1)]?.C2()} << 8) + ${this[_fields][String(key2)]?.C2()} ${not} ${op} :${pkey} `);
|
|
2843
3432
|
this._param[pkey] = value;
|
|
2844
3433
|
if (name) {
|
|
2845
3434
|
this._paramKeys[name] = pkey;
|
|
@@ -2853,7 +3442,7 @@ class StreamCondition {
|
|
|
2853
3442
|
}
|
|
2854
3443
|
else {
|
|
2855
3444
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2856
|
-
this._wheres.push(`AND MATCH(${keys.join(',')}) AGAINST (:${pkey} ${append ?? ''})`);
|
|
3445
|
+
this._wheres.push(`AND MATCH(${keys.map(key => this[_fields][String(key)]?.C2()).join(',')}) AGAINST (:${pkey} ${append ?? ''})`);
|
|
2857
3446
|
this._param[pkey] = value;
|
|
2858
3447
|
if (name) {
|
|
2859
3448
|
this._paramKeys[name] = pkey;
|
|
@@ -2867,7 +3456,7 @@ class StreamCondition {
|
|
|
2867
3456
|
}
|
|
2868
3457
|
else {
|
|
2869
3458
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2870
|
-
this._wheres.push(`AND NOT POW(2, ${String(key)}) & :${pkey}`);
|
|
3459
|
+
this._wheres.push(`AND NOT POW(2, ${this[_fields][String(key)]?.C2()}) & :${pkey}`);
|
|
2871
3460
|
this._param[pkey] = value;
|
|
2872
3461
|
if (name) {
|
|
2873
3462
|
this._paramKeys[name] = pkey;
|
|
@@ -2882,7 +3471,7 @@ class StreamCondition {
|
|
|
2882
3471
|
}
|
|
2883
3472
|
else {
|
|
2884
3473
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2885
|
-
this._wheres.push(`AND ${String(key)} ${not} ${op} CONCAT('${left}', :${pkey}, '${right}') `);
|
|
3474
|
+
this._wheres.push(`AND ${this[_fields][String(key)]?.C2()} ${not} ${op} CONCAT('${left}', :${pkey}, '${right}') `);
|
|
2886
3475
|
this._param[pkey] = value;
|
|
2887
3476
|
if (name) {
|
|
2888
3477
|
this._paramKeys[name] = pkey;
|
|
@@ -2900,7 +3489,7 @@ class StreamCondition {
|
|
|
2900
3489
|
}
|
|
2901
3490
|
else {
|
|
2902
3491
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
2903
|
-
this._wheres.push(`AND LOCATE(${String(key)}, :${pkey}) ${not ? '=' : ''} 0`);
|
|
3492
|
+
this._wheres.push(`AND LOCATE(${this[_fields][String(key)]?.C2()}, :${pkey}) ${not ? '=' : ''} 0`);
|
|
2904
3493
|
this._param[pkey] = value;
|
|
2905
3494
|
if (name) {
|
|
2906
3495
|
this._paramKeys[name] = pkey;
|
|
@@ -2914,579 +3503,493 @@ __decorate([
|
|
|
2914
3503
|
__metadata("design:type", Function),
|
|
2915
3504
|
__metadata("design:paramtypes", [Boolean]),
|
|
2916
3505
|
__metadata("design:returntype", void 0)
|
|
2917
|
-
],
|
|
3506
|
+
], StreamQuery.prototype, "if", null);
|
|
2918
3507
|
__decorate([
|
|
2919
3508
|
IF_PROCEED(),
|
|
2920
3509
|
__metadata("design:type", Function),
|
|
2921
3510
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
2922
3511
|
__metadata("design:returntype", void 0)
|
|
2923
|
-
],
|
|
3512
|
+
], StreamQuery.prototype, "eq", null);
|
|
2924
3513
|
__decorate([
|
|
2925
3514
|
IF_PROCEED(),
|
|
2926
3515
|
__metadata("design:type", Function),
|
|
2927
3516
|
__metadata("design:paramtypes", [Object, Object]),
|
|
2928
3517
|
__metadata("design:returntype", void 0)
|
|
2929
|
-
],
|
|
3518
|
+
], StreamQuery.prototype, "eqT", null);
|
|
2930
3519
|
__decorate([
|
|
2931
3520
|
IF_PROCEED(),
|
|
2932
3521
|
__metadata("design:type", Function),
|
|
2933
3522
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
2934
3523
|
__metadata("design:returntype", void 0)
|
|
2935
|
-
],
|
|
3524
|
+
], StreamQuery.prototype, "notEq", null);
|
|
2936
3525
|
__decorate([
|
|
2937
3526
|
IF_PROCEED(),
|
|
2938
3527
|
__metadata("design:type", Function),
|
|
2939
3528
|
__metadata("design:paramtypes", [Object, Object]),
|
|
2940
3529
|
__metadata("design:returntype", void 0)
|
|
2941
|
-
],
|
|
3530
|
+
], StreamQuery.prototype, "eqWith", null);
|
|
2942
3531
|
__decorate([
|
|
2943
3532
|
IF_PROCEED(),
|
|
2944
3533
|
__metadata("design:type", Function),
|
|
2945
3534
|
__metadata("design:paramtypes", [Object, Object]),
|
|
2946
3535
|
__metadata("design:returntype", void 0)
|
|
2947
|
-
],
|
|
3536
|
+
], StreamQuery.prototype, "notEqWith", null);
|
|
2948
3537
|
__decorate([
|
|
2949
3538
|
IF_PROCEED(),
|
|
2950
3539
|
__metadata("design:type", Function),
|
|
2951
3540
|
__metadata("design:paramtypes", [Object, String, Object]),
|
|
2952
3541
|
__metadata("design:returntype", void 0)
|
|
2953
|
-
],
|
|
3542
|
+
], StreamQuery.prototype, "regexp", null);
|
|
2954
3543
|
__decorate([
|
|
2955
3544
|
IF_PROCEED(),
|
|
2956
3545
|
__metadata("design:type", Function),
|
|
2957
3546
|
__metadata("design:paramtypes", [Object, String, Object]),
|
|
2958
3547
|
__metadata("design:returntype", void 0)
|
|
2959
|
-
],
|
|
3548
|
+
], StreamQuery.prototype, "notRegexp", null);
|
|
2960
3549
|
__decorate([
|
|
2961
3550
|
IF_PROCEED(),
|
|
2962
3551
|
__metadata("design:type", Function),
|
|
2963
3552
|
__metadata("design:paramtypes", [Object, Object, Number, Object]),
|
|
2964
3553
|
__metadata("design:returntype", void 0)
|
|
2965
|
-
],
|
|
3554
|
+
], StreamQuery.prototype, "shiftEq", null);
|
|
2966
3555
|
__decorate([
|
|
2967
3556
|
IF_PROCEED(),
|
|
2968
3557
|
__metadata("design:type", Function),
|
|
2969
3558
|
__metadata("design:paramtypes", [Object, Object, Number, Object]),
|
|
2970
3559
|
__metadata("design:returntype", void 0)
|
|
2971
|
-
],
|
|
3560
|
+
], StreamQuery.prototype, "shiftNotEq", null);
|
|
2972
3561
|
__decorate([
|
|
2973
3562
|
IF_PROCEED(),
|
|
2974
3563
|
__metadata("design:type", Function),
|
|
2975
3564
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
2976
3565
|
__metadata("design:returntype", void 0)
|
|
2977
|
-
],
|
|
3566
|
+
], StreamQuery.prototype, "grate", null);
|
|
2978
3567
|
__decorate([
|
|
2979
3568
|
IF_PROCEED(),
|
|
2980
3569
|
__metadata("design:type", Function),
|
|
2981
3570
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
2982
3571
|
__metadata("design:returntype", void 0)
|
|
2983
|
-
],
|
|
3572
|
+
], StreamQuery.prototype, "grateEq", null);
|
|
2984
3573
|
__decorate([
|
|
2985
3574
|
IF_PROCEED(),
|
|
2986
3575
|
__metadata("design:type", Function),
|
|
2987
3576
|
__metadata("design:paramtypes", [Object, Object]),
|
|
2988
3577
|
__metadata("design:returntype", void 0)
|
|
2989
|
-
],
|
|
3578
|
+
], StreamQuery.prototype, "grateWith", null);
|
|
2990
3579
|
__decorate([
|
|
2991
3580
|
IF_PROCEED(),
|
|
2992
3581
|
__metadata("design:type", Function),
|
|
2993
3582
|
__metadata("design:paramtypes", [Object, Object]),
|
|
2994
3583
|
__metadata("design:returntype", void 0)
|
|
2995
|
-
],
|
|
3584
|
+
], StreamQuery.prototype, "grateEqWith", null);
|
|
2996
3585
|
__decorate([
|
|
2997
3586
|
IF_PROCEED(),
|
|
2998
3587
|
__metadata("design:type", Function),
|
|
2999
3588
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3000
3589
|
__metadata("design:returntype", void 0)
|
|
3001
|
-
],
|
|
3590
|
+
], StreamQuery.prototype, "less", null);
|
|
3002
3591
|
__decorate([
|
|
3003
3592
|
IF_PROCEED(),
|
|
3004
3593
|
__metadata("design:type", Function),
|
|
3005
3594
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3006
3595
|
__metadata("design:returntype", void 0)
|
|
3007
|
-
],
|
|
3596
|
+
], StreamQuery.prototype, "lessEq", null);
|
|
3008
3597
|
__decorate([
|
|
3009
3598
|
IF_PROCEED(),
|
|
3010
3599
|
__metadata("design:type", Function),
|
|
3011
3600
|
__metadata("design:paramtypes", [Object, Object]),
|
|
3012
3601
|
__metadata("design:returntype", void 0)
|
|
3013
|
-
],
|
|
3602
|
+
], StreamQuery.prototype, "lessWith", null);
|
|
3014
3603
|
__decorate([
|
|
3015
3604
|
IF_PROCEED(),
|
|
3016
3605
|
__metadata("design:type", Function),
|
|
3017
3606
|
__metadata("design:paramtypes", [Object, Object]),
|
|
3018
3607
|
__metadata("design:returntype", void 0)
|
|
3019
|
-
],
|
|
3608
|
+
], StreamQuery.prototype, "lessEqWith", null);
|
|
3020
3609
|
__decorate([
|
|
3021
3610
|
IF_PROCEED(),
|
|
3022
3611
|
__metadata("design:type", Function),
|
|
3023
3612
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3024
3613
|
__metadata("design:returntype", void 0)
|
|
3025
|
-
],
|
|
3614
|
+
], StreamQuery.prototype, "like", null);
|
|
3026
3615
|
__decorate([
|
|
3027
3616
|
IF_PROCEED(),
|
|
3028
3617
|
__metadata("design:type", Function),
|
|
3029
3618
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3030
3619
|
__metadata("design:returntype", void 0)
|
|
3031
|
-
],
|
|
3620
|
+
], StreamQuery.prototype, "notLike", null);
|
|
3032
3621
|
__decorate([
|
|
3033
3622
|
IF_PROCEED(),
|
|
3034
3623
|
__metadata("design:type", Function),
|
|
3035
3624
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3036
3625
|
__metadata("design:returntype", void 0)
|
|
3037
|
-
],
|
|
3626
|
+
], StreamQuery.prototype, "leftLike", null);
|
|
3038
3627
|
__decorate([
|
|
3039
3628
|
IF_PROCEED(),
|
|
3040
3629
|
__metadata("design:type", Function),
|
|
3041
3630
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3042
3631
|
__metadata("design:returntype", void 0)
|
|
3043
|
-
],
|
|
3632
|
+
], StreamQuery.prototype, "notLeftLike", null);
|
|
3044
3633
|
__decorate([
|
|
3045
3634
|
IF_PROCEED(),
|
|
3046
3635
|
__metadata("design:type", Function),
|
|
3047
3636
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3048
3637
|
__metadata("design:returntype", void 0)
|
|
3049
|
-
],
|
|
3638
|
+
], StreamQuery.prototype, "rightLike", null);
|
|
3050
3639
|
__decorate([
|
|
3051
3640
|
IF_PROCEED(),
|
|
3052
3641
|
__metadata("design:type", Function),
|
|
3053
3642
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3054
3643
|
__metadata("design:returntype", void 0)
|
|
3055
|
-
],
|
|
3644
|
+
], StreamQuery.prototype, "notRightLike", null);
|
|
3056
3645
|
__decorate([
|
|
3057
3646
|
IF_PROCEED(),
|
|
3058
3647
|
__metadata("design:type", Function),
|
|
3059
3648
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3060
3649
|
__metadata("design:returntype", void 0)
|
|
3061
|
-
],
|
|
3650
|
+
], StreamQuery.prototype, "PreciseLike", null);
|
|
3062
3651
|
__decorate([
|
|
3063
3652
|
IF_PROCEED(),
|
|
3064
3653
|
__metadata("design:type", Function),
|
|
3065
3654
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3066
3655
|
__metadata("design:returntype", void 0)
|
|
3067
|
-
],
|
|
3656
|
+
], StreamQuery.prototype, "notPreciseLike", null);
|
|
3068
3657
|
__decorate([
|
|
3069
3658
|
IF_PROCEED(),
|
|
3070
3659
|
__metadata("design:type", Function),
|
|
3071
3660
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3072
3661
|
__metadata("design:returntype", void 0)
|
|
3073
|
-
],
|
|
3662
|
+
], StreamQuery.prototype, "glob", null);
|
|
3074
3663
|
__decorate([
|
|
3075
3664
|
IF_PROCEED(),
|
|
3076
3665
|
__metadata("design:type", Function),
|
|
3077
3666
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3078
3667
|
__metadata("design:returntype", void 0)
|
|
3079
|
-
],
|
|
3668
|
+
], StreamQuery.prototype, "notGlob", null);
|
|
3080
3669
|
__decorate([
|
|
3081
3670
|
IF_PROCEED(),
|
|
3082
3671
|
__metadata("design:type", Function),
|
|
3083
3672
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3084
3673
|
__metadata("design:returntype", void 0)
|
|
3085
|
-
],
|
|
3674
|
+
], StreamQuery.prototype, "leftGlob", null);
|
|
3086
3675
|
__decorate([
|
|
3087
3676
|
IF_PROCEED(),
|
|
3088
3677
|
__metadata("design:type", Function),
|
|
3089
3678
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3090
3679
|
__metadata("design:returntype", void 0)
|
|
3091
|
-
],
|
|
3680
|
+
], StreamQuery.prototype, "notLeftGlob", null);
|
|
3092
3681
|
__decorate([
|
|
3093
3682
|
IF_PROCEED(),
|
|
3094
3683
|
__metadata("design:type", Function),
|
|
3095
3684
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3096
3685
|
__metadata("design:returntype", void 0)
|
|
3097
|
-
],
|
|
3686
|
+
], StreamQuery.prototype, "rightGlob", null);
|
|
3098
3687
|
__decorate([
|
|
3099
3688
|
IF_PROCEED(),
|
|
3100
3689
|
__metadata("design:type", Function),
|
|
3101
3690
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3102
3691
|
__metadata("design:returntype", void 0)
|
|
3103
|
-
],
|
|
3692
|
+
], StreamQuery.prototype, "notRightGlob", null);
|
|
3104
3693
|
__decorate([
|
|
3105
3694
|
IF_PROCEED(),
|
|
3106
3695
|
__metadata("design:type", Function),
|
|
3107
3696
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3108
3697
|
__metadata("design:returntype", void 0)
|
|
3109
|
-
],
|
|
3698
|
+
], StreamQuery.prototype, "PreciseGlob", null);
|
|
3110
3699
|
__decorate([
|
|
3111
3700
|
IF_PROCEED(),
|
|
3112
3701
|
__metadata("design:type", Function),
|
|
3113
3702
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3114
3703
|
__metadata("design:returntype", void 0)
|
|
3115
|
-
],
|
|
3704
|
+
], StreamQuery.prototype, "notPreciseGlob", null);
|
|
3116
3705
|
__decorate([
|
|
3117
3706
|
IF_PROCEED(),
|
|
3118
3707
|
__metadata("design:type", Function),
|
|
3119
3708
|
__metadata("design:paramtypes", [Object, Array, Object]),
|
|
3120
3709
|
__metadata("design:returntype", void 0)
|
|
3121
|
-
],
|
|
3710
|
+
], StreamQuery.prototype, "in", null);
|
|
3122
3711
|
__decorate([
|
|
3123
3712
|
IF_PROCEED(),
|
|
3124
3713
|
__metadata("design:type", Function),
|
|
3125
3714
|
__metadata("design:paramtypes", [Object, Array, Object]),
|
|
3126
3715
|
__metadata("design:returntype", void 0)
|
|
3127
|
-
],
|
|
3716
|
+
], StreamQuery.prototype, "notIn", null);
|
|
3128
3717
|
__decorate([
|
|
3129
3718
|
IF_PROCEED(),
|
|
3130
3719
|
__metadata("design:type", Function),
|
|
3131
3720
|
__metadata("design:paramtypes", [Object]),
|
|
3132
3721
|
__metadata("design:returntype", void 0)
|
|
3133
|
-
],
|
|
3722
|
+
], StreamQuery.prototype, "isNULL", null);
|
|
3134
3723
|
__decorate([
|
|
3135
3724
|
IF_PROCEED(),
|
|
3136
3725
|
__metadata("design:type", Function),
|
|
3137
3726
|
__metadata("design:paramtypes", [Object]),
|
|
3138
3727
|
__metadata("design:returntype", void 0)
|
|
3139
|
-
],
|
|
3728
|
+
], StreamQuery.prototype, "isNotNULL", null);
|
|
3140
3729
|
__decorate([
|
|
3141
3730
|
IF_PROCEED(),
|
|
3142
3731
|
__metadata("design:type", Function),
|
|
3143
3732
|
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
3144
3733
|
__metadata("design:returntype", void 0)
|
|
3145
|
-
],
|
|
3734
|
+
], StreamQuery.prototype, "between", null);
|
|
3146
3735
|
__decorate([
|
|
3147
3736
|
IF_PROCEED(),
|
|
3148
3737
|
__metadata("design:type", Function),
|
|
3149
3738
|
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
3150
3739
|
__metadata("design:returntype", void 0)
|
|
3151
|
-
],
|
|
3740
|
+
], StreamQuery.prototype, "notBetween", null);
|
|
3152
3741
|
__decorate([
|
|
3153
3742
|
IF_PROCEED(),
|
|
3154
3743
|
__metadata("design:type", Function),
|
|
3155
3744
|
__metadata("design:paramtypes", [Object, Number, Object]),
|
|
3156
3745
|
__metadata("design:returntype", void 0)
|
|
3157
|
-
],
|
|
3746
|
+
], StreamQuery.prototype, "pow", null);
|
|
3158
3747
|
__decorate([
|
|
3159
3748
|
IF_PROCEED(),
|
|
3160
3749
|
__metadata("design:type", Function),
|
|
3161
3750
|
__metadata("design:paramtypes", [Object, Number, Object]),
|
|
3162
3751
|
__metadata("design:returntype", void 0)
|
|
3163
|
-
],
|
|
3752
|
+
], StreamQuery.prototype, "notPow", null);
|
|
3164
3753
|
__decorate([
|
|
3165
3754
|
IF_PROCEED(),
|
|
3166
3755
|
__metadata("design:type", Function),
|
|
3167
3756
|
__metadata("design:paramtypes", [Object, Array, Object]),
|
|
3168
3757
|
__metadata("design:returntype", void 0)
|
|
3169
|
-
],
|
|
3758
|
+
], StreamQuery.prototype, "powWith", null);
|
|
3170
3759
|
__decorate([
|
|
3171
3760
|
IF_PROCEED(),
|
|
3172
3761
|
__metadata("design:type", Function),
|
|
3173
3762
|
__metadata("design:paramtypes", [Object, Array, Object]),
|
|
3174
3763
|
__metadata("design:returntype", void 0)
|
|
3175
|
-
],
|
|
3764
|
+
], StreamQuery.prototype, "notPowWith", null);
|
|
3176
3765
|
__decorate([
|
|
3177
3766
|
IF_PROCEED(),
|
|
3178
3767
|
__metadata("design:type", Function),
|
|
3179
3768
|
__metadata("design:paramtypes", [String, Array, Object]),
|
|
3180
3769
|
__metadata("design:returntype", void 0)
|
|
3181
|
-
],
|
|
3770
|
+
], StreamQuery.prototype, "match", null);
|
|
3182
3771
|
__decorate([
|
|
3183
3772
|
IF_PROCEED(),
|
|
3184
3773
|
__metadata("design:type", Function),
|
|
3185
3774
|
__metadata("design:paramtypes", [String, Array, Object]),
|
|
3186
3775
|
__metadata("design:returntype", void 0)
|
|
3187
|
-
],
|
|
3776
|
+
], StreamQuery.prototype, "notMatch", null);
|
|
3188
3777
|
__decorate([
|
|
3189
3778
|
IF_PROCEED(),
|
|
3190
3779
|
__metadata("design:type", Function),
|
|
3191
3780
|
__metadata("design:paramtypes", [String, Array, Object]),
|
|
3192
3781
|
__metadata("design:returntype", void 0)
|
|
3193
|
-
],
|
|
3782
|
+
], StreamQuery.prototype, "matchBoolean", null);
|
|
3194
3783
|
__decorate([
|
|
3195
3784
|
IF_PROCEED(),
|
|
3196
3785
|
__metadata("design:type", Function),
|
|
3197
3786
|
__metadata("design:paramtypes", [String, Array, Object]),
|
|
3198
3787
|
__metadata("design:returntype", void 0)
|
|
3199
|
-
],
|
|
3788
|
+
], StreamQuery.prototype, "notMatchBoolean", null);
|
|
3200
3789
|
__decorate([
|
|
3201
3790
|
IF_PROCEED(),
|
|
3202
3791
|
__metadata("design:type", Function),
|
|
3203
3792
|
__metadata("design:paramtypes", [String, Array, Object]),
|
|
3204
3793
|
__metadata("design:returntype", void 0)
|
|
3205
|
-
],
|
|
3794
|
+
], StreamQuery.prototype, "matchQuery", null);
|
|
3206
3795
|
__decorate([
|
|
3207
3796
|
IF_PROCEED(),
|
|
3208
3797
|
__metadata("design:type", Function),
|
|
3209
3798
|
__metadata("design:paramtypes", [String, Array, Object]),
|
|
3210
3799
|
__metadata("design:returntype", void 0)
|
|
3211
|
-
],
|
|
3800
|
+
], StreamQuery.prototype, "notMatchQuery", null);
|
|
3212
3801
|
__decorate([
|
|
3213
3802
|
IF_PROCEED(),
|
|
3214
3803
|
__metadata("design:type", Function),
|
|
3215
3804
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3216
3805
|
__metadata("design:returntype", void 0)
|
|
3217
|
-
],
|
|
3806
|
+
], StreamQuery.prototype, "includes", null);
|
|
3218
3807
|
__decorate([
|
|
3219
3808
|
IF_PROCEED(),
|
|
3220
3809
|
__metadata("design:type", Function),
|
|
3221
3810
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3222
3811
|
__metadata("design:returntype", void 0)
|
|
3223
|
-
],
|
|
3812
|
+
], StreamQuery.prototype, "notIncludes", null);
|
|
3224
3813
|
__decorate([
|
|
3225
3814
|
IF_PROCEED(),
|
|
3226
3815
|
__metadata("design:type", Function),
|
|
3227
|
-
__metadata("design:paramtypes", [
|
|
3816
|
+
__metadata("design:paramtypes", [Object]),
|
|
3228
3817
|
__metadata("design:returntype", void 0)
|
|
3229
|
-
],
|
|
3818
|
+
], StreamQuery.prototype, "and", null);
|
|
3230
3819
|
__decorate([
|
|
3231
3820
|
IF_PROCEED(),
|
|
3232
3821
|
__metadata("design:type", Function),
|
|
3233
|
-
__metadata("design:paramtypes", [
|
|
3822
|
+
__metadata("design:paramtypes", [Object]),
|
|
3234
3823
|
__metadata("design:returntype", void 0)
|
|
3235
|
-
],
|
|
3236
|
-
class StreamBuild extends StreamCondition {
|
|
3237
|
-
constructor(table) {
|
|
3238
|
-
super();
|
|
3239
|
-
this._distinct = false;
|
|
3240
|
-
this._columns = [];
|
|
3241
|
-
this._updateColumns = [];
|
|
3242
|
-
this._groups = [];
|
|
3243
|
-
this._orders = [];
|
|
3244
|
-
this._startRow = 0;
|
|
3245
|
-
this._pageSize = 0;
|
|
3246
|
-
this._table = table;
|
|
3247
|
-
}
|
|
3248
|
-
/** 将当前stream重置 */
|
|
3249
|
-
reset() {
|
|
3250
|
-
super.reset();
|
|
3251
|
-
this._pageSize = 0;
|
|
3252
|
-
this._startRow = 0;
|
|
3253
|
-
this._orders.length = 0;
|
|
3254
|
-
this._groups.length = 0;
|
|
3255
|
-
this._columns.length = 0;
|
|
3256
|
-
this._updateColumns.length = 0;
|
|
3257
|
-
return this;
|
|
3258
|
-
}
|
|
3259
|
-
groupBy(key) { this._groups.push(key); return this; }
|
|
3260
|
-
asc(...keys) { this._orders.push(...keys.map(key => `${String(key)} ASC`)); return this; }
|
|
3261
|
-
desc(...keys) { this._orders.push(...keys.map(key => `${String(key)} DESC`)); return this; }
|
|
3262
|
-
limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
|
|
3263
|
-
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3264
|
-
table(_table) { this._table = _table; return this; }
|
|
3265
|
-
distinct(on = true) { this._distinct = on; return this; }
|
|
3266
|
-
count(key, countName, distinct) { this._columns.push(`COUNT(${distinct ? 'DISTINCT' : ''} ${String(key)}) ${countName || `${String(key)}`}`); return this; }
|
|
3267
|
-
sum(key, legName, distinct) { this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} ${String(key)}) ${legName || `${String(key)}`}`); return this; }
|
|
3268
|
-
avg(key, legName, distinct) { this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} ${String(key)}) ${legName || `${String(key)}`}`); return this; }
|
|
3269
|
-
max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} ${String(key)}) ${legName || `${String(key)}`}`); return this; }
|
|
3270
|
-
min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} ${String(key)}) ${legName || `${String(key)}`}`); return this; }
|
|
3271
|
-
groupConcat(key, param) {
|
|
3272
|
-
this._columns.push(`GROUP_CONCAT(
|
|
3273
|
-
${param && param.distinct ? 'DISTINCT' : ''} ${String(key)}
|
|
3274
|
-
${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `${String(i)} ASC`)} ` : ''}
|
|
3275
|
-
${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `${String(i)} DESC`)} ` : ''}
|
|
3276
|
-
SEPARATOR '${param && param.separator || ','}'
|
|
3277
|
-
) ${param && param.groupName || `${String(key)}`}`);
|
|
3278
|
-
return this;
|
|
3279
|
-
}
|
|
3280
|
-
selectColumn(...key) { this._columns.push(...(key.map(k => k))); return this; }
|
|
3281
|
-
updateColumn(key, value) { this._updates ?? (this._updates = {}); this._updates[key] = value; return this; }
|
|
3282
|
-
updateT(t) { this._updates ?? (this._updates = {}); Object.assign(this._updates, t); return this; }
|
|
3283
|
-
replace(key, valueToFind, valueToReplace) {
|
|
3284
|
-
const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
|
|
3285
|
-
this._updateColumns.push(` ${String(key)} = REPLACE(${String(key)}, :${pkey1}, :${pkey2}) `);
|
|
3286
|
-
this._param[pkey1] = valueToFind;
|
|
3287
|
-
this._param[pkey2] = valueToReplace;
|
|
3288
|
-
return this;
|
|
3289
|
-
}
|
|
3290
|
-
}
|
|
3824
|
+
], StreamQuery.prototype, "or", null);
|
|
3291
3825
|
__decorate([
|
|
3292
3826
|
IF_PROCEED(),
|
|
3293
3827
|
__metadata("design:type", Function),
|
|
3294
3828
|
__metadata("design:paramtypes", [Object]),
|
|
3295
3829
|
__metadata("design:returntype", void 0)
|
|
3296
|
-
],
|
|
3830
|
+
], StreamQuery.prototype, "groupBy", null);
|
|
3831
|
+
__decorate([
|
|
3832
|
+
IF_PROCEED(),
|
|
3833
|
+
__metadata("design:type", Function),
|
|
3834
|
+
__metadata("design:paramtypes", [String]),
|
|
3835
|
+
__metadata("design:returntype", void 0)
|
|
3836
|
+
], StreamQuery.prototype, "groupBy2", null);
|
|
3297
3837
|
__decorate([
|
|
3298
3838
|
IF_PROCEED(),
|
|
3299
3839
|
__metadata("design:type", Function),
|
|
3300
3840
|
__metadata("design:paramtypes", [Object]),
|
|
3301
3841
|
__metadata("design:returntype", void 0)
|
|
3302
|
-
],
|
|
3842
|
+
], StreamQuery.prototype, "asc", null);
|
|
3843
|
+
__decorate([
|
|
3844
|
+
IF_PROCEED(),
|
|
3845
|
+
__metadata("design:type", Function),
|
|
3846
|
+
__metadata("design:paramtypes", [String]),
|
|
3847
|
+
__metadata("design:returntype", void 0)
|
|
3848
|
+
], StreamQuery.prototype, "asc2", null);
|
|
3303
3849
|
__decorate([
|
|
3304
3850
|
IF_PROCEED(),
|
|
3305
3851
|
__metadata("design:type", Function),
|
|
3306
3852
|
__metadata("design:paramtypes", [Object]),
|
|
3307
3853
|
__metadata("design:returntype", void 0)
|
|
3308
|
-
],
|
|
3854
|
+
], StreamQuery.prototype, "desc", null);
|
|
3855
|
+
__decorate([
|
|
3856
|
+
IF_PROCEED(),
|
|
3857
|
+
__metadata("design:type", Function),
|
|
3858
|
+
__metadata("design:paramtypes", [String]),
|
|
3859
|
+
__metadata("design:returntype", void 0)
|
|
3860
|
+
], StreamQuery.prototype, "desc2", null);
|
|
3309
3861
|
__decorate([
|
|
3310
3862
|
IF_PROCEED(),
|
|
3311
3863
|
__metadata("design:type", Function),
|
|
3312
3864
|
__metadata("design:paramtypes", [Number, Number]),
|
|
3313
3865
|
__metadata("design:returntype", void 0)
|
|
3314
|
-
],
|
|
3866
|
+
], StreamQuery.prototype, "limit", null);
|
|
3315
3867
|
__decorate([
|
|
3316
3868
|
IF_PROCEED(),
|
|
3317
3869
|
__metadata("design:type", Function),
|
|
3318
3870
|
__metadata("design:paramtypes", [Number, Number]),
|
|
3319
3871
|
__metadata("design:returntype", void 0)
|
|
3320
|
-
],
|
|
3872
|
+
], StreamQuery.prototype, "page", null);
|
|
3321
3873
|
__decorate([
|
|
3322
3874
|
IF_PROCEED(),
|
|
3323
3875
|
__metadata("design:type", Function),
|
|
3324
3876
|
__metadata("design:paramtypes", [String]),
|
|
3325
3877
|
__metadata("design:returntype", void 0)
|
|
3326
|
-
],
|
|
3878
|
+
], StreamQuery.prototype, "table", null);
|
|
3327
3879
|
__decorate([
|
|
3328
3880
|
IF_PROCEED(),
|
|
3329
3881
|
__metadata("design:type", Function),
|
|
3330
3882
|
__metadata("design:paramtypes", [Object]),
|
|
3331
3883
|
__metadata("design:returntype", void 0)
|
|
3332
|
-
],
|
|
3884
|
+
], StreamQuery.prototype, "distinct", null);
|
|
3333
3885
|
__decorate([
|
|
3334
3886
|
IF_PROCEED(),
|
|
3335
3887
|
__metadata("design:type", Function),
|
|
3336
|
-
__metadata("design:paramtypes", [Object, String
|
|
3888
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
3337
3889
|
__metadata("design:returntype", void 0)
|
|
3338
|
-
],
|
|
3890
|
+
], StreamQuery.prototype, "countDistinct", null);
|
|
3891
|
+
__decorate([
|
|
3892
|
+
IF_PROCEED(),
|
|
3893
|
+
__metadata("design:type", Function),
|
|
3894
|
+
__metadata("design:paramtypes", [String]),
|
|
3895
|
+
__metadata("design:returntype", void 0)
|
|
3896
|
+
], StreamQuery.prototype, "count", null);
|
|
3339
3897
|
__decorate([
|
|
3340
3898
|
IF_PROCEED(),
|
|
3341
3899
|
__metadata("design:type", Function),
|
|
3342
3900
|
__metadata("design:paramtypes", [Object, String, Boolean]),
|
|
3343
3901
|
__metadata("design:returntype", void 0)
|
|
3344
|
-
],
|
|
3902
|
+
], StreamQuery.prototype, "sum", null);
|
|
3345
3903
|
__decorate([
|
|
3346
3904
|
IF_PROCEED(),
|
|
3347
3905
|
__metadata("design:type", Function),
|
|
3348
3906
|
__metadata("design:paramtypes", [Object, String, Boolean]),
|
|
3349
3907
|
__metadata("design:returntype", void 0)
|
|
3350
|
-
],
|
|
3908
|
+
], StreamQuery.prototype, "avg", null);
|
|
3351
3909
|
__decorate([
|
|
3352
3910
|
IF_PROCEED(),
|
|
3353
3911
|
__metadata("design:type", Function),
|
|
3354
3912
|
__metadata("design:paramtypes", [Object, String, Boolean]),
|
|
3355
3913
|
__metadata("design:returntype", void 0)
|
|
3356
|
-
],
|
|
3914
|
+
], StreamQuery.prototype, "max", null);
|
|
3357
3915
|
__decorate([
|
|
3358
3916
|
IF_PROCEED(),
|
|
3359
3917
|
__metadata("design:type", Function),
|
|
3360
3918
|
__metadata("design:paramtypes", [Object, String, Boolean]),
|
|
3361
3919
|
__metadata("design:returntype", void 0)
|
|
3362
|
-
],
|
|
3920
|
+
], StreamQuery.prototype, "min", null);
|
|
3363
3921
|
__decorate([
|
|
3364
3922
|
IF_PROCEED(),
|
|
3365
3923
|
__metadata("design:type", Function),
|
|
3366
3924
|
__metadata("design:paramtypes", [Object, Object]),
|
|
3367
3925
|
__metadata("design:returntype", Object)
|
|
3368
|
-
],
|
|
3926
|
+
], StreamQuery.prototype, "groupConcat", null);
|
|
3369
3927
|
__decorate([
|
|
3370
3928
|
IF_PROCEED(),
|
|
3371
3929
|
__metadata("design:type", Function),
|
|
3372
3930
|
__metadata("design:paramtypes", [Object]),
|
|
3373
3931
|
__metadata("design:returntype", void 0)
|
|
3374
|
-
],
|
|
3932
|
+
], StreamQuery.prototype, "select", null);
|
|
3933
|
+
__decorate([
|
|
3934
|
+
IF_PROCEED(),
|
|
3935
|
+
__metadata("design:type", Function),
|
|
3936
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
3937
|
+
__metadata("design:returntype", void 0)
|
|
3938
|
+
], StreamQuery.prototype, "select2", null);
|
|
3375
3939
|
__decorate([
|
|
3376
3940
|
IF_PROCEED(),
|
|
3377
3941
|
__metadata("design:type", Function),
|
|
3378
3942
|
__metadata("design:paramtypes", [Object, Object]),
|
|
3379
3943
|
__metadata("design:returntype", void 0)
|
|
3380
|
-
],
|
|
3944
|
+
], StreamQuery.prototype, "update", null);
|
|
3945
|
+
__decorate([
|
|
3946
|
+
IF_PROCEED(),
|
|
3947
|
+
__metadata("design:type", Function),
|
|
3948
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
3949
|
+
__metadata("design:returntype", void 0)
|
|
3950
|
+
], StreamQuery.prototype, "update2", null);
|
|
3381
3951
|
__decorate([
|
|
3382
3952
|
IF_PROCEED(),
|
|
3383
3953
|
__metadata("design:type", Function),
|
|
3384
3954
|
__metadata("design:paramtypes", [Object]),
|
|
3385
3955
|
__metadata("design:returntype", void 0)
|
|
3386
|
-
],
|
|
3956
|
+
], StreamQuery.prototype, "updateT", null);
|
|
3387
3957
|
__decorate([
|
|
3388
3958
|
IF_PROCEED(),
|
|
3389
3959
|
__metadata("design:type", Function),
|
|
3390
3960
|
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
3391
3961
|
__metadata("design:returntype", void 0)
|
|
3392
|
-
],
|
|
3393
|
-
class StreamQuery extends StreamBuild {
|
|
3394
|
-
constructor(table, service) {
|
|
3395
|
-
super(table);
|
|
3396
|
-
this._service = service;
|
|
3397
|
-
}
|
|
3398
|
-
select(option) {
|
|
3399
|
-
option.sync ?? (option.sync = SyncMode.Async);
|
|
3400
|
-
const { where, params } = this.where();
|
|
3401
|
-
const sql = `
|
|
3402
|
-
SELECT
|
|
3403
|
-
${this._columns && this._columns.length > 0 ? this._columns.join(',') : '*'}
|
|
3404
|
-
FROM ${this._table}
|
|
3405
|
-
${where ? ' WHERE ' : ''}
|
|
3406
|
-
${where}`;
|
|
3407
|
-
if (option.sync === SyncMode.Async) {
|
|
3408
|
-
switch (option.selectResult) {
|
|
3409
|
-
case SelectResult.Many_Row_Many_Column: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.Many_Row_Many_Column, errorMsg: option.errorMsg, sql, params });
|
|
3410
|
-
case SelectResult.Many_Row_One_Column: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.Many_Row_One_Column, errorMsg: option.errorMsg, sql, params });
|
|
3411
|
-
case SelectResult.One_Row_Many_Column_Assert: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_Many_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3412
|
-
case SelectResult.One_Row_One_Column_Assert: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_One_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3413
|
-
case SelectResult.One_Row_Many_Column_NotSure: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_Many_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3414
|
-
case SelectResult.One_Row_One_Column_NotSure: return this._service.select({ sync: SyncMode.Async, selectResult: SelectResult.One_Row_One_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3415
|
-
}
|
|
3416
|
-
}
|
|
3417
|
-
else {
|
|
3418
|
-
switch (option.selectResult) {
|
|
3419
|
-
case SelectResult.Many_Row_Many_Column: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.Many_Row_Many_Column, errorMsg: option.errorMsg, sql, params });
|
|
3420
|
-
case SelectResult.Many_Row_One_Column: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.Many_Row_One_Column, errorMsg: option.errorMsg, sql, params });
|
|
3421
|
-
case SelectResult.One_Row_Many_Column_Assert: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_Many_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3422
|
-
case SelectResult.One_Row_One_Column_Assert: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_One_Column_Assert, errorMsg: option.errorMsg, sql, params });
|
|
3423
|
-
case SelectResult.One_Row_Many_Column_NotSure: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_Many_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3424
|
-
case SelectResult.One_Row_One_Column_NotSure: return this._service.select({ sync: SyncMode.Sync, selectResult: SelectResult.One_Row_One_Column_NotSure, errorMsg: option.errorMsg, sql, params });
|
|
3425
|
-
}
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
update(option) {
|
|
3429
|
-
option.sync ?? (option.sync = SyncMode.Async);
|
|
3430
|
-
const { where, params } = this.where();
|
|
3431
|
-
const sets = new Array(...this._updateColumns);
|
|
3432
|
-
if (this._updates) {
|
|
3433
|
-
for (const [K, V] of Object.entries(this._updates)) {
|
|
3434
|
-
const pkey = `p${this._prefix}${this._index++}`;
|
|
3435
|
-
sets.push(` ${K} = :${pkey} `);
|
|
3436
|
-
params[pkey] = V;
|
|
3437
|
-
}
|
|
3438
|
-
}
|
|
3439
|
-
if (sets.length > 0) {
|
|
3440
|
-
const sql = `UPDATE ${this._table} SET ${sets.join(',')} ${where}`;
|
|
3441
|
-
if (option.sync === SyncMode.Async) {
|
|
3442
|
-
return this._service.excute({ sync: SyncMode.Async, sql, params });
|
|
3443
|
-
}
|
|
3444
|
-
else {
|
|
3445
|
-
return this._service.excute({ sync: SyncMode.Sync, sql, params });
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
else {
|
|
3449
|
-
return 0;
|
|
3450
|
-
}
|
|
3451
|
-
}
|
|
3452
|
-
delete(option) {
|
|
3453
|
-
option.sync ?? (option.sync = SyncMode.Async);
|
|
3454
|
-
const { where, params } = this.where();
|
|
3455
|
-
const sql = `DELETE FROM ${this._table} ${where}`;
|
|
3456
|
-
if (option.sync === SyncMode.Async) {
|
|
3457
|
-
return this._service.excute({ sync: SyncMode.Async, sql, params });
|
|
3458
|
-
}
|
|
3459
|
-
else {
|
|
3460
|
-
return this._service.excute({ sync: SyncMode.Sync, sql, params });
|
|
3461
|
-
}
|
|
3462
|
-
}
|
|
3463
|
-
}
|
|
3962
|
+
], StreamQuery.prototype, "replace", null);
|
|
3464
3963
|
__decorate([
|
|
3465
3964
|
IF_EXEC(null),
|
|
3466
3965
|
__metadata("design:type", Function),
|
|
3467
3966
|
__metadata("design:paramtypes", [Object]),
|
|
3468
3967
|
__metadata("design:returntype", Object)
|
|
3469
|
-
], StreamQuery.prototype, "
|
|
3968
|
+
], StreamQuery.prototype, "excuteSelect", null);
|
|
3470
3969
|
__decorate([
|
|
3471
3970
|
IF_EXEC(0),
|
|
3472
3971
|
__metadata("design:type", Function),
|
|
3473
3972
|
__metadata("design:paramtypes", [Object]),
|
|
3474
3973
|
__metadata("design:returntype", Object)
|
|
3475
|
-
], StreamQuery.prototype, "
|
|
3974
|
+
], StreamQuery.prototype, "excuteUpdate", null);
|
|
3476
3975
|
__decorate([
|
|
3477
3976
|
IF_EXEC(0),
|
|
3478
3977
|
__metadata("design:type", Function),
|
|
3479
3978
|
__metadata("design:paramtypes", [Object]),
|
|
3480
3979
|
__metadata("design:returntype", Object)
|
|
3481
|
-
], StreamQuery.prototype, "
|
|
3980
|
+
], StreamQuery.prototype, "excuteDelete", null);
|
|
3482
3981
|
/**
|
|
3483
3982
|
获取REDIS客户端,
|
|
3484
3983
|
# [查看库的API](https://github.com/redis/ioredis?tab=readme-ov-file)
|
|
3485
3984
|
# [REDIS API](http://doc.redisfans.com/)
|
|
3486
3985
|
REDIS 的API 可以直接用,将方法名转为小写
|
|
3986
|
+
```
|
|
3987
|
+
// 设置<Redis>来获得代码提示
|
|
3988
|
+
getRedisDB<Redis>('').exists(?)
|
|
3989
|
+
```
|
|
3487
3990
|
*/
|
|
3488
3991
|
function getRedisDB(db) {
|
|
3489
|
-
const rd = globalThis[_dao][DBType.Redis][db ?? _primaryDB];
|
|
3992
|
+
const rd = globalThis[exports._dao][DBType.Redis][db ?? exports._primaryDB];
|
|
3490
3993
|
error_1.Throw.if(!rd, 'not found redis!');
|
|
3491
3994
|
return rd;
|
|
3492
3995
|
}
|
|
@@ -3495,7 +3998,7 @@ exports.getRedisDB = getRedisDB;
|
|
|
3495
3998
|
redlock
|
|
3496
3999
|
*/
|
|
3497
4000
|
async function GetRedisLock(key, lockMaxActive) {
|
|
3498
|
-
const lock = globalThis[_dao][DBType.RedisLock];
|
|
4001
|
+
const lock = globalThis[exports._dao][DBType.RedisLock];
|
|
3499
4002
|
error_1.Throw.if(!lock, 'not found lock!');
|
|
3500
4003
|
const db = getRedisDB();
|
|
3501
4004
|
let initLock;
|
|
@@ -3534,24 +4037,24 @@ async function excuteWithLock(config, fn__) {
|
|
|
3534
4037
|
const lock = await GetRedisLock(key, config.lockMaxActive);
|
|
3535
4038
|
if (lock === false) {
|
|
3536
4039
|
if (config.lockWait !== false && ((config.lockMaxWaitTime ?? 0) === 0 || (wait_time + (config.lockRetryInterval ?? 100)) <= (config.lockMaxWaitTime ?? 0))) {
|
|
3537
|
-
logger.debug(`get lock ${key} fail, retry after ${config.lockRetryInterval ?? 100}ms...`);
|
|
4040
|
+
exports.logger.debug(`get lock ${key} fail, retry after ${config.lockRetryInterval ?? 100}ms...`);
|
|
3538
4041
|
await (0, fn_1.sleep)(config.lockRetryInterval ?? 100);
|
|
3539
4042
|
wait_time += (config.lockRetryInterval ?? 100);
|
|
3540
4043
|
return await fn();
|
|
3541
4044
|
}
|
|
3542
4045
|
else {
|
|
3543
|
-
logger.debug(`get lock ${key} fail`);
|
|
4046
|
+
exports.logger.debug(`get lock ${key} fail`);
|
|
3544
4047
|
throw new Error(config.errorMessage || `get lock fail: ${key}`);
|
|
3545
4048
|
}
|
|
3546
4049
|
}
|
|
3547
4050
|
else {
|
|
3548
|
-
logger.debug(`get lock ${key} ok!`);
|
|
4051
|
+
exports.logger.debug(`get lock ${key} ok!`);
|
|
3549
4052
|
await db.get('other').pexpire(key, config.lockMaxTime ?? 60000);
|
|
3550
4053
|
try {
|
|
3551
4054
|
return await fn__();
|
|
3552
4055
|
}
|
|
3553
4056
|
finally {
|
|
3554
|
-
logger.debug(`unlock ${key} ok!`);
|
|
4057
|
+
exports.logger.debug(`unlock ${key} ok!`);
|
|
3555
4058
|
await db.get('other').decr(key);
|
|
3556
4059
|
}
|
|
3557
4060
|
}
|
|
@@ -3584,7 +4087,7 @@ async function setMethodCache(config, devid) {
|
|
|
3584
4087
|
await db.set(`[cache]${config.key}`, JSON.stringify(config.result), 'EX', config.autoClearTime * 60);
|
|
3585
4088
|
// 订阅:清空 clear list
|
|
3586
4089
|
if (config.clearKey && config.clearKey.length > 0) {
|
|
3587
|
-
globalThis[_EventBus].on(`[cache]${config.key}`, async (key) => {
|
|
4090
|
+
globalThis[exports._EventBus].on(`[cache]${config.key}`, async (key) => {
|
|
3588
4091
|
await clearChild(key, true);
|
|
3589
4092
|
});
|
|
3590
4093
|
}
|
|
@@ -3594,7 +4097,7 @@ async function setMethodCache(config, devid) {
|
|
|
3594
4097
|
}
|
|
3595
4098
|
if (devid) {
|
|
3596
4099
|
// 订阅:清空 clear list
|
|
3597
|
-
globalThis[_EventBus].on(`user-${devid}`, async function (key) {
|
|
4100
|
+
globalThis[exports._EventBus].on(`user-${devid}`, async function (key) {
|
|
3598
4101
|
await clearChild(key);
|
|
3599
4102
|
});
|
|
3600
4103
|
}
|
|
@@ -3634,7 +4137,7 @@ async function clearParent(clearKey) {
|
|
|
3634
4137
|
const keys = await db.smembers(`[cache-parent]${clearKey}`);
|
|
3635
4138
|
if (keys) {
|
|
3636
4139
|
for (const key of keys) {
|
|
3637
|
-
logger.debug(`cache ${key} cleared!`);
|
|
4140
|
+
exports.logger.debug(`cache ${key} cleared!`);
|
|
3638
4141
|
await clearChild(key);
|
|
3639
4142
|
}
|
|
3640
4143
|
}
|
|
@@ -3643,11 +4146,11 @@ async function excuteWithCache(config, fn) {
|
|
|
3643
4146
|
const db = getRedisDB();
|
|
3644
4147
|
const cache = await db.get(`[cache]${config.key}`);
|
|
3645
4148
|
if (cache) {
|
|
3646
|
-
logger.debug(`cache ${config.key} hit!`);
|
|
4149
|
+
exports.logger.debug(`cache ${config.key} hit!`);
|
|
3647
4150
|
return JSON.parse(cache);
|
|
3648
4151
|
}
|
|
3649
4152
|
else {
|
|
3650
|
-
logger.debug(`cache ${config.key} miss!`);
|
|
4153
|
+
exports.logger.debug(`cache ${config.key} miss!`);
|
|
3651
4154
|
const result = await fn();
|
|
3652
4155
|
await setMethodCache({
|
|
3653
4156
|
key: config.key,
|
|
@@ -3667,11 +4170,11 @@ function MethodCache(config) {
|
|
|
3667
4170
|
const db = getRedisDB();
|
|
3668
4171
|
const cache = await db.get('other').get(`[cache]${key}`);
|
|
3669
4172
|
if (cache) {
|
|
3670
|
-
logger.debug(`cache ${key} hit!`);
|
|
4173
|
+
exports.logger.debug(`cache ${key} hit!`);
|
|
3671
4174
|
return JSON.parse(cache);
|
|
3672
4175
|
}
|
|
3673
4176
|
else {
|
|
3674
|
-
logger.debug(`cache ${key} miss!`);
|
|
4177
|
+
exports.logger.debug(`cache ${key} miss!`);
|
|
3675
4178
|
const result = await fn.call(this, ...args);
|
|
3676
4179
|
const clearKey = config.clearKey ? typeof config.clearKey === 'function' ? config.clearKey.call(this, ...args) : config.clearKey : undefined;
|
|
3677
4180
|
await setMethodCache({
|
|
@@ -3689,6 +4192,8 @@ exports.MethodCache = MethodCache;
|
|
|
3689
4192
|
class MUParser {
|
|
3690
4193
|
constructor(modelName, file) {
|
|
3691
4194
|
this.linNumber = 0;
|
|
4195
|
+
this.lastLine = '';
|
|
4196
|
+
this.lastlastLine = '';
|
|
3692
4197
|
this.status = 0;
|
|
3693
4198
|
this.lineSeparator = '\n';
|
|
3694
4199
|
this.modelName = modelName;
|
|
@@ -3697,7 +4202,7 @@ class MUParser {
|
|
|
3697
4202
|
}
|
|
3698
4203
|
next() {
|
|
3699
4204
|
let sqlId = this.readSqlId();
|
|
3700
|
-
if (this.status === MUParser.END
|
|
4205
|
+
if (this.status === MUParser.END) {
|
|
3701
4206
|
return null;
|
|
3702
4207
|
}
|
|
3703
4208
|
// 去掉可能的尾部空格
|
|
@@ -3712,9 +4217,6 @@ class MUParser {
|
|
|
3712
4217
|
skipHeader() {
|
|
3713
4218
|
while (true) {
|
|
3714
4219
|
const line = this.nextLine();
|
|
3715
|
-
if (!line) {
|
|
3716
|
-
return;
|
|
3717
|
-
}
|
|
3718
4220
|
if (this.status === MUParser.END) {
|
|
3719
4221
|
return;
|
|
3720
4222
|
}
|
|
@@ -3741,7 +4243,7 @@ class MUParser {
|
|
|
3741
4243
|
let findComment = false;
|
|
3742
4244
|
while (true) {
|
|
3743
4245
|
let line = this.nextLine();
|
|
3744
|
-
if (this.status === MUParser.END
|
|
4246
|
+
if (this.status === MUParser.END) {
|
|
3745
4247
|
return;
|
|
3746
4248
|
}
|
|
3747
4249
|
line = line.trim();
|
|
@@ -3770,28 +4272,18 @@ class MUParser {
|
|
|
3770
4272
|
}
|
|
3771
4273
|
readSql() {
|
|
3772
4274
|
const list = [];
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
if (this.status === MUParser.END) {
|
|
3779
|
-
return this.getBuildSql(list);
|
|
3780
|
-
}
|
|
3781
|
-
if (line.startsWith('===')) {
|
|
3782
|
-
// 删除下一个sqlId表示
|
|
3783
|
-
list.pop();
|
|
3784
|
-
return this.getBuildSql(list);
|
|
3785
|
-
}
|
|
3786
|
-
list.push(line);
|
|
3787
|
-
}
|
|
3788
|
-
else {
|
|
3789
|
-
return '';
|
|
3790
|
-
}
|
|
4275
|
+
list.push(this.lastLine);
|
|
4276
|
+
while (true) {
|
|
4277
|
+
const line = this.nextLine();
|
|
4278
|
+
if (this.status === MUParser.END) {
|
|
4279
|
+
return this.getBuildSql(list);
|
|
3791
4280
|
}
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
4281
|
+
if (line.startsWith('===')) {
|
|
4282
|
+
// 删除下一个sqlId表示
|
|
4283
|
+
list.pop();
|
|
4284
|
+
return this.getBuildSql(list);
|
|
4285
|
+
}
|
|
4286
|
+
list.push(line);
|
|
3795
4287
|
}
|
|
3796
4288
|
}
|
|
3797
4289
|
getBuildSql(list) {
|
|
@@ -3808,127 +4300,3 @@ class MUParser {
|
|
|
3808
4300
|
}
|
|
3809
4301
|
}
|
|
3810
4302
|
MUParser.END = 1;
|
|
3811
|
-
const Boot = async function (options) {
|
|
3812
|
-
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
|
|
3813
|
-
if (options.sqlDir) {
|
|
3814
|
-
globalThis[_path] = await Promise.resolve().then(() => __importStar(require('path')));
|
|
3815
|
-
globalThis[_fs] = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
3816
|
-
}
|
|
3817
|
-
logger.level = options.log ?? 'info';
|
|
3818
|
-
globalThis[_sqlCache] = new SqlCache();
|
|
3819
|
-
if (options.sqlMap || options.sqlDir) {
|
|
3820
|
-
await globalThis[_sqlCache].init(options);
|
|
3821
|
-
}
|
|
3822
|
-
globalThis[_dao] = {
|
|
3823
|
-
[DBType.Mongo]: {},
|
|
3824
|
-
[DBType.Mysql]: {},
|
|
3825
|
-
[DBType.Sqlite]: {},
|
|
3826
|
-
[DBType.SqliteRemote]: {},
|
|
3827
|
-
[DBType.Redis]: {}
|
|
3828
|
-
};
|
|
3829
|
-
if (options.Mysql) {
|
|
3830
|
-
const { createPool } = await Promise.resolve().then(() => __importStar(require('mysql2/promise')));
|
|
3831
|
-
if (options.Mysql['host']) {
|
|
3832
|
-
globalThis[_dao][DBType.Mysql][_primaryDB] = new Mysql(createPool({
|
|
3833
|
-
...options.Mysql,
|
|
3834
|
-
multipleStatements: true,
|
|
3835
|
-
decimalNumbers: true,
|
|
3836
|
-
supportBigNumbers: true
|
|
3837
|
-
}));
|
|
3838
|
-
}
|
|
3839
|
-
else {
|
|
3840
|
-
let flag = false;
|
|
3841
|
-
for (const [key, option] of Object.entries(options.Mysql)) {
|
|
3842
|
-
const db = new Mysql(createPool({
|
|
3843
|
-
...option,
|
|
3844
|
-
multipleStatements: true,
|
|
3845
|
-
decimalNumbers: true,
|
|
3846
|
-
supportBigNumbers: true
|
|
3847
|
-
}));
|
|
3848
|
-
if (flag === false) {
|
|
3849
|
-
globalThis[_dao][DBType.Mysql][_primaryDB] = db;
|
|
3850
|
-
flag = true;
|
|
3851
|
-
}
|
|
3852
|
-
globalThis[_dao][DBType.Mysql][key] = db;
|
|
3853
|
-
}
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
if (options.Sqlite) {
|
|
3857
|
-
const BetterSqlite3 = await Promise.resolve().then(() => __importStar(require('better-sqlite3')));
|
|
3858
|
-
if (typeof options.Sqlite === 'string') {
|
|
3859
|
-
globalThis[_dao][DBType.Sqlite][_primaryDB] = new Sqlite(new BetterSqlite3.default(options.Sqlite, { fileMustExist: false }));
|
|
3860
|
-
}
|
|
3861
|
-
else {
|
|
3862
|
-
let flag = false;
|
|
3863
|
-
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
3864
|
-
const db = new Sqlite(new BetterSqlite3.default(fileName, { fileMustExist: false }));
|
|
3865
|
-
if (flag === false) {
|
|
3866
|
-
globalThis[_dao][DBType.Sqlite][_primaryDB] = db;
|
|
3867
|
-
flag = true;
|
|
3868
|
-
}
|
|
3869
|
-
globalThis[_dao][DBType.Sqlite][key] = db;
|
|
3870
|
-
}
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3873
|
-
if (options.SqliteRemote) {
|
|
3874
|
-
if (typeof options.SqliteRemote.db === 'string') {
|
|
3875
|
-
await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
3876
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
3877
|
-
}
|
|
3878
|
-
else {
|
|
3879
|
-
let flag = false;
|
|
3880
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
3881
|
-
await options.SqliteRemote.service.initDB(fileName);
|
|
3882
|
-
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
3883
|
-
if (flag === false) {
|
|
3884
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
3885
|
-
flag = true;
|
|
3886
|
-
}
|
|
3887
|
-
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
3888
|
-
}
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
if (options.Redis) {
|
|
3892
|
-
const { Redis } = await Promise.resolve().then(() => __importStar(require('ioredis')));
|
|
3893
|
-
if (options.Redis['host']) {
|
|
3894
|
-
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
3895
|
-
}
|
|
3896
|
-
else {
|
|
3897
|
-
let flag = false;
|
|
3898
|
-
for (const [key, option] of Object.entries(options.Redis)) {
|
|
3899
|
-
const db = new Redis(option);
|
|
3900
|
-
if (flag === false) {
|
|
3901
|
-
globalThis[_dao][DBType.Redis][_primaryDB] = db;
|
|
3902
|
-
flag = true;
|
|
3903
|
-
}
|
|
3904
|
-
globalThis[_dao][DBType.Redis][key] = db;
|
|
3905
|
-
}
|
|
3906
|
-
}
|
|
3907
|
-
const clients = Object.values(globalThis[_dao][DBType.Redis]);
|
|
3908
|
-
const Redlock = await Promise.resolve().then(() => __importStar(require('redlock')));
|
|
3909
|
-
globalThis[_dao][DBType.RedisLock] = new Redlock.default(clients, {
|
|
3910
|
-
// The expected clock drift; for more details see:
|
|
3911
|
-
// http://redis.io/topics/distlock
|
|
3912
|
-
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
3913
|
-
// The max number of times Redlock will attempt to lock a resource
|
|
3914
|
-
// before erroring.
|
|
3915
|
-
retryCount: 10,
|
|
3916
|
-
// the time in ms between attempts
|
|
3917
|
-
retryDelay: 200, // time in ms
|
|
3918
|
-
// the max time in ms randomly added to retries
|
|
3919
|
-
// to improve performance under high contention
|
|
3920
|
-
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
3921
|
-
retryJitter: 200, // time in ms
|
|
3922
|
-
// The minimum remaining time on a lock before an extension is automatically
|
|
3923
|
-
// attempted with the `using` API.
|
|
3924
|
-
automaticExtensionThreshold: 500, // time in ms
|
|
3925
|
-
});
|
|
3926
|
-
const { EventEmitter } = await Promise.resolve().then(() => __importStar(require('events')));
|
|
3927
|
-
const event = new EventEmitter({ captureRejections: true });
|
|
3928
|
-
event.on('error', error => {
|
|
3929
|
-
logger.error('event-bus', error);
|
|
3930
|
-
});
|
|
3931
|
-
globalThis[_EventBus] = event;
|
|
3932
|
-
}
|
|
3933
|
-
};
|
|
3934
|
-
exports.Boot = Boot;
|