baja-lite 1.0.4 → 1.0.6

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