baja-lite 1.4.6 → 1.4.7

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 (6) hide show
  1. package/boot.js +11 -8
  2. package/object.d.ts +2 -2
  3. package/object.js +25 -3
  4. package/package.json +1 -1
  5. package/sql.d.ts +415 -338
  6. package/sql.js +825 -395
package/sql.js CHANGED
@@ -26,7 +26,9 @@ import { add, calc, ten2Any } from './math.js';
26
26
  import { C2P, C2P2, P2C } from './object.js';
27
27
  import { emptyString } from './string.js';
28
28
  const iterate = ite.iterate;
29
- BigInt.prototype.toJSON = function () { return this.toString(); };
29
+ BigInt.prototype.toJSON = function () {
30
+ return this.toString();
31
+ };
30
32
  const BIGINT_EXT_TYPE = 0;
31
33
  export const extensionCodec = new ExtensionCodec();
32
34
  extensionCodec.register({
@@ -72,6 +74,7 @@ const _sqliteRemoteName = Symbol('sqliteRemoteName');
72
74
  const _SqlOption = Symbol('SqlOption');
73
75
  const _resultMap = Symbol('resultMap');
74
76
  const _resultMap_SQLID = Symbol('resultMap_SQLID');
77
+ export const _dataConvert = Symbol('dataConvert');
75
78
  export const _enum = Symbol('_enum');
76
79
  export const _GlobalSqlOption = Symbol('GlobalSqlOption');
77
80
  export const _EventBus = Symbol('EventBus');
@@ -101,7 +104,6 @@ export var MapperIfUndefined;
101
104
  MapperIfUndefined[MapperIfUndefined["Zero"] = 2] = "Zero";
102
105
  MapperIfUndefined[MapperIfUndefined["EmptyString"] = 3] = "EmptyString";
103
106
  })(MapperIfUndefined || (MapperIfUndefined = {}));
104
- ;
105
107
  export var SyncMode;
106
108
  (function (SyncMode) {
107
109
  /** 同步执行 */
@@ -112,27 +114,27 @@ export var SyncMode;
112
114
  export var InsertMode;
113
115
  (function (InsertMode) {
114
116
  /**
115
- # 默认使用
116
- ** 支持单个、批量,语法 `INSERT INTO XX VALUES (第一条数据), (第二条数据);`
117
- ** 批量执行有性能优势,但无法利用数据库的sql预编译功能
118
- */
117
+ # 默认使用
118
+ ** 支持单个、批量,语法 `INSERT INTO XX VALUES (第一条数据), (第二条数据);`
119
+ ** 批量执行有性能优势,但无法利用数据库的sql预编译功能
120
+ */
119
121
  InsertMode[InsertMode["Insert"] = 0] = "Insert";
120
122
  /**
121
- # 利用临时表
122
- ## 执行步骤
123
- 1. 建立临时表(从正式表复制)
124
- 2. 数据全部进入临时表
125
- 3. 临时表数据转移到正式表: `INSERT INTO 正式表 SELECT * FROM 临时表`
126
- 4. 删除临时表
127
- ## 注意
128
- 1. 适用于:主键不会冲突、非自增
129
- 2. 临时表的结构复制正式表
123
+ # 利用临时表
124
+ ## 执行步骤
125
+ 1. 建立临时表(从正式表复制)
126
+ 2. 数据全部进入临时表
127
+ 3. 临时表数据转移到正式表: `INSERT INTO 正式表 SELECT * FROM 临时表`
128
+ 4. 删除临时表
129
+ ## 注意
130
+ 1. 适用于:主键不会冲突、非自增
131
+ 2. 临时表的结构复制正式表
130
132
  */
131
133
  InsertMode[InsertMode["InsertWithTempTable"] = 1] = "InsertWithTempTable";
132
134
  InsertMode[InsertMode["InsertIfNotExists"] = 2] = "InsertIfNotExists";
133
135
  /**
134
- # 插入或者更新
135
- 1. 判断依据是主键
136
+ # 插入或者更新
137
+ 1. 判断依据是主键
136
138
  */
137
139
  InsertMode[InsertMode["Replace"] = 3] = "Replace";
138
140
  })(InsertMode || (InsertMode = {}));
@@ -144,7 +146,7 @@ export var DeleteMode;
144
146
  `DELETE FROM WHERE (id = 1) OR (id = 2)`
145
147
  ### 例二
146
148
  `DELETE FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
147
- */
149
+ */
148
150
  DeleteMode[DeleteMode["Common"] = 0] = "Common";
149
151
  /*
150
152
  ## 借助临时表
@@ -161,7 +163,7 @@ export var SelectMode;
161
163
  `SELECT * FROM WHERE (id = 1) OR (id = 2)`
162
164
  ### 例二
163
165
  `SELECT * FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
164
- */
166
+ */
165
167
  SelectMode[SelectMode["Common"] = 0] = "Common";
166
168
  /*
167
169
  ## 借助临时表
@@ -214,7 +216,6 @@ export const _defOption = {
214
216
  skipNull: true,
215
217
  skipEmptyString: true
216
218
  };
217
- ;
218
219
  class MysqlConnection {
219
220
  constructor(conn) {
220
221
  this[_b] = false;
@@ -225,12 +226,10 @@ class MysqlConnection {
225
226
  if (!sql) {
226
227
  return { affectedRows: 0, insertId: 0n };
227
228
  }
228
- ;
229
229
  if (sync === SyncMode.Sync) {
230
230
  logger.warn('MYSQL not suppouted sync mode');
231
231
  return { affectedRows: 0, insertId: 0n };
232
232
  }
233
- ;
234
233
  if (globalThis[_GlobalSqlOption].log === 'trace') {
235
234
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
236
235
  }
@@ -258,12 +257,10 @@ class MysqlConnection {
258
257
  if (!sql) {
259
258
  return null;
260
259
  }
261
- ;
262
260
  if (sync === SyncMode.Sync) {
263
261
  logger.warn('MYSQL not suppouted sync mode');
264
262
  return null;
265
263
  }
266
- ;
267
264
  if (globalThis[_GlobalSqlOption].log === 'trace') {
268
265
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
269
266
  }
@@ -294,12 +291,10 @@ class MysqlConnection {
294
291
  if (!sql) {
295
292
  return null;
296
293
  }
297
- ;
298
294
  if (sync === SyncMode.Sync) {
299
295
  logger.warn('MYSQL not suppouted sync mode');
300
296
  return null;
301
297
  }
302
- ;
303
298
  if (globalThis[_GlobalSqlOption].log === 'trace') {
304
299
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
305
300
  }
@@ -328,12 +323,10 @@ class MysqlConnection {
328
323
  if (!sql) {
329
324
  return [];
330
325
  }
331
- ;
332
326
  if (sync === SyncMode.Sync) {
333
327
  logger.warn('MYSQL not suppouted sync mode');
334
328
  return [];
335
329
  }
336
- ;
337
330
  if (globalThis[_GlobalSqlOption].log === 'trace') {
338
331
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
339
332
  }
@@ -362,12 +355,10 @@ class MysqlConnection {
362
355
  if (!sql) {
363
356
  return [];
364
357
  }
365
- ;
366
358
  if (sync === SyncMode.Sync) {
367
359
  logger.warn('MYSQL not suppouted sync mode');
368
360
  return [];
369
361
  }
370
- ;
371
362
  if (globalThis[_GlobalSqlOption].log === 'trace') {
372
363
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
373
364
  }
@@ -397,7 +388,6 @@ class MysqlConnection {
397
388
  catch (error) {
398
389
  }
399
390
  }
400
- ;
401
391
  }
402
392
  }
403
393
  _b = _inTransaction;
@@ -415,7 +405,6 @@ export class Mysql {
415
405
  logger.error('MYSQL not suppouted sync mode');
416
406
  return null;
417
407
  }
418
- ;
419
408
  return new Promise(async (resolve, reject) => {
420
409
  try {
421
410
  const connection = await this[_daoDB].getConnection();
@@ -432,7 +421,6 @@ export class Mysql {
432
421
  logger.warn('MYSQL not suppouted sync mode');
433
422
  return null;
434
423
  }
435
- ;
436
424
  return new Promise(async (resolve, reject) => {
437
425
  let needCommit = false;
438
426
  let newConn = false;
@@ -449,7 +437,7 @@ export class Mysql {
449
437
  conn[_inTransaction] = true;
450
438
  try {
451
439
  const result = await fn(conn);
452
- if (needCommit === true) {
440
+ if (needCommit) {
453
441
  logger.debug('commit begin!');
454
442
  await conn[_daoConnection].commit();
455
443
  conn[_inTransaction] = false;
@@ -467,10 +455,10 @@ export class Mysql {
467
455
  }
468
456
  finally {
469
457
  try {
470
- if (needCommit === true) {
458
+ if (needCommit) {
471
459
  conn[_inTransaction] = false;
472
460
  }
473
- if (newConn === true) {
461
+ if (newConn) {
474
462
  logger.debug('release begin!');
475
463
  conn[_daoConnection].release();
476
464
  logger.debug('release end!');
@@ -485,7 +473,6 @@ export class Mysql {
485
473
  if (sync === SyncMode.Sync) {
486
474
  this[_daoDB]?.destroy();
487
475
  }
488
- ;
489
476
  }
490
477
  backup(sync, name) {
491
478
  }
@@ -504,12 +491,10 @@ class PostgresqlConnection {
504
491
  if (!sql) {
505
492
  return { affectedRows: 0, insertId: 0n };
506
493
  }
507
- ;
508
494
  if (sync === SyncMode.Sync) {
509
495
  logger.warn('Postgresql not suppouted sync mode');
510
496
  return { affectedRows: 0, insertId: 0n };
511
497
  }
512
- ;
513
498
  if (globalThis[_GlobalSqlOption].log === 'trace') {
514
499
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
515
500
  }
@@ -541,12 +526,10 @@ class PostgresqlConnection {
541
526
  if (!sql) {
542
527
  return null;
543
528
  }
544
- ;
545
529
  if (sync === SyncMode.Sync) {
546
530
  logger.warn('Postgresql not suppouted sync mode');
547
531
  return null;
548
532
  }
549
- ;
550
533
  if (globalThis[_GlobalSqlOption].log === 'trace') {
551
534
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
552
535
  }
@@ -581,12 +564,10 @@ class PostgresqlConnection {
581
564
  if (!sql) {
582
565
  return null;
583
566
  }
584
- ;
585
567
  if (sync === SyncMode.Sync) {
586
568
  logger.warn('Postgresql not suppouted sync mode');
587
569
  return null;
588
570
  }
589
- ;
590
571
  if (globalThis[_GlobalSqlOption].log === 'trace') {
591
572
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
592
573
  }
@@ -619,12 +600,10 @@ class PostgresqlConnection {
619
600
  if (!sql) {
620
601
  return [];
621
602
  }
622
- ;
623
603
  if (sync === SyncMode.Sync) {
624
604
  logger.warn('Postgresql not suppouted sync mode');
625
605
  return [];
626
606
  }
627
- ;
628
607
  if (globalThis[_GlobalSqlOption].log === 'trace') {
629
608
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
630
609
  }
@@ -657,12 +636,10 @@ class PostgresqlConnection {
657
636
  if (!sql) {
658
637
  return [];
659
638
  }
660
- ;
661
639
  if (sync === SyncMode.Sync) {
662
640
  logger.warn('Postgresql not suppouted sync mode');
663
641
  return [];
664
642
  }
665
- ;
666
643
  if (globalThis[_GlobalSqlOption].log === 'trace') {
667
644
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
668
645
  }
@@ -696,7 +673,6 @@ class PostgresqlConnection {
696
673
  catch (error) {
697
674
  }
698
675
  }
699
- ;
700
676
  }
701
677
  }
702
678
  _c = _inTransaction;
@@ -714,7 +690,6 @@ export class Postgresql {
714
690
  logger.error('Postgresql not suppouted sync mode');
715
691
  return null;
716
692
  }
717
- ;
718
693
  return new Promise(async (resolve, reject) => {
719
694
  try {
720
695
  const connection = await this[_daoDB].connect();
@@ -731,7 +706,6 @@ export class Postgresql {
731
706
  logger.warn('Postgresql not suppouted sync mode');
732
707
  return null;
733
708
  }
734
- ;
735
709
  return new Promise(async (resolve, reject) => {
736
710
  let needCommit = false;
737
711
  let newConn = false;
@@ -748,7 +722,7 @@ export class Postgresql {
748
722
  conn[_inTransaction] = true;
749
723
  try {
750
724
  const result = await fn(conn);
751
- if (needCommit === true) {
725
+ if (needCommit) {
752
726
  logger.debug('commit begin!');
753
727
  await conn[_daoConnection].query('COMMIT');
754
728
  conn[_inTransaction] = false;
@@ -766,10 +740,10 @@ export class Postgresql {
766
740
  }
767
741
  finally {
768
742
  try {
769
- if (needCommit === true) {
743
+ if (needCommit) {
770
744
  conn[_inTransaction] = false;
771
745
  }
772
- if (newConn === true) {
746
+ if (newConn) {
773
747
  logger.debug('release begin!');
774
748
  conn[_daoConnection].release();
775
749
  logger.debug('release end!');
@@ -784,7 +758,6 @@ export class Postgresql {
784
758
  if (sync === SyncMode.Sync) {
785
759
  this[_daoDB]?.end();
786
760
  }
787
- ;
788
761
  }
789
762
  backup(sync, name) {
790
763
  }
@@ -804,12 +777,10 @@ class SqliteConnection {
804
777
  if (!sql) {
805
778
  return { affectedRows: 0, insertId: 0n };
806
779
  }
807
- ;
808
780
  if (sync === SyncMode.Async) {
809
781
  logger.warn(`SQLITE not suppoted async mode`);
810
782
  return { affectedRows: 0, insertId: 0n };
811
783
  }
812
- ;
813
784
  if (globalThis[_GlobalSqlOption].log === 'trace') {
814
785
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
815
786
  }
@@ -835,12 +806,10 @@ class SqliteConnection {
835
806
  if (!sql) {
836
807
  return null;
837
808
  }
838
- ;
839
809
  if (sync === SyncMode.Async) {
840
810
  logger.warn(`SQLITE not suppoted async mode`);
841
811
  return null;
842
812
  }
843
- ;
844
813
  if (globalThis[_GlobalSqlOption].log === 'trace') {
845
814
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
846
815
  }
@@ -861,11 +830,9 @@ class SqliteConnection {
861
830
  if (!sql) {
862
831
  return null;
863
832
  }
864
- ;
865
833
  if (sync === SyncMode.Async) {
866
834
  return null;
867
835
  }
868
- ;
869
836
  if (globalThis[_GlobalSqlOption].log === 'trace') {
870
837
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
871
838
  }
@@ -886,12 +853,10 @@ class SqliteConnection {
886
853
  if (!sql) {
887
854
  return [];
888
855
  }
889
- ;
890
856
  if (sync === SyncMode.Async) {
891
857
  logger.warn(`SQLITE not suppoted async mode`);
892
858
  return [];
893
859
  }
894
- ;
895
860
  if (globalThis[_GlobalSqlOption].log === 'trace') {
896
861
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
897
862
  }
@@ -912,12 +877,10 @@ class SqliteConnection {
912
877
  if (!sql) {
913
878
  return [];
914
879
  }
915
- ;
916
880
  if (sync === SyncMode.Async) {
917
881
  logger.warn(`SQLITE not suppoted async mode`);
918
882
  return [];
919
883
  }
920
- ;
921
884
  if (globalThis[_GlobalSqlOption].log === 'trace') {
922
885
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
923
886
  }
@@ -941,14 +904,37 @@ export class Sqlite {
941
904
  this[_daoDB] = db;
942
905
  this[_daoDB].pragma('journal_mode = WAL');
943
906
  this[_daoDB].exec(`
944
- CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
945
- DELETE FROM DUAL;
946
- INSERT INTO DUAL (______id ) VALUES ( 1 );
947
- CREATE TABLE IF NOT EXISTS TABLE_VERSION (
948
- ______tableName text NOT NULL,
949
- ______version text NOT NULL,
950
- PRIMARY KEY ( ______tableName )
951
- );
907
+ CREATE TABLE IF NOT EXISTS DUAL
908
+ (
909
+ ______id
910
+ INTEGER
911
+ NOT
912
+ NULL,
913
+ PRIMARY
914
+ KEY
915
+ (
916
+ ______id
917
+ ));
918
+ DELETE
919
+ FROM DUAL;
920
+ INSERT INTO DUAL (______id)
921
+ VALUES (1);
922
+ CREATE TABLE IF NOT EXISTS TABLE_VERSION
923
+ (
924
+ ______tableName
925
+ text
926
+ NOT
927
+ NULL,
928
+ ______version
929
+ text
930
+ NOT
931
+ NULL,
932
+ PRIMARY
933
+ KEY
934
+ (
935
+ ______tableName
936
+ )
937
+ );
952
938
  `);
953
939
  }
954
940
  createConnection(sync) {
@@ -956,7 +942,6 @@ export class Sqlite {
956
942
  logger.error(`SQLITE not suppoted async mode`);
957
943
  return null;
958
944
  }
959
- ;
960
945
  return new SqliteConnection(this[_daoDB]);
961
946
  }
962
947
  transaction(sync, fn, conn) {
@@ -964,11 +949,10 @@ export class Sqlite {
964
949
  logger.warn(`SQLITE not suppoted async mode`);
965
950
  return null;
966
951
  }
967
- ;
968
952
  if (!conn) {
969
953
  conn = this.createConnection(SyncMode.Sync) ?? undefined;
970
954
  }
971
- if (conn[_inTransaction] !== true) {
955
+ if (!conn[_inTransaction]) {
972
956
  return this[_daoDB].transaction(() => {
973
957
  conn[_inTransaction] = true;
974
958
  const rt = fn(conn);
@@ -985,13 +969,11 @@ export class Sqlite {
985
969
  if (sync === SyncMode.Sync) {
986
970
  this[_daoDB].close();
987
971
  }
988
- ;
989
972
  }
990
973
  backup(sync, name) {
991
974
  if (sync === SyncMode.Sync) {
992
975
  this[_daoDB].backup(name);
993
976
  }
994
- ;
995
977
  }
996
978
  remove(sync) {
997
979
  }
@@ -1009,12 +991,10 @@ export class SqliteRemoteConnection {
1009
991
  if (!sql) {
1010
992
  return { affectedRows: 0, insertId: 0n };
1011
993
  }
1012
- ;
1013
994
  if (sync === SyncMode.Sync) {
1014
995
  logger.warn('SqliteRemote not suppouted sync mode');
1015
996
  return { affectedRows: 0, insertId: 0n };
1016
997
  }
1017
- ;
1018
998
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1019
999
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1020
1000
  }
@@ -1039,12 +1019,10 @@ export class SqliteRemoteConnection {
1039
1019
  if (!sql) {
1040
1020
  return null;
1041
1021
  }
1042
- ;
1043
1022
  if (sync === SyncMode.Sync) {
1044
1023
  logger.warn('SqliteRemote not suppouted sync mode');
1045
1024
  return null;
1046
1025
  }
1047
- ;
1048
1026
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1049
1027
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1050
1028
  }
@@ -1069,12 +1047,10 @@ export class SqliteRemoteConnection {
1069
1047
  if (!sql) {
1070
1048
  return null;
1071
1049
  }
1072
- ;
1073
1050
  if (sync === SyncMode.Sync) {
1074
1051
  logger.warn('SqliteRemote not suppouted sync mode');
1075
1052
  return null;
1076
1053
  }
1077
- ;
1078
1054
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1079
1055
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1080
1056
  }
@@ -1099,12 +1075,10 @@ export class SqliteRemoteConnection {
1099
1075
  if (!sql) {
1100
1076
  return [];
1101
1077
  }
1102
- ;
1103
1078
  if (sync === SyncMode.Sync) {
1104
1079
  logger.warn('SqliteRemote not suppouted sync mode');
1105
1080
  return [];
1106
1081
  }
1107
- ;
1108
1082
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1109
1083
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1110
1084
  }
@@ -1129,12 +1103,10 @@ export class SqliteRemoteConnection {
1129
1103
  if (!sql) {
1130
1104
  return [];
1131
1105
  }
1132
- ;
1133
1106
  if (sync === SyncMode.Sync) {
1134
1107
  logger.warn('SqliteRemote not suppouted sync mode');
1135
1108
  return [];
1136
1109
  }
1137
- ;
1138
1110
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1139
1111
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1140
1112
  }
@@ -1168,7 +1140,6 @@ export class SqliteRemote {
1168
1140
  logger.error('SQLITEREMOTE not suppouted sync mode');
1169
1141
  return null;
1170
1142
  }
1171
- ;
1172
1143
  return new Promise(async (resolve, reject) => {
1173
1144
  if (!this.connection) {
1174
1145
  this.connection = new SqliteRemoteConnection(this[_daoDB], this[_sqliteRemoteName]);
@@ -1189,13 +1160,11 @@ export class SqliteRemote {
1189
1160
  if (sync === SyncMode.Async) {
1190
1161
  return this[_daoDB]?.close(this[_sqliteRemoteName]);
1191
1162
  }
1192
- ;
1193
1163
  }
1194
1164
  backup(sync, exportPath) {
1195
1165
  if (sync === SyncMode.Async) {
1196
1166
  return this[_daoDB]?.export(this[_sqliteRemoteName], exportPath);
1197
1167
  }
1198
- ;
1199
1168
  }
1200
1169
  remove(sync) {
1201
1170
  }
@@ -1203,13 +1172,12 @@ export class SqliteRemote {
1203
1172
  if (sync === SyncMode.Async) {
1204
1173
  return this[_daoDB]?.restore(this[_sqliteRemoteName], importPath);
1205
1174
  }
1206
- ;
1207
1175
  }
1208
1176
  }
1209
1177
  class Build {
1210
1178
  /**
1211
1179
  *
1212
- * @param count 是否是count查询
1180
+ * @param isCount 是否是count查询
1213
1181
  * @param isSum 是否是sum查询
1214
1182
  * @param param
1215
1183
  */
@@ -1228,23 +1196,23 @@ class Build {
1228
1196
  */
1229
1197
  page() {
1230
1198
  return (text, render) => {
1231
- if (this.isCount === true) {
1199
+ if (this.isCount) {
1232
1200
  return Build.page;
1233
1201
  }
1234
- else if (this.isSum !== true) {
1202
+ else if (!this.isSum) {
1235
1203
  return render(text);
1236
1204
  }
1237
1205
  };
1238
1206
  }
1239
1207
  /**
1240
- *
1241
- * 包含的内容只在汇总查询时有效,否则是空白
1242
- * @returns
1243
- * @memberof Build
1244
- */
1208
+ *
1209
+ * 包含的内容只在汇总查询时有效,否则是空白
1210
+ * @returns
1211
+ * @memberof Build
1212
+ */
1245
1213
  sum() {
1246
1214
  return (text, render) => {
1247
- if (this.isSum !== true) {
1215
+ if (!this.isSum) {
1248
1216
  return '';
1249
1217
  }
1250
1218
  else {
@@ -1260,7 +1228,7 @@ class Build {
1260
1228
  */
1261
1229
  notPage() {
1262
1230
  return (text, render) => {
1263
- if (this.isCount === true || this.isSum === true) {
1231
+ if (this.isCount || this.isSum) {
1264
1232
  return '';
1265
1233
  }
1266
1234
  else {
@@ -1314,7 +1282,7 @@ class Build {
1314
1282
  const datas = data.split(',');
1315
1283
  for (let i = 0; i < datas.length; i++) {
1316
1284
  if (datas[i]?.match(/\s|\t/) === null) {
1317
- datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b, c) => b.toUpperCase())}`;
1285
+ datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b) => b.toUpperCase())}`;
1318
1286
  }
1319
1287
  }
1320
1288
  return ` ${datas.join(',')} `;
@@ -1351,7 +1319,7 @@ class Build {
1351
1319
  */
1352
1320
  order() {
1353
1321
  return (text, render) => {
1354
- if (this.isCount === true || this.isSum === true) {
1322
+ if (this.isCount || this.isSum) {
1355
1323
  return '';
1356
1324
  }
1357
1325
  else {
@@ -1381,7 +1349,7 @@ class Build {
1381
1349
  */
1382
1350
  group() {
1383
1351
  return (text, render) => {
1384
- if (this.isCount === true || this.isSum === true) {
1352
+ if (this.isCount || this.isSum) {
1385
1353
  return '';
1386
1354
  }
1387
1355
  else {
@@ -1492,13 +1460,13 @@ class Build {
1492
1460
  }
1493
1461
  Build.page = 'COUNT(1) zccw1986 ';
1494
1462
  function replaceCdata(rawText) {
1495
- var cdataRegex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1496
- var matches = rawText.match(cdataRegex);
1463
+ const cdataRegex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1464
+ const matches = rawText.match(cdataRegex);
1497
1465
  if (matches != null && matches.length > 0) {
1498
- for (var z = 0; z < matches.length; z++) {
1499
- var regex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1500
- var m = regex.exec(matches[z]);
1501
- var cdataText = m[2];
1466
+ for (let z = 0; z < matches.length; z++) {
1467
+ const regex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1468
+ const m = regex.exec(matches[z]);
1469
+ let cdataText = m[2];
1502
1470
  cdataText = cdataText.replace(/\&/g, '&amp;');
1503
1471
  cdataText = cdataText.replace(/\</g, '&lt;');
1504
1472
  cdataText = cdataText.replace(/\>/g, '&gt;');
@@ -1508,7 +1476,7 @@ function replaceCdata(rawText) {
1508
1476
  }
1509
1477
  return rawText;
1510
1478
  }
1511
- function _flatData(result, i, length, keys, V) {
1479
+ function _flatData(result, i, length, keys, V, convert) {
1512
1480
  var _f;
1513
1481
  const key = keys[i];
1514
1482
  if (i < length) {
@@ -1517,7 +1485,12 @@ function _flatData(result, i, length, keys, V) {
1517
1485
  _flatData(result[key], i, length, keys, V);
1518
1486
  }
1519
1487
  else {
1520
- result[key] = V;
1488
+ if (convert) {
1489
+ result[key] = convert(V);
1490
+ }
1491
+ else {
1492
+ result[key] = V;
1493
+ }
1521
1494
  }
1522
1495
  }
1523
1496
  /**
@@ -1532,7 +1505,7 @@ export function flatData(options) {
1532
1505
  options.mapperIfUndefined ?? (options.mapperIfUndefined = MapperIfUndefined.Skip);
1533
1506
  options.mapper = options.mapper;
1534
1507
  const result = {};
1535
- for (const [columnName, keys, def] of options.mapper) {
1508
+ for (const { columnName, mapNames, def, convert } of options.mapper) {
1536
1509
  let V = options.data[columnName];
1537
1510
  if (V === undefined) {
1538
1511
  if (options.mapperIfUndefined === MapperIfUndefined.Null) {
@@ -1551,7 +1524,7 @@ export function flatData(options) {
1551
1524
  continue;
1552
1525
  }
1553
1526
  }
1554
- _flatData(result, 0, keys.length - 1, keys, V);
1527
+ _flatData(result, 0, mapNames.length - 1, mapNames, V, convert);
1555
1528
  }
1556
1529
  return result;
1557
1530
  }
@@ -1584,7 +1557,7 @@ export class SqlCache {
1584
1557
  }
1585
1558
  logger.debug(`sql: ${file} explain over[${ct}]!`);
1586
1559
  }
1587
- else if (jsMode === true && extname === '.js') {
1560
+ else if (jsMode && extname === '.js') {
1588
1561
  logger.debug(`sql: ${file} start explain!`);
1589
1562
  const obj = (await import(globalThis[_path].join(sqlDir, modeName))).default;
1590
1563
  for (const [key, fn] of Object.entries(obj)) {
@@ -1610,8 +1583,8 @@ export class SqlCache {
1610
1583
  globalThis[_resultMap] ?? (globalThis[_resultMap] = {});
1611
1584
  const keys = [];
1612
1585
  this.readResultMap(am.children, keys, []);
1613
- globalThis[_resultMap][am.id] = keys;
1614
- logger.debug(`sql_resultMap: ${am.id} found!`);
1586
+ globalThis[_resultMap][`${rootName || name}.${am.id}`] = keys;
1587
+ logger.debug(`sql_resultMap: ${`${rootName || name}.${am.id}`} found!`);
1615
1588
  }
1616
1589
  else {
1617
1590
  this.sqlMap[`${rootName || name}.${am.id}`] = am.children;
@@ -1635,20 +1608,24 @@ export class SqlCache {
1635
1608
  /**
1636
1609
  *
1637
1610
  * ```
1638
- // 第一个元素=列名,第二个元素是属性路径,
1639
- [
1640
- ['dit_id', ['id']], // 列名ditid,对应属性id
1641
- ['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
1642
- ]
1611
+ // 第一个元素=列名,第二个元素是属性路径,
1612
+ [
1613
+ ['dit_id', ['id']], // 列名ditid,对应属性id
1614
+ ['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
1615
+ ]
1643
1616
  * ```
1644
- * @param am
1617
+ * @param ams
1645
1618
  * @param keys
1619
+ * @param key
1646
1620
  */
1647
1621
  readResultMap(ams, keys, key) {
1648
1622
  for (const am of ams) {
1649
1623
  if (am.type === 'tag') {
1650
1624
  if (am.name === 'result' || am.name === 'id') {
1651
- keys.push([am.attrs['column'], [...key, am.attrs['property']]]);
1625
+ keys.push({
1626
+ columnName: am.attrs['column'],
1627
+ mapNames: [...key, am.attrs['property']]
1628
+ });
1652
1629
  }
1653
1630
  else {
1654
1631
  this.readResultMap(am.children, keys, [...key, am.attrs['property']]);
@@ -1708,14 +1685,14 @@ export class SqlCache {
1708
1685
  if (typeof sqlSource === 'function') {
1709
1686
  const _sql = sqlSource(options);
1710
1687
  let sql = mustache.render(_sql, buildParam, this.sqlFNMap);
1711
- if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1688
+ if (!buildParam.OrderSeted && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1712
1689
  sql += ` ORDER BY ${buildParam.OrderBy}`;
1713
1690
  }
1714
1691
  return sql;
1715
1692
  }
1716
1693
  else if (typeof sqlSource === 'string') {
1717
1694
  let sql = mustache.render(sqlSource, buildParam, this.sqlFNMap);
1718
- if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1695
+ if (!buildParam.OrderSeted && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1719
1696
  sql += ` ORDER BY ${buildParam.OrderBy}`;
1720
1697
  }
1721
1698
  return sql;
@@ -1723,7 +1700,7 @@ export class SqlCache {
1723
1700
  else if (typeof sqlSource === 'object') {
1724
1701
  const _sql = convert(sqlSource, options, matchSqlid, this.sqlMap);
1725
1702
  let sql = mustache.render(_sql, buildParam, this.sqlFNMap);
1726
- if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1703
+ if (!buildParam.OrderSeted && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1727
1704
  sql += ` ORDER BY ${buildParam.OrderBy}`;
1728
1705
  }
1729
1706
  return sql;
@@ -1734,18 +1711,18 @@ export class SqlCache {
1734
1711
  // #endregion
1735
1712
  /**
1736
1713
 
1737
- ## 所有service中内置方法定义规则
1714
+ ## 所有service中内置方法定义规则
1738
1715
  ** 方法第一个参数必须是 sync: SyncMode
1739
1716
  ** 方法最后一个参数必须是 option
1740
1717
 
1741
- ## sync 表示是否是同步方法
1718
+ ## sync 表示是否是同步方法
1742
1719
 
1743
- 因为mysql是异步、sqlite是同步,导致必须通过一个标识来区分,否则将必须为两种数据库设置不同的service,失去了意义
1720
+ 因为mysql是异步、sqlite是同步,导致必须通过一个标识来区分,否则将必须为两种数据库设置不同的service,失去了意义
1744
1721
 
1745
- ## option 额外控制参数
1722
+ ## option 额外控制参数
1746
1723
 
1747
- ## length
1748
- 方法的参数数量
1724
+ ## length
1725
+ 方法的参数数量
1749
1726
  */
1750
1727
  function P(skipConn = false) {
1751
1728
  return (_target, propertyKey, descriptor) => {
@@ -1771,7 +1748,7 @@ function P(skipConn = false) {
1771
1748
  }
1772
1749
  Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!');
1773
1750
  // 连接共享
1774
- if (skipConn === false && !option.conn) {
1751
+ if (!skipConn && !option.conn) {
1775
1752
  option.conn = option.dao.createConnection(SyncMode.Sync);
1776
1753
  }
1777
1754
  else {
@@ -1814,7 +1791,7 @@ function P(skipConn = false) {
1814
1791
  Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!');
1815
1792
  return new Promise(async (resolve, reject) => {
1816
1793
  // 连接共享
1817
- if (skipConn === false && !option.conn) {
1794
+ if (!skipConn && !option.conn) {
1818
1795
  (option).conn = await option.dao.createConnection(SyncMode.Async);
1819
1796
  }
1820
1797
  else {
@@ -1846,7 +1823,7 @@ function P(skipConn = false) {
1846
1823
  return new Promise(async (resolve, reject) => {
1847
1824
  try {
1848
1825
  // 连接共享
1849
- if (skipConn === false && !option.conn) {
1826
+ if (!skipConn && !option.conn) {
1850
1827
  (option).conn = await option.dao.createConnection(SyncMode.Async);
1851
1828
  }
1852
1829
  else {
@@ -1877,7 +1854,7 @@ function P(skipConn = false) {
1877
1854
  return new Promise(async (resolve, reject) => {
1878
1855
  try {
1879
1856
  // 连接共享
1880
- if (skipConn === false && !option.conn) {
1857
+ if (!skipConn && !option.conn) {
1881
1858
  (option).conn = await option.dao.createConnection(SyncMode.Async);
1882
1859
  }
1883
1860
  else {
@@ -1910,7 +1887,7 @@ const FieldFilter = (K, V, def, uuidColumn, option) => {
1910
1887
  let ret = 0;
1911
1888
  // 如果是插入操作且字段是UUID,则不进行空值检查
1912
1889
  // 只有在非插入或者非UUID时,进行空置检查
1913
- if (option?.insert === true && uuidColumn === true) {
1890
+ if (option?.insert === true && uuidColumn) {
1914
1891
  ret = 1;
1915
1892
  if (V === undefined || emptyString(`${V ?? ''}`)) {
1916
1893
  V = null;
@@ -2033,16 +2010,16 @@ export const DB = (config) => {
2033
2010
  };
2034
2011
  };
2035
2012
  /**
2036
- js项目中实体类注解替代品,只要确保函数被执行即可,举例:
2037
- ```
2038
- // 声明一个class
2039
- export class AmaFuck {}
2040
- DeclareClass(AmaFuck, [
2041
- { type: "String", name: "SellerSKU" },
2042
- { type: "String", name: "SellerSKU2" },
2043
- { type: "String", name: "site" }
2044
- ]);
2045
- ```
2013
+ js项目中实体类注解替代品,只要确保函数被执行即可,举例:
2014
+ ```
2015
+ // 声明一个class
2016
+ export class AmaFuck {}
2017
+ DeclareClass(AmaFuck, [
2018
+ { type: "String", name: "SellerSKU" },
2019
+ { type: "String", name: "SellerSKU2" },
2020
+ { type: "String", name: "site" }
2021
+ ]);
2022
+ ```
2046
2023
  */
2047
2024
  export function DeclareClass(clz, FieldOptions) {
2048
2025
  for (const item of FieldOptions) {
@@ -2053,13 +2030,13 @@ export function DeclareClass(clz, FieldOptions) {
2053
2030
  JS项目中,service注解代替,举例:
2054
2031
  ```
2055
2032
  // 声明一个service,注意这里的let
2056
- export let AmaService = class AmaService extends SqlService {};
2057
- AmaService = DeclareService(AmaService, {
2058
- tableName: "ama_fuck2",
2059
- clz: AmaFuck,
2060
- dbType: DBType.Sqlite,
2061
- sqliteVersion: "0.0.3"
2062
- });
2033
+ export let AmaService = class AmaService extends SqlService {};
2034
+ AmaService = DeclareService(AmaService, {
2035
+ tableName: "ama_fuck2",
2036
+ clz: AmaFuck,
2037
+ dbType: DBType.Sqlite,
2038
+ sqliteVersion: "0.0.3"
2039
+ });
2063
2040
  ```
2064
2041
  */
2065
2042
  export function DeclareService(clz, config) {
@@ -2068,11 +2045,11 @@ export function DeclareService(clz, config) {
2068
2045
  /**
2069
2046
  ## 数据库服务
2070
2047
  ### 注解DB
2071
-
2048
+
2072
2049
  ### 泛型 T,同DB注解中的clz
2073
2050
  ** 服务中所有方法默认以该类型为准
2074
2051
  **
2075
-
2052
+
2076
2053
  */
2077
2054
  export class SqlService {
2078
2055
  _insert(datas, option) {
@@ -2140,13 +2117,14 @@ export class SqlService {
2140
2117
  ? this[_def][column]
2141
2118
  : null);
2142
2119
  }
2143
- return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2120
+ return `SELECT ${questMark.join(',')}
2121
+ FROM DUAL
2122
+ WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2144
2123
  });
2145
2124
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2146
- const sql = formatDialect(`INSERT INTO
2147
- ${tableName}
2148
- (${columnNames})
2149
- ${questMarks.join(' UNION ALL ')};`, { dialect: formatDialects[option.dbType] });
2125
+ const sql = formatDialect(`INSERT INTO ${tableName}
2126
+ (${columnNames})
2127
+ ${questMarks.join(' UNION ALL ')};`, { dialect: formatDialects[option.dbType] });
2150
2128
  sqls.push({ sql, params });
2151
2129
  break;
2152
2130
  }
@@ -2203,10 +2181,14 @@ export class SqlService {
2203
2181
  });
2204
2182
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2205
2183
  const sql = formatDialect(`
2206
- ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2184
+ ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'}
2185
+ REPLACE INTO
2207
2186
  ${tableName}
2208
- (${columnNames})
2209
- VALUES ${questMarks};
2187
+ (
2188
+ ${columnNames}
2189
+ )
2190
+ VALUES
2191
+ ${questMarks};
2210
2192
  `, { dialect: formatDialects[option.dbType] });
2211
2193
  sqls.push({ sql, params });
2212
2194
  break;
@@ -2264,9 +2246,8 @@ export class SqlService {
2264
2246
  });
2265
2247
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2266
2248
  const sql = formatDialect(`
2267
- INSERT INTO
2268
- ${tableName}
2269
- (${columnNames})
2249
+ INSERT INTO ${tableName}
2250
+ (${columnNames})
2270
2251
  VALUES ${questMarks};
2271
2252
  `, { dialect: formatDialects[option.dbType] });
2272
2253
  sqls.push({ sql, params });
@@ -2331,15 +2312,15 @@ export class SqlService {
2331
2312
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2332
2313
  sqls.push({
2333
2314
  sql: formatDialect(`
2334
- INSERT INTO
2335
- ${tableTemp}
2336
- (${columnNames})
2315
+ INSERT INTO ${tableTemp}
2316
+ (${columnNames})
2337
2317
  VALUES ${questMarks};
2338
2318
  `, { dialect: formatDialects[option.dbType] }), params
2339
2319
  });
2340
2320
  sqls.push({
2341
2321
  sql: formatDialect(`INSERT INTO ${option.tableName} (${columnNames})
2342
- SELECT ${columnNames} FROM ${tableTemp};`, { dialect: formatDialects[option.dbType] })
2322
+ SELECT ${columnNames}
2323
+ FROM ${tableTemp};`, { dialect: formatDialects[option.dbType] })
2343
2324
  });
2344
2325
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2345
2326
  break;
@@ -2446,7 +2427,8 @@ export class SqlService {
2446
2427
  }
2447
2428
  });
2448
2429
  }
2449
- const sql = formatDialect(`UPDATE ${tableName} SET ${iterate(this[_columnsNoId])
2430
+ const sql = formatDialect(`UPDATE ${tableName}
2431
+ SET ${iterate(this[_columnsNoId])
2450
2432
  .filter(K => columnMaps[K].where.length > 0)
2451
2433
  .map(K => {
2452
2434
  params.push(...columnMaps[K].params);
@@ -2540,32 +2522,54 @@ export class SqlService {
2540
2522
  params.unshift(this[_deleteState]);
2541
2523
  sqls.push({
2542
2524
  sql: formatDialect(`
2543
- UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2544
- WHERE ${whereSql};
2545
- `, { dialect: formatDialects[option.dbType] }), params
2525
+ UPDATE ${tableNameESC}
2526
+ SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2527
+ WHERE ${whereSql};
2528
+ `, { dialect: formatDialects[option.dbType] }), params
2546
2529
  });
2547
2530
  }
2548
2531
  else {
2549
- sqls.push({ sql: formatDialect(`DELETE FROM ${tableNameESC} WHERE ${whereSql};`, { dialect: formatDialects[option.dbType] }), params });
2532
+ sqls.push({
2533
+ sql: formatDialect(`DELETE
2534
+ FROM ${tableNameESC}
2535
+ WHERE ${whereSql};`, { dialect: formatDialects[option.dbType] }), params
2536
+ });
2550
2537
  }
2551
2538
  }
2552
2539
  else {
2553
2540
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2554
2541
  const delWhere = Object.keys(wheres[0]);
2555
- const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: delWhere, data: wheres, index: 'all', id: 'none' });
2542
+ const _sqls = this._createTable({
2543
+ tableName: tableTemp,
2544
+ temp: true,
2545
+ columns: delWhere,
2546
+ data: wheres,
2547
+ index: 'all',
2548
+ id: 'none'
2549
+ });
2556
2550
  sqls.push(..._sqls);
2557
2551
  switch (option.dbType) {
2558
2552
  case DBType.Mysql: {
2559
2553
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2560
2554
  sqls.push({
2561
- sql: formatDialect(`UPDATE ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')}
2562
- SET a.${this[_fields][this[_stateFileName]]?.C2()} = ?;`, { dialect: formatDialects[option.dbType] }),
2555
+ sql: formatDialect(`UPDATE ${tableNameESC} a INNER JOIN ${tableTempESC} b
2556
+ ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')}
2557
+ SET a.${this[_fields][this[_stateFileName]]?.C2()} = ?;`, { dialect: formatDialects[option.dbType] }),
2563
2558
  params: [this[_deleteState]]
2564
2559
  });
2565
2560
  }
2566
2561
  else {
2567
2562
  sqls.push({
2568
- sql: formatDialect(`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 ')};`, { dialect: formatDialects[option.dbType] })
2563
+ sql: formatDialect(`DELETE
2564
+ a.* FROM
2565
+ ${tableNameESC}
2566
+ a
2567
+ INNER
2568
+ JOIN
2569
+ ${tableTempESC}
2570
+ b
2571
+ ON
2572
+ ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')};`, { dialect: formatDialects[option.dbType] })
2569
2573
  });
2570
2574
  }
2571
2575
  break;
@@ -2575,13 +2579,18 @@ export class SqlService {
2575
2579
  const columnNames = iterate(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2576
2580
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2577
2581
  sqls.push({
2578
- sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2579
- WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }),
2582
+ sql: formatDialect(`UPDATE ${tableNameESC}
2583
+ SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2584
+ WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }),
2580
2585
  params: [this[_deleteState]]
2581
2586
  });
2582
2587
  }
2583
2588
  else {
2584
- sqls.push({ sql: formatDialect(`DELETE FROM ${tableNameESC} WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }) });
2589
+ sqls.push({
2590
+ sql: formatDialect(`DELETE
2591
+ FROM ${tableNameESC}
2592
+ WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] })
2593
+ });
2585
2594
  }
2586
2595
  break;
2587
2596
  }
@@ -2665,8 +2674,9 @@ export class SqlService {
2665
2674
  if (option.mode === SelectMode.Common) {
2666
2675
  const params = new Array();
2667
2676
  const whereSql = formatDialect(iterate(wheres).map(where => this[_transformer](where, option)).map(where => {
2668
- return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2669
- ${Object.entries(where).map(([K, V]) => {
2677
+ return `SELECT ${columns}
2678
+ FROM ${tableNameESC} a
2679
+ WHERE ${Object.entries(where).map(([K, V]) => {
2670
2680
  params.push(V);
2671
2681
  return `${this[_fields][K]?.C2()} = ?`;
2672
2682
  }).join(' AND ')}`;
@@ -2677,10 +2687,21 @@ export class SqlService {
2677
2687
  else {
2678
2688
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2679
2689
  const delWhere = Object.keys(wheres[0]);
2680
- const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: delWhere, data: wheres, index: 'all', id: 'none' });
2690
+ const _sqls = this._createTable({
2691
+ tableName: tableTemp,
2692
+ temp: true,
2693
+ columns: delWhere,
2694
+ data: wheres,
2695
+ index: 'all',
2696
+ id: 'none'
2697
+ });
2681
2698
  sqls.push(..._sqls);
2682
2699
  resultIndex = sqls.length;
2683
- sqls.push({ sql: formatDialect(`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 ')};`, { dialect: formatDialects[option.dbType] }) });
2700
+ sqls.push({
2701
+ sql: formatDialect(`SELECT ${columns}
2702
+ FROM ${tableNameESC} a
2703
+ INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields][K]?.C2()} = b.${this[_fields][K]?.C2()}`).join(' AND ')};`, { dialect: formatDialects[option.dbType] })
2704
+ });
2684
2705
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2685
2706
  }
2686
2707
  if (option.sync === SyncMode.Sync) {
@@ -2715,10 +2736,17 @@ export class SqlService {
2715
2736
  });
2716
2737
  }
2717
2738
  }
2718
- _select(templateResult, result, def, errorMsg, hump, mapper, mapperIfUndefined) {
2739
+ _select(templateResult, result, def, errorMsg, hump, mapper, mapperIfUndefined, dataConvert) {
2719
2740
  switch (templateResult) {
2720
2741
  case SelectResult.R_C_NotSure: {
2721
2742
  try {
2743
+ if (dataConvert) {
2744
+ const key = Object.keys(result[0])[0];
2745
+ const value = Object.values(result[0])[0];
2746
+ if (key && dataConvert[key] && globalThis[_dataConvert][dataConvert[key]]) {
2747
+ return globalThis[_dataConvert][dataConvert[key]](value);
2748
+ }
2749
+ }
2722
2750
  return Object.values(result[0])[0];
2723
2751
  }
2724
2752
  catch (error) {
@@ -2727,6 +2755,13 @@ export class SqlService {
2727
2755
  }
2728
2756
  case SelectResult.R_C_Assert: {
2729
2757
  try {
2758
+ if (dataConvert) {
2759
+ const key = Object.keys(result[0])[0];
2760
+ const value = Object.values(result[0])[0];
2761
+ if (key && dataConvert[key] && globalThis[_dataConvert][dataConvert[key]]) {
2762
+ return globalThis[_dataConvert][dataConvert[key]](value);
2763
+ }
2764
+ }
2730
2765
  return Object.values(result[0])[0];
2731
2766
  }
2732
2767
  catch (error) {
@@ -2739,11 +2774,15 @@ export class SqlService {
2739
2774
  if (mapper) {
2740
2775
  return flatData({ data: result[0], mapper, mapperIfUndefined });
2741
2776
  }
2742
- else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
2743
- return C2P2(result[0]) ?? null;
2744
- }
2745
2777
  else {
2746
- return result[0] ?? null;
2778
+ hump = hump === true || (hump === undefined && globalThis[_Hump] === true);
2779
+ const _dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map((k, v) => [k, globalThis[_dataConvert][v]])) : undefined;
2780
+ if (hump || _dataConvert) {
2781
+ return C2P2(result[0], hump, _dataConvert) ?? null;
2782
+ }
2783
+ else {
2784
+ return result[0] ?? null;
2785
+ }
2747
2786
  }
2748
2787
  }
2749
2788
  case SelectResult.R_CS_Assert: {
@@ -2752,15 +2791,25 @@ export class SqlService {
2752
2791
  if (mapper) {
2753
2792
  return flatData({ data, mapper, mapperIfUndefined });
2754
2793
  }
2755
- else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
2756
- return C2P2(data) ?? null;
2757
- }
2758
2794
  else {
2759
- return data ?? null;
2795
+ hump = hump === true || (hump === undefined && globalThis[_Hump] === true);
2796
+ const _dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map((k, v) => [k, globalThis[_dataConvert][v]])) : undefined;
2797
+ if (hump || _dataConvert) {
2798
+ return C2P2(data, hump, _dataConvert) ?? null;
2799
+ }
2800
+ else {
2801
+ return data;
2802
+ }
2760
2803
  }
2761
2804
  }
2762
2805
  case SelectResult.RS_C: {
2763
2806
  try {
2807
+ if (dataConvert) {
2808
+ const key = Object.keys(result[0])[0];
2809
+ if (key && dataConvert[key] && globalThis[_dataConvert][dataConvert[key]]) {
2810
+ return result.map((r) => globalThis[_dataConvert][dataConvert[key]](Object.values(r)[0]));
2811
+ }
2812
+ }
2764
2813
  return result.map((r) => Object.values(r)[0]);
2765
2814
  }
2766
2815
  catch (error) {
@@ -2771,15 +2820,25 @@ export class SqlService {
2771
2820
  if (mapper) {
2772
2821
  return iterate(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray();
2773
2822
  }
2774
- else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
2775
- return iterate(result).map((r) => C2P2(r)).toArray();
2776
- }
2777
2823
  else {
2778
- return result;
2824
+ hump = hump === true || (hump === undefined && globalThis[_Hump] === true);
2825
+ const _dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map((k, v) => [k, globalThis[_dataConvert][v]])) : undefined;
2826
+ if (hump || _dataConvert) {
2827
+ return iterate(result).map((r) => C2P2(r, hump, _dataConvert)).toArray();
2828
+ }
2829
+ else {
2830
+ return result;
2831
+ }
2779
2832
  }
2780
2833
  }
2781
2834
  case SelectResult.RS_C_List: {
2782
2835
  try {
2836
+ if (dataConvert) {
2837
+ const key = Object.keys(result[0])[0];
2838
+ if (key && dataConvert[key] && globalThis[_dataConvert][dataConvert[key]]) {
2839
+ return new ArrayList(result.map((r) => globalThis[_dataConvert][dataConvert[key]](Object.values(r)[0])));
2840
+ }
2841
+ }
2783
2842
  return new ArrayList(result.map((r) => Object.values(r)[0]));
2784
2843
  }
2785
2844
  catch (error) {
@@ -2788,13 +2847,21 @@ export class SqlService {
2788
2847
  }
2789
2848
  case SelectResult.RS_CS_List: {
2790
2849
  if (mapper) {
2791
- return new ArrayList(iterate(result).map((data) => flatData({ data, mapper, mapperIfUndefined })).toArray());
2792
- }
2793
- else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
2794
- return new ArrayList(iterate(result).map((r) => C2P2(r)).toArray());
2850
+ return new ArrayList(iterate(result).map((data) => flatData({
2851
+ data,
2852
+ mapper,
2853
+ mapperIfUndefined
2854
+ })).toArray());
2795
2855
  }
2796
2856
  else {
2797
- return new ArrayList();
2857
+ hump = hump === true || (hump === undefined && globalThis[_Hump] === true);
2858
+ const _dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map((k, v) => [k, globalThis[_dataConvert][v]])) : undefined;
2859
+ if (hump || _dataConvert) {
2860
+ return new ArrayList(iterate(result).map((r) => C2P2(r, hump, _dataConvert)).toArray());
2861
+ }
2862
+ else {
2863
+ return new ArrayList();
2864
+ }
2798
2865
  }
2799
2866
  }
2800
2867
  }
@@ -2807,17 +2874,20 @@ export class SqlService {
2807
2874
  option.mapper = globalThis[_resultMap_SQLID][option.sqlId];
2808
2875
  }
2809
2876
  const _params = Object.assign({}, option.context, option.params);
2810
- option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: option.isCount, ..._params }));
2877
+ option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2878
+ ctx: option.context,
2879
+ isCount: option.isCount, ..._params
2880
+ }));
2811
2881
  const { sql, params } = this._generSql(option.dbType, option.sql, _params);
2812
2882
  if (option.sync === SyncMode.Sync) {
2813
2883
  const result = option.conn.query(SyncMode.Sync, sql, params);
2814
- return this._select(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined);
2884
+ return this._select(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined, option.dataConvert);
2815
2885
  }
2816
2886
  else {
2817
2887
  return new Promise(async (resolve, reject) => {
2818
2888
  try {
2819
2889
  const result = await option.conn.query(SyncMode.Async, sql, params);
2820
- resolve(this._select(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined));
2890
+ resolve(this._select(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined, option.dataConvert));
2821
2891
  }
2822
2892
  catch (error) {
2823
2893
  reject(error);
@@ -2883,11 +2953,18 @@ export class SqlService {
2883
2953
  sortName: option.sortName ?? undefined,
2884
2954
  sortType: option.sortType ?? undefined
2885
2955
  });
2886
- let sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, ...option.params });
2956
+ let sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2957
+ ctx: option.context,
2958
+ isCount: false, ...option.params
2959
+ });
2887
2960
  let sqlSum = '';
2888
2961
  let sqlCount = '';
2889
2962
  if (option.sumSelf === true) {
2890
- sqlSum = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, isSum: true, ...option.params });
2963
+ sqlSum = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2964
+ ctx: option.context,
2965
+ isCount: false,
2966
+ isSum: true, ...option.params
2967
+ });
2891
2968
  }
2892
2969
  if (option.limitSelf !== true) {
2893
2970
  if (option.countSelf !== true) {
@@ -2898,10 +2975,18 @@ export class SqlService {
2898
2975
  }
2899
2976
  if (option.pageSize > 0) {
2900
2977
  if (option.countSelf === true) {
2901
- sqlCount = globalThis[_sqlCache].load(this._matchSqlid(`${option.sqlId}_count`), { ctx: option.context, isCount: true, isSum: false, ...option.params });
2978
+ sqlCount = globalThis[_sqlCache].load(this._matchSqlid(`${option.sqlId}_count`), {
2979
+ ctx: option.context,
2980
+ isCount: true,
2981
+ isSum: false, ...option.params
2982
+ });
2902
2983
  }
2903
2984
  else {
2904
- sqlCount = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: true, isSum: false, ...option.params });
2985
+ sqlCount = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2986
+ ctx: option.context,
2987
+ isCount: true,
2988
+ isSum: false, ...option.params
2989
+ });
2905
2990
  }
2906
2991
  }
2907
2992
  if (option.sync === SyncMode.Sync) {
@@ -3024,6 +3109,7 @@ export class SqlService {
3024
3109
  }
3025
3110
  const lastVersion = this[_sqlite_version] ?? '0.0.1';
3026
3111
  // 检查表
3112
+ // language=SQL format=false
3027
3113
  const tableCheckResult = option.conn.pluck(SyncMode.Sync, `SELECT COUNT(1) t FROM sqlite_master WHERE TYPE = 'table' AND name = ?`, [option.tableName]);
3028
3114
  if (tableCheckResult) {
3029
3115
  // 旧版本
@@ -3038,7 +3124,8 @@ export class SqlService {
3038
3124
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${rtable};`);
3039
3125
  option.conn.execute(SyncMode.Sync, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3040
3126
  option.conn.execute(SyncMode.Sync, `
3041
- CREATE TABLE IF NOT EXISTS ${tableES}(
3127
+ CREATE TABLE IF NOT EXISTS ${tableES}
3128
+ (
3042
3129
  ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3043
3130
  ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3044
3131
  );
@@ -3048,8 +3135,12 @@ export class SqlService {
3048
3135
  option.conn.execute(SyncMode.Sync, `CREATE INDEX ${`${index}_${Math.random()}`.replace(/\./, '')} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
3049
3136
  }
3050
3137
  }
3051
- option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3052
- option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3138
+ option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns})
3139
+ SELECT ${columns}
3140
+ FROM ${rtable};`);
3141
+ option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns})
3142
+ SELECT ${columns}
3143
+ FROM ${rtable};`);
3053
3144
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${rtable};`);
3054
3145
  // 更新完毕,保存版本号
3055
3146
  option.conn.execute(SyncMode.Sync, 'UPDATE TABLE_VERSION SET ______version = ? WHERE ______tableName = ?', [option.tableName, lastVersion]);
@@ -3061,10 +3152,11 @@ export class SqlService {
3061
3152
  else { // 表不存在
3062
3153
  // 创建表
3063
3154
  option.conn.execute(SyncMode.Sync, `
3064
- CREATE TABLE IF NOT EXISTS ${tableES} (
3155
+ CREATE TABLE IF NOT EXISTS ${tableES}
3156
+ (
3065
3157
  ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3066
3158
  ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3067
-
3159
+
3068
3160
  );
3069
3161
  `);
3070
3162
  if (this[_index] && this[_index].length) {
@@ -3083,7 +3175,10 @@ export class SqlService {
3083
3175
  }
3084
3176
  const lastVersion = this[_sqlite_version] ?? '0.0.1';
3085
3177
  // 检查表
3086
- const tableCheckResult = await option.conn.pluck(SyncMode.Async, `SELECT COUNT(1) t FROM sqlite_master WHERE TYPE = 'table' AND name = ?`, [option.tableName]);
3178
+ const tableCheckResult = await option.conn.pluck(SyncMode.Async, `SELECT COUNT(1) t
3179
+ FROM sqlite_master
3180
+ WHERE TYPE = 'table'
3181
+ AND name = ?`, [option.tableName]);
3087
3182
  if (tableCheckResult) {
3088
3183
  // 旧版本
3089
3184
  const tableVersion = await option.conn.pluck(SyncMode.Async, 'SELECT ______version v from TABLE_VERSION WHERE ______tableName = ?', [option.tableName]);
@@ -3097,18 +3192,23 @@ export class SqlService {
3097
3192
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${rtable};`);
3098
3193
  await option.conn.execute(SyncMode.Async, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3099
3194
  await option.conn.execute(SyncMode.Async, `
3100
- CREATE TABLE IF NOT EXISTS ${tableES}(
3101
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3102
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3103
- );
3104
- `);
3195
+ CREATE TABLE IF NOT EXISTS ${tableES}
3196
+ (
3197
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3198
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3199
+ );
3200
+ `);
3105
3201
  if (this[_index] && this[_index].length) {
3106
3202
  for (const index of this[_index]) {
3107
3203
  await option.conn.execute(SyncMode.Async, `CREATE INDEX ${`${index}_${Math.random()}`.replace(/\./, '')} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
3108
3204
  }
3109
3205
  }
3110
- await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3111
- await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3206
+ await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns})
3207
+ SELECT ${columns}
3208
+ FROM ${rtable};`);
3209
+ await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns})
3210
+ SELECT ${columns}
3211
+ FROM ${rtable};`);
3112
3212
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${rtable};`);
3113
3213
  // 更新完毕,保存版本号
3114
3214
  await option.conn.execute(SyncMode.Async, 'UPDATE TABLE_VERSION SET ______version = ? WHERE ______tableName = ?', [option.tableName, lastVersion]);
@@ -3120,11 +3220,12 @@ export class SqlService {
3120
3220
  else { // 表不存在
3121
3221
  // 创建表
3122
3222
  await option.conn.execute(SyncMode.Async, `
3123
- CREATE TABLE IF NOT EXISTS ${tableES}(
3124
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3125
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3126
- );
3127
- `);
3223
+ CREATE TABLE IF NOT EXISTS ${tableES}
3224
+ (
3225
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3226
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3227
+ );
3228
+ `);
3128
3229
  if (this[_index] && this[_index].length) {
3129
3230
  for (const index of this[_index]) {
3130
3231
  await option.conn.execute(SyncMode.Async, `CREATE INDEX ${`${index}_${Math.random()}`.replace(/\./, '')} ON ${option.tableName} ("${this[_fields][index]?.C2()}");`);
@@ -3150,16 +3251,16 @@ export class SqlService {
3150
3251
  }
3151
3252
  }
3152
3253
  /**
3153
- #创建表
3154
- ** `tableName` 表名称
3155
- ** `temp` 是否是临时表,默认true
3156
- ** `columns` 字符串数组,默认是当前实体类全部字段,通过`columns` 可以创建部分字段临时表
3157
- ** `id` 表的主键设置 4种:
3158
- 1. `auto`: `columns`中已经在当前实体类配置的ID作为主键 `默认`
3159
- 2. `all`: `columns`中所有字段全部当主键
3160
- 3. `none`: 没有主键
3161
- 4. 自定义字段名称:字符串数组
3162
- ** `index` 表的索引,设置方式同ID
3254
+ #创建表
3255
+ ** `tableName` 表名称
3256
+ ** `temp` 是否是临时表,默认true
3257
+ ** `columns` 字符串数组,默认是当前实体类全部字段,通过`columns` 可以创建部分字段临时表
3258
+ ** `id` 表的主键设置 4种:
3259
+ 1. `auto`: `columns`中已经在当前实体类配置的ID作为主键 `默认`
3260
+ 2. `all`: `columns`中所有字段全部当主键
3261
+ 3. `none`: 没有主键
3262
+ 4. 自定义字段名称:字符串数组
3263
+ ** `index` 表的索引,设置方式同ID
3163
3264
  */
3164
3265
  _createTable({ tableName, temp = true, columns, data, id = 'auto', index = 'auto', dbType } = {}) {
3165
3266
  const sqls = [];
@@ -3193,17 +3294,23 @@ export class SqlService {
3193
3294
  tableName = tableName ?? this[_tableName];
3194
3295
  switch (dbType) {
3195
3296
  case DBType.Mysql: {
3196
- let sql = formatDialect(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3197
- ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3198
- ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3199
- ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3200
- ) ENGINE=MEMORY;`, { dialect: mysql });
3297
+ let sql = formatDialect(`CREATE
3298
+ ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS
3299
+ ${tableName}
3300
+ (
3301
+ ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3302
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3303
+ ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3304
+ )
3305
+ ENGINE
3306
+ =
3307
+ MEMORY;`, { dialect: mysql });
3201
3308
  sqls.push({ sql });
3202
3309
  if (data && data.length > 0) {
3203
3310
  const params = [];
3204
3311
  let first = true;
3205
3312
  sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3206
- ${(data).map(d => {
3313
+ ${(data).map(d => {
3207
3314
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3208
3315
  params.push(V);
3209
3316
  return `? ${first ? this[_fields][K]?.C2() : ''}`;
@@ -3217,9 +3324,12 @@ export class SqlService {
3217
3324
  }
3218
3325
  case DBType.Sqlite:
3219
3326
  case DBType.SqliteRemote: {
3220
- let sql = formatDialect(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3221
- ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3222
- ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3327
+ let sql = formatDialect(`CREATE
3328
+ ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS
3329
+ ${tableName}
3330
+ (
3331
+ ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3332
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3223
3333
  );`, { dialect: sqlite });
3224
3334
  sqls.push({ sql });
3225
3335
  if (indexs) {
@@ -3232,7 +3342,7 @@ export class SqlService {
3232
3342
  const params = [];
3233
3343
  let first = true;
3234
3344
  sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3235
- ${(data).map(d => {
3345
+ ${(data).map(d => {
3236
3346
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3237
3347
  params.push(V);
3238
3348
  return `? ${first ? this[_fields][K]?.C2() : ''}`;
@@ -3266,7 +3376,7 @@ export class SqlService {
3266
3376
  }
3267
3377
  _generSql(dbType, _sql, _params) {
3268
3378
  const params = [];
3269
- const sql = formatDialect(_sql?.replace(/\:(\w+)/g, (txt, key) => {
3379
+ const sql = formatDialect(_sql?.replace(/:(\w+)/g, (txt, key) => {
3270
3380
  let V = LGet(_params, key);
3271
3381
  if (V !== undefined) {
3272
3382
  return this._setParam(V, params);
@@ -3351,7 +3461,7 @@ const IF_PROCEED = function () {
3351
3461
  return function (_target, _propertyKey, descriptor) {
3352
3462
  const fn = descriptor.value;
3353
3463
  descriptor.value = function () {
3354
- if (this.if_proceed === true) {
3464
+ if (this.if_proceed) {
3355
3465
  // eslint-disable-next-line prefer-rest-params
3356
3466
  const args = Array.from(arguments);
3357
3467
  fn.call(this, ...args);
@@ -3368,7 +3478,7 @@ const IF_EXEC = function (def) {
3368
3478
  return function (_target, _propertyKey, descriptor) {
3369
3479
  const fn = descriptor.value;
3370
3480
  descriptor.value = async function () {
3371
- if (this.if_proceed === true && this.if_exec === true) {
3481
+ if (this.if_proceed && this.if_exec) {
3372
3482
  // eslint-disable-next-line prefer-rest-params
3373
3483
  const args = Array.from(arguments);
3374
3484
  return await fn.call(this, ...args);
@@ -3425,10 +3535,16 @@ class StreamQuery {
3425
3535
  /**
3426
3536
  * AND(key1 = :value OR key2 = :value)
3427
3537
  * @param keys [key1, key2, ...]
3538
+ * @param keys
3539
+ * @param value
3428
3540
  */
3429
- eqs(keys, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this.__(keys, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3541
+ eqs(keys, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3542
+ return this.__(keys, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip });
3543
+ }
3430
3544
  /*** AND key = :value */
3431
- eq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3545
+ eq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3546
+ return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip });
3547
+ }
3432
3548
  /*** AND key1 = :value1 AND key2 = :value2 */
3433
3549
  eqT(t, { name: paramName = '', breakExcuteIfSkip = false } = {}) {
3434
3550
  let exe = false;
@@ -3462,113 +3578,272 @@ class StreamQuery {
3462
3578
  exe = true;
3463
3579
  }
3464
3580
  }
3465
- if (breakExcuteIfSkip === true && exe === false) {
3581
+ if (breakExcuteIfSkip && !exe) {
3466
3582
  this.if_exec = false;
3467
3583
  }
3468
3584
  return this;
3469
3585
  }
3470
3586
  /*** AND key <> :value */
3471
- notEq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '<>', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3587
+ notEq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3588
+ return this._(key, value, '<>', { paramName, skipEmptyString, breakExcuteIfSkip });
3589
+ }
3472
3590
  /** AND key1 = key2 */
3473
- eqWith(key1, key2) { return this._key(key1, key2, '='); }
3591
+ eqWith(key1, key2) {
3592
+ return this._key(key1, key2, '=');
3593
+ }
3474
3594
  /** AND key1 <> key2 */
3475
- notEqWith(key1, key2) { return this._key(key1, key2, '<>'); }
3595
+ notEqWith(key1, key2) {
3596
+ return this._key(key1, key2, '<>');
3597
+ }
3476
3598
  /** AND key REGEXP :regexp */
3477
- regexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3599
+ regexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) {
3600
+ return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3601
+ }
3478
3602
  /** AND key NOT REGEXP :regexp */
3479
- notRegexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, not: 'NOT', breakExcuteIfSkip }); }
3603
+ notRegexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) {
3604
+ return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, not: 'NOT', breakExcuteIfSkip });
3605
+ }
3480
3606
  /** AND (key1 << 8) + key2 = value */
3481
- shiftEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '=', { paramName, breakExcuteIfSkip }); }
3607
+ shiftEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3608
+ return this._shift(key1, key2, value, '=', { paramName, breakExcuteIfSkip });
3609
+ }
3482
3610
  /** AND (key1 << 8) + key2 <> value */
3483
- shiftNotEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '<>', { paramName, breakExcuteIfSkip }); }
3611
+ shiftNotEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3612
+ return this._shift(key1, key2, value, '<>', { paramName, breakExcuteIfSkip });
3613
+ }
3484
3614
  /** AND key > :value */
3485
- grate(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3615
+ grate(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3616
+ return this._(key, value, '>', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3617
+ }
3486
3618
  /** AND key >= :value */
3487
- grateEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3619
+ grateEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3620
+ return this._(key, value, '>=', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3621
+ }
3488
3622
  /** AND key1 > key2 */
3489
- grateWith(key1, key2) { return this._key(key1, key2, '>'); }
3623
+ grateWith(key1, key2) {
3624
+ return this._key(key1, key2, '>');
3625
+ }
3490
3626
  /** AND key1 >= key2 */
3491
- grateEqWith(key1, key2) { return this._key(key1, key2, '>='); }
3627
+ grateEqWith(key1, key2) {
3628
+ return this._key(key1, key2, '>=');
3629
+ }
3492
3630
  /** AND key < :value */
3493
- less(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3631
+ less(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3632
+ return this._(key, value, '<', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3633
+ }
3494
3634
  /** AND key <= :value */
3495
- lessEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3635
+ lessEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3636
+ return this._(key, value, '<=', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3637
+ }
3496
3638
  /** AND key1 < key2 */
3497
- lessWith(key1, key2) { return this._key(key1, key2, '<'); }
3639
+ lessWith(key1, key2) {
3640
+ return this._key(key1, key2, '<');
3641
+ }
3498
3642
  /** AND key1 <= key2 */
3499
- lessEqWith(key1, key2) { return this._key(key1, key2, '<='); }
3643
+ lessEqWith(key1, key2) {
3644
+ return this._key(key1, key2, '<=');
3645
+ }
3500
3646
  /** AND key LIKE CONCAT('%', :value, '%') */
3501
- like(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip }); }
3647
+ like(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3648
+ return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip });
3649
+ }
3502
3650
  /** AND key NOT LIKE CONCAT('%', :value, '%') */
3503
- notLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip }); }
3651
+ notLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3652
+ return this._like(key, value, {
3653
+ paramName,
3654
+ skipEmptyString,
3655
+ left: '%',
3656
+ right: '%',
3657
+ not: 'NOT',
3658
+ breakExcuteIfSkip
3659
+ });
3660
+ }
3504
3661
  /** AND key NOT LIKE CONCAT('%', :value) */
3505
- leftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip }); }
3662
+ leftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3663
+ return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip });
3664
+ }
3506
3665
  /** AND key LIKE CONCAT('%', :value) */
3507
- notLeftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip }); }
3666
+ notLeftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3667
+ return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip });
3668
+ }
3508
3669
  /** AND key LIKE CONCAT(:value, '%') */
3509
- rightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip }); }
3670
+ rightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3671
+ return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip });
3672
+ }
3510
3673
  /** AND key NOT LIKE CONCAT(:value, '%') */
3511
- notRightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip }); }
3674
+ notRightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3675
+ return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip });
3676
+ }
3512
3677
  /** AND key NOT LIKE :value */
3513
- PreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3678
+ PreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3679
+ return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip });
3680
+ }
3514
3681
  /** AND key LIKE :value */
3515
- notPreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3682
+ notPreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3683
+ return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3684
+ }
3516
3685
  /** AND key GLOB CONCAT('%', :value, '%') */
3517
- glob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3686
+ glob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3687
+ return this._like(key, value, {
3688
+ paramName,
3689
+ skipEmptyString,
3690
+ left: '%',
3691
+ right: '%',
3692
+ breakExcuteIfSkip,
3693
+ op: 'GLOB'
3694
+ });
3695
+ }
3518
3696
  /** AND key NOT GLOB CONCAT('%', :value, '%') */
3519
- notGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3697
+ notGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3698
+ return this._like(key, value, {
3699
+ paramName,
3700
+ skipEmptyString,
3701
+ left: '%',
3702
+ right: '%',
3703
+ not: 'NOT',
3704
+ breakExcuteIfSkip,
3705
+ op: 'GLOB'
3706
+ });
3707
+ }
3520
3708
  /** AND key GLOB CONCAT('%', :value) */
3521
- leftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3709
+ leftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3710
+ return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip, op: 'GLOB' });
3711
+ }
3522
3712
  /** AND key NOT GLOB CONCAT('%', :value) */
3523
- notLeftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3713
+ notLeftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3714
+ return this._like(key, value, {
3715
+ paramName,
3716
+ skipEmptyString,
3717
+ left: '%',
3718
+ not: 'NOT',
3719
+ breakExcuteIfSkip,
3720
+ op: 'GLOB'
3721
+ });
3722
+ }
3524
3723
  /** AND key GLOB CONCAT(:value, '%') */
3525
- rightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3724
+ rightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3725
+ return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip, op: 'GLOB' });
3726
+ }
3526
3727
  /** AND key NOT GLOB CONCAT(:value, '%') */
3527
- notRightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3728
+ notRightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3729
+ return this._like(key, value, {
3730
+ paramName,
3731
+ skipEmptyString,
3732
+ right: '%',
3733
+ not: 'NOT',
3734
+ breakExcuteIfSkip,
3735
+ op: 'GLOB'
3736
+ });
3737
+ }
3528
3738
  /** AND key GLOB :value */
3529
- PreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip, op: 'GLOB' }); }
3739
+ PreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3740
+ return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip, op: 'GLOB' });
3741
+ }
3530
3742
  /** AND key NOT GLOB :value */
3531
- notPreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3743
+ notPreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3744
+ return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip, op: 'GLOB' });
3745
+ }
3532
3746
  /** AND key IN :value */
3533
- in(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, breakExcuteIfSkip }); }
3747
+ in(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3748
+ return this._in(key, value, { paramName, breakExcuteIfSkip });
3749
+ }
3534
3750
  /** AND key NOT IN :value */
3535
- notIn(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3751
+ notIn(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3752
+ return this._in(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3753
+ }
3536
3754
  /** AND :value IN (key1, key2, ...) */
3537
- in2(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._in2(key, value, { paramName, breakExcuteIfSkip }); }
3755
+ in2(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3756
+ return this._in2(key, value, { paramName, breakExcuteIfSkip });
3757
+ }
3538
3758
  /** AND :value NOT IN (key1, key2, ...) */
3539
- notIn2(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._in2(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3759
+ notIn2(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3760
+ return this._in2(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3761
+ }
3540
3762
  /** AND key IS NULL */
3541
- isNULL(key) { return this._null(key); }
3763
+ isNULL(key) {
3764
+ return this._null(key);
3765
+ }
3542
3766
  /** AND key IS NOT NULL */
3543
- isNotNULL(key) { return this._null(key, 'NOT'); }
3767
+ isNotNULL(key) {
3768
+ return this._null(key, 'NOT');
3769
+ }
3544
3770
  /** AND key BETWEEN :value1 AND :value2 */
3545
- between(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3771
+ between(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3772
+ return this._between(key, value1, value2, { paramName, skipEmptyString, breakExcuteIfSkip });
3773
+ }
3546
3774
  /** AND key NOT BETWEEN :value1 AND :value2 */
3547
- notBetween(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3775
+ notBetween(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3776
+ return this._between(key, value1, value2, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3777
+ }
3548
3778
  /** AND POW(2, key) & :value */
3549
- pow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, breakExcuteIfSkip }); }
3779
+ pow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3780
+ return this._pow(key, value, { paramName, breakExcuteIfSkip });
3781
+ }
3550
3782
  /** AND NOT POW(2, key) & :value */
3551
- notPow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, not: 'NOT', breakExcuteIfSkip }); }
3783
+ notPow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3784
+ return this._pow(key, value, { paramName, not: 'NOT', breakExcuteIfSkip });
3785
+ }
3552
3786
  /** AND POW(2, key1) & key2 */
3553
- powWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, breakExcuteIfSkip }); }
3787
+ powWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) {
3788
+ return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, breakExcuteIfSkip });
3789
+ }
3554
3790
  /** AND NOT POW(2, key1) & key2 */
3555
- notPowWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, not: 'NOT', breakExcuteIfSkip }); }
3791
+ notPowWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) {
3792
+ return this._pow(key, add(...values.map(value => Math.pow(2, +value))), {
3793
+ paramName,
3794
+ not: 'NOT',
3795
+ breakExcuteIfSkip
3796
+ });
3797
+ }
3556
3798
  /** AND MATCH(key1, key2, key3) AGAINST (:value) */
3557
- match(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3799
+ match(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3800
+ return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip });
3801
+ }
3558
3802
  /** AND NOT MATCH(key1, key2, key3) AGAINST (:value) */
3559
- notMatch(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3803
+ notMatch(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3804
+ return this._match(value, keys, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3805
+ }
3560
3806
  /** AND MATCH(key1, key2, key3) AGAINST (:value) IN BOOLEAN MODE*/
3561
- matchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'IN BOOLEAN MODE' }); }
3807
+ matchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3808
+ return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'IN BOOLEAN MODE' });
3809
+ }
3562
3810
  /** AND NOT MATCH(key1, key2, key3) AGAINST (:value) IN BOOLEAN MODE */
3563
- notMatchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'IN BOOLEAN MODE' }); }
3811
+ notMatchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3812
+ return this._match(value, keys, {
3813
+ paramName,
3814
+ skipEmptyString,
3815
+ breakExcuteIfSkip,
3816
+ not: 'NOT',
3817
+ append: 'IN BOOLEAN MODE'
3818
+ });
3819
+ }
3564
3820
  /** AND MATCH(key1, key2, key3) AGAINST (:value) WITH QUERY EXPANSION*/
3565
- matchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'WITH QUERY EXPANSION' }); }
3821
+ matchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3822
+ return this._match(value, keys, {
3823
+ paramName,
3824
+ skipEmptyString,
3825
+ breakExcuteIfSkip,
3826
+ append: 'WITH QUERY EXPANSION'
3827
+ });
3828
+ }
3566
3829
  /** AND NOT MATCH(key1, key2, key3) AGAINST (:value) WITH QUERY EXPANSION*/
3567
- notMatchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'WITH QUERY EXPANSION' }); }
3830
+ notMatchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3831
+ return this._match(value, keys, {
3832
+ paramName,
3833
+ skipEmptyString,
3834
+ breakExcuteIfSkip,
3835
+ not: 'NOT',
3836
+ append: 'WITH QUERY EXPANSION'
3837
+ });
3838
+ }
3568
3839
  /** AND NOT LOCATE(key, :value) > 0 */
3569
- includes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3840
+ includes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3841
+ return this._includes(key, value, { paramName, skipEmptyString, breakExcuteIfSkip });
3842
+ }
3570
3843
  /** AND NOT LOCATE(key, :value) = 0 */
3571
- notIncludes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3844
+ notIncludes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3845
+ return this._includes(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3846
+ }
3572
3847
  and(fn) {
3573
3848
  if (fn instanceof StreamQuery) {
3574
3849
  this._andQuerys.push(fn);
@@ -3604,29 +3879,76 @@ class StreamQuery {
3604
3879
  return this;
3605
3880
  }
3606
3881
  /** GROUP BY key1, key2, ... */
3607
- groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3882
+ groupBy(...keys) {
3883
+ this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`));
3884
+ return this;
3885
+ }
3608
3886
  /** GROUP BY key1, key2, ... */
3609
- groupBy2(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3887
+ groupBy2(...keys) {
3888
+ this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`));
3889
+ return this;
3890
+ }
3610
3891
  /** ORDER BY key1 ASC, key2 ASC, ... */
3611
- asc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3892
+ asc(...keys) {
3893
+ this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`));
3894
+ return this;
3895
+ }
3612
3896
  /** ORDER BY key1 ASC, key2 ASC, ... */
3613
- asc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3897
+ asc2(...keys) {
3898
+ this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`));
3899
+ return this;
3900
+ }
3614
3901
  /** ORDER BY key1 DESC, key2 DESC, ... */
3615
- desc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`)); return this; }
3902
+ desc(...keys) {
3903
+ this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`));
3904
+ return this;
3905
+ }
3616
3906
  /** ORDER BY key1 DESC, key2 DESC, ... */
3617
- desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3907
+ desc2(...keys) {
3908
+ this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`));
3909
+ return this;
3910
+ }
3618
3911
  /** LIMIT :startRow, :pageSize */
3619
- limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
3912
+ limit(startRow, pageSize) {
3913
+ this._startRow = startRow;
3914
+ this._pageSize = pageSize;
3915
+ return this;
3916
+ }
3620
3917
  /** LIMIT ((:pageNumber || 1) - 1) * :pageSize, :pageSize */
3621
- page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
3622
- distinct(on = true) { this._distinct = on; return this; }
3918
+ page(pageNumber, pageSize) {
3919
+ this._startRow = ((pageNumber || 1) - 1) * pageSize;
3920
+ this._pageSize = pageSize;
3921
+ return this;
3922
+ }
3923
+ distinct(on = true) {
3924
+ this._distinct = on;
3925
+ return this;
3926
+ }
3623
3927
  /** COUNT(DISTINCT key) */
3624
- countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3625
- count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
3626
- sum(key, legName, distinct) { this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3627
- avg(key, legName, distinct) { this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3628
- max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3629
- min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3928
+ countDistinct(key, countName) {
3929
+ this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`);
3930
+ return this;
3931
+ }
3932
+ count(countName) {
3933
+ this._columns.push(`COUNT(1) ${countName ?? 'ct'}`);
3934
+ return this;
3935
+ }
3936
+ sum(key, legName, distinct) {
3937
+ this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`);
3938
+ return this;
3939
+ }
3940
+ avg(key, legName, distinct) {
3941
+ this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`);
3942
+ return this;
3943
+ }
3944
+ max(key, legName, distinct) {
3945
+ this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`);
3946
+ return this;
3947
+ }
3948
+ min(key, legName, distinct) {
3949
+ this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`);
3950
+ return this;
3951
+ }
3630
3952
  /** GROUP_CONCAT([DISTINCT] key [ORDER BY :asc ASC] [ORDER BY :asc DESC] [SEPARATOR :separator]) */
3631
3953
  groupConcat(key, param) {
3632
3954
  this._columns.push(`GROUP_CONCAT(
@@ -3637,10 +3959,25 @@ class StreamQuery {
3637
3959
  ) ${param && param.groupName || `${this[_fields][String(key)]?.C2()}`}`);
3638
3960
  return this;
3639
3961
  }
3640
- select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
3641
- select2(sql, param) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
3642
- update(key, value) { this._updates ?? (this._updates = {}); this._updates[this[_fields][String(key)]?.C2()] = value; return this; }
3643
- update2(sql, param) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
3962
+ select(...key) {
3963
+ this._columns.push(...(key.map(k => this[_fields][String(k)].C3())));
3964
+ return this;
3965
+ }
3966
+ select2(sql, param) {
3967
+ this._columns.push(`${sql}`);
3968
+ Object.assign(this._param, param);
3969
+ return this;
3970
+ }
3971
+ update(key, value) {
3972
+ this._updates ?? (this._updates = {});
3973
+ this._updates[this[_fields][String(key)]?.C2()] = value;
3974
+ return this;
3975
+ }
3976
+ update2(sql, param) {
3977
+ this._updateColumns.push(sql);
3978
+ Object.assign(this._param, param);
3979
+ return this;
3980
+ }
3644
3981
  updateT(t) {
3645
3982
  this._updates ?? (this._updates = {});
3646
3983
  for (const [key, value] of Object.entries(t)) {
@@ -3649,6 +3986,7 @@ class StreamQuery {
3649
3986
  Object.assign(this._updates, t);
3650
3987
  return this;
3651
3988
  }
3989
+ /** SET key = REPLACE(key, :valueToFind, :valueToReplace) */
3652
3990
  replace(key, valueToFind, valueToReplace) {
3653
3991
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
3654
3992
  this._updateColumns.push(` ${this[_fields][String(key)]?.C2()} = REPLACE(${this[_fields][String(key)]?.C2()}, :${pkey1}, :${pkey2}) `);
@@ -3662,13 +4000,9 @@ class StreamQuery {
3662
4000
  option.selectResult ?? (option.selectResult = SelectResult.RS_CS);
3663
4001
  const { where, params } = this._where();
3664
4002
  let sql = `
3665
- SELECT
3666
- ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3667
- FROM ${option.tableName ?? this._service[_tableName]}
3668
- ${where ? ' WHERE ' : ''}
3669
- ${where}
3670
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3671
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
4003
+ SELECT ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
4004
+ FROM ${option.tableName ?? this._service[_tableName]} ${where ? ' WHERE ' : ''} ${where} ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
4005
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3672
4006
  `;
3673
4007
  if (this._startRow && this._pageSize) {
3674
4008
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3678,26 +4012,138 @@ class StreamQuery {
3678
4012
  }
3679
4013
  if (option.sync === SyncMode.Async) {
3680
4014
  switch (option.selectResult) {
3681
- case SelectResult.RS_CS: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS, sql, params });
3682
- case SelectResult.RS_C: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C, sql, params });
3683
- case SelectResult.RS_CS_List: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS_List, sql, params });
3684
- case SelectResult.RS_C_List: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C_List, sql, params });
3685
- case SelectResult.R_CS_Assert: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_Assert, sql, params });
3686
- case SelectResult.R_C_Assert: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_Assert, sql, params });
3687
- case SelectResult.R_CS_NotSure: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_NotSure, sql, params });
3688
- case SelectResult.R_C_NotSure: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_NotSure, sql, params });
4015
+ case SelectResult.RS_CS:
4016
+ return this._service.select({
4017
+ ...option,
4018
+ sync: SyncMode.Async,
4019
+ selectResult: SelectResult.RS_CS,
4020
+ sql,
4021
+ params
4022
+ });
4023
+ case SelectResult.RS_C:
4024
+ return this._service.select({
4025
+ ...option,
4026
+ sync: SyncMode.Async,
4027
+ selectResult: SelectResult.RS_C,
4028
+ sql,
4029
+ params
4030
+ });
4031
+ case SelectResult.RS_CS_List:
4032
+ return this._service.select({
4033
+ ...option,
4034
+ sync: SyncMode.Async,
4035
+ selectResult: SelectResult.RS_CS_List,
4036
+ sql,
4037
+ params
4038
+ });
4039
+ case SelectResult.RS_C_List:
4040
+ return this._service.select({
4041
+ ...option,
4042
+ sync: SyncMode.Async,
4043
+ selectResult: SelectResult.RS_C_List,
4044
+ sql,
4045
+ params
4046
+ });
4047
+ case SelectResult.R_CS_Assert:
4048
+ return this._service.select({
4049
+ ...option,
4050
+ sync: SyncMode.Async,
4051
+ selectResult: SelectResult.R_CS_Assert,
4052
+ sql,
4053
+ params
4054
+ });
4055
+ case SelectResult.R_C_Assert:
4056
+ return this._service.select({
4057
+ ...option,
4058
+ sync: SyncMode.Async,
4059
+ selectResult: SelectResult.R_C_Assert,
4060
+ sql,
4061
+ params
4062
+ });
4063
+ case SelectResult.R_CS_NotSure:
4064
+ return this._service.select({
4065
+ ...option,
4066
+ sync: SyncMode.Async,
4067
+ selectResult: SelectResult.R_CS_NotSure,
4068
+ sql,
4069
+ params
4070
+ });
4071
+ case SelectResult.R_C_NotSure:
4072
+ return this._service.select({
4073
+ ...option,
4074
+ sync: SyncMode.Async,
4075
+ selectResult: SelectResult.R_C_NotSure,
4076
+ sql,
4077
+ params
4078
+ });
3689
4079
  }
3690
4080
  }
3691
4081
  else {
3692
4082
  switch (option.selectResult) {
3693
- case SelectResult.RS_CS: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS, sql, params });
3694
- case SelectResult.RS_C: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C, sql, params });
3695
- case SelectResult.RS_CS_List: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS_List, sql, params });
3696
- case SelectResult.RS_C_List: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C_List, sql, params });
3697
- case SelectResult.R_CS_Assert: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_Assert, sql, params });
3698
- case SelectResult.R_C_Assert: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_Assert, sql, params });
3699
- case SelectResult.R_CS_NotSure: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_NotSure, sql, params });
3700
- case SelectResult.R_C_NotSure: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_NotSure, sql, params });
4083
+ case SelectResult.RS_CS:
4084
+ return this._service.select({
4085
+ ...option,
4086
+ sync: SyncMode.Sync,
4087
+ selectResult: SelectResult.RS_CS,
4088
+ sql,
4089
+ params
4090
+ });
4091
+ case SelectResult.RS_C:
4092
+ return this._service.select({
4093
+ ...option,
4094
+ sync: SyncMode.Sync,
4095
+ selectResult: SelectResult.RS_C,
4096
+ sql,
4097
+ params
4098
+ });
4099
+ case SelectResult.RS_CS_List:
4100
+ return this._service.select({
4101
+ ...option,
4102
+ sync: SyncMode.Sync,
4103
+ selectResult: SelectResult.RS_CS_List,
4104
+ sql,
4105
+ params
4106
+ });
4107
+ case SelectResult.RS_C_List:
4108
+ return this._service.select({
4109
+ ...option,
4110
+ sync: SyncMode.Sync,
4111
+ selectResult: SelectResult.RS_C_List,
4112
+ sql,
4113
+ params
4114
+ });
4115
+ case SelectResult.R_CS_Assert:
4116
+ return this._service.select({
4117
+ ...option,
4118
+ sync: SyncMode.Sync,
4119
+ selectResult: SelectResult.R_CS_Assert,
4120
+ sql,
4121
+ params
4122
+ });
4123
+ case SelectResult.R_C_Assert:
4124
+ return this._service.select({
4125
+ ...option,
4126
+ sync: SyncMode.Sync,
4127
+ selectResult: SelectResult.R_C_Assert,
4128
+ sql,
4129
+ params
4130
+ });
4131
+ case SelectResult.R_CS_NotSure:
4132
+ return this._service.select({
4133
+ ...option,
4134
+ sync: SyncMode.Sync,
4135
+ selectResult: SelectResult.R_CS_NotSure,
4136
+ sql,
4137
+ params
4138
+ });
4139
+ case SelectResult.R_C_NotSure:
4140
+ return this._service.select({
4141
+ ...option,
4142
+ sync: SyncMode.Sync,
4143
+ selectResult: SelectResult.R_C_NotSure,
4144
+ sql,
4145
+ params
4146
+ });
3701
4147
  }
3702
4148
  }
3703
4149
  }
@@ -3711,13 +4157,9 @@ class StreamQuery {
3711
4157
  total: 0
3712
4158
  };
3713
4159
  let sql = `
3714
- SELECT
3715
- ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3716
- FROM ${option.tableName ?? this._service[_tableName]}
3717
- ${where ? ' WHERE ' : ''}
3718
- ${where}
3719
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3720
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
4160
+ SELECT ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
4161
+ FROM ${option.tableName ?? this._service[_tableName]} ${where ? ' WHERE ' : ''} ${where} ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
4162
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3721
4163
  `;
3722
4164
  if (this._startRow && this._pageSize) {
3723
4165
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3727,11 +4169,8 @@ class StreamQuery {
3727
4169
  }
3728
4170
  const sqlCount = `
3729
4171
  SELECT COUNT(1)
3730
- FROM ${option.tableName ?? this._service[_tableName]}
3731
- ${where ? ' WHERE ' : ''}
3732
- ${where}
3733
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3734
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
4172
+ FROM ${option.tableName ?? this._service[_tableName]} ${where ? ' WHERE ' : ''} ${where} ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
4173
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3735
4174
  `;
3736
4175
  if (option.sync === SyncMode.Sync) {
3737
4176
  result.total = this._service.select({
@@ -3798,9 +4237,9 @@ class StreamQuery {
3798
4237
  }
3799
4238
  }
3800
4239
  if (sets.length > 0) {
3801
- const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
3802
- ${where ? ' WHERE ' : ''}
3803
- ${where}
4240
+ const sql = `UPDATE ${option.tableName ?? this._service[_tableName]}
4241
+ SET ${sets.join(',')}
4242
+ ${where ? ' WHERE ' : ''} ${where}
3804
4243
  `;
3805
4244
  if (option.sync === SyncMode.Async) {
3806
4245
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -3817,9 +4256,8 @@ class StreamQuery {
3817
4256
  option ?? (option = {});
3818
4257
  option.sync ?? (option.sync = SyncMode.Async);
3819
4258
  const { where, params } = this._where();
3820
- const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
3821
- ${where ? ' WHERE ' : ''}
3822
- ${where}
4259
+ const sql = `DELETE
4260
+ FROM ${option.tableName ?? this._service[_tableName]} ${where ? ' WHERE ' : ''} ${where}
3823
4261
  `;
3824
4262
  if (option.sync === SyncMode.Async) {
3825
4263
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -3857,8 +4295,8 @@ class StreamQuery {
3857
4295
  _(key, value, op, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3858
4296
  if (value === null
3859
4297
  || value === undefined
3860
- || (emptyString(`${value ?? ''}`) && skipEmptyString === true)) {
3861
- if (breakExcuteIfSkip === true) {
4298
+ || (emptyString(`${value ?? ''}`) && skipEmptyString)) {
4299
+ if (breakExcuteIfSkip) {
3862
4300
  this.if_exec = false;
3863
4301
  }
3864
4302
  return this;
@@ -3879,8 +4317,8 @@ class StreamQuery {
3879
4317
  __(keys, value, op, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3880
4318
  if (value === null
3881
4319
  || value === undefined
3882
- || (emptyString(`${value ?? ''}`) && skipEmptyString === true)) {
3883
- if (breakExcuteIfSkip === true) {
4320
+ || (emptyString(`${value ?? ''}`) && skipEmptyString)) {
4321
+ if (breakExcuteIfSkip) {
3884
4322
  this.if_exec = false;
3885
4323
  }
3886
4324
  return this;
@@ -3908,12 +4346,8 @@ class StreamQuery {
3908
4346
  }
3909
4347
  _between(key, value1, value2, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3910
4348
  if (value1 === null
3911
- || value1 === undefined
3912
- || (emptyString(`${value1 ?? ''}`) && skipEmptyString === true)
3913
- || value2 === null
3914
- || value2 === undefined
3915
- || (emptyString(`${value2 ?? ''}`) && skipEmptyString === true)) {
3916
- if (breakExcuteIfSkip === true) {
4349
+ || value1 === undefined || (emptyString(`${value1 ?? ''}`) && skipEmptyString) || value2 === null || value2 === undefined || (emptyString(`${value2 ?? ''}`) && skipEmptyString)) {
4350
+ if (breakExcuteIfSkip) {
3917
4351
  this.if_exec = false;
3918
4352
  }
3919
4353
  return this;
@@ -3934,7 +4368,7 @@ class StreamQuery {
3934
4368
  return this;
3935
4369
  }
3936
4370
  _in(key, value, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3937
- if (value && value.length > 0 && skipEmptyString === true) {
4371
+ if (value && value.length > 0 && skipEmptyString) {
3938
4372
  value = value.filter(v => !emptyString(`${v ?? ''}`));
3939
4373
  }
3940
4374
  if (value && value.length > 0) {
@@ -3950,13 +4384,13 @@ class StreamQuery {
3950
4384
  }
3951
4385
  }
3952
4386
  }
3953
- else if (breakExcuteIfSkip !== true) {
4387
+ else if (!breakExcuteIfSkip) {
3954
4388
  this.if_exec = false;
3955
4389
  }
3956
4390
  return this;
3957
4391
  }
3958
4392
  _in2(key, value, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3959
- const skip = emptyString(`${value ?? ''}`) && skipEmptyString === true;
4393
+ const skip = emptyString(`${value ?? ''}`) && skipEmptyString;
3960
4394
  if (!skip) {
3961
4395
  if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
3962
4396
  this._param[this._paramKeys[paramName]] = value;
@@ -3970,7 +4404,7 @@ class StreamQuery {
3970
4404
  }
3971
4405
  }
3972
4406
  }
3973
- else if (breakExcuteIfSkip !== true) {
4407
+ else if (!breakExcuteIfSkip) {
3974
4408
  this.if_exec = false;
3975
4409
  }
3976
4410
  return this;
@@ -3979,7 +4413,7 @@ class StreamQuery {
3979
4413
  if (value === null
3980
4414
  || value === undefined
3981
4415
  || emptyString(`${value ?? ''}`)) {
3982
- if (breakExcuteIfSkip === true) {
4416
+ if (breakExcuteIfSkip) {
3983
4417
  this.if_exec = false;
3984
4418
  }
3985
4419
  return this;
@@ -4001,7 +4435,7 @@ class StreamQuery {
4001
4435
  if (value === null
4002
4436
  || value === undefined
4003
4437
  || emptyString(`${value ?? ''}`)) {
4004
- if (breakExcuteIfSkip === true) {
4438
+ if (breakExcuteIfSkip) {
4005
4439
  this.if_exec = false;
4006
4440
  }
4007
4441
  return this;
@@ -4023,7 +4457,7 @@ class StreamQuery {
4023
4457
  if (value === null
4024
4458
  || value === undefined
4025
4459
  || emptyString(`${value ?? ''}`)) {
4026
- if (breakExcuteIfSkip === true) {
4460
+ if (breakExcuteIfSkip) {
4027
4461
  this.if_exec = false;
4028
4462
  }
4029
4463
  return this;
@@ -4044,8 +4478,8 @@ class StreamQuery {
4044
4478
  _like(key, value, { not = '', left = '', right = '', paramName = '', op = 'LIKE', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
4045
4479
  if (value === null
4046
4480
  || value === undefined
4047
- || (emptyString(`${value ?? ''}`) && skipEmptyString === true)) {
4048
- if (breakExcuteIfSkip === true) {
4481
+ || (emptyString(`${value ?? ''}`) && skipEmptyString)) {
4482
+ if (breakExcuteIfSkip) {
4049
4483
  this.if_exec = false;
4050
4484
  }
4051
4485
  return this;
@@ -4066,8 +4500,8 @@ class StreamQuery {
4066
4500
  _includes(key, value, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = true } = {}) {
4067
4501
  if (value === null
4068
4502
  || value === undefined
4069
- || (emptyString(`${value ?? ''}`) && skipEmptyString === true)) {
4070
- if (breakExcuteIfSkip === true) {
4503
+ || (emptyString(`${value ?? ''}`) && skipEmptyString)) {
4504
+ if (breakExcuteIfSkip) {
4071
4505
  this.if_exec = false;
4072
4506
  }
4073
4507
  return this;
@@ -4638,7 +5072,6 @@ export async function GetRedisLock(key, lockMaxActive) {
4638
5072
  }
4639
5073
  }
4640
5074
  }
4641
- ;
4642
5075
  /** 对FN加锁、缓存执行 */
4643
5076
  export async function excuteWithLock(config, fn__) {
4644
5077
  const key = `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
@@ -4646,7 +5079,7 @@ export async function excuteWithLock(config, fn__) {
4646
5079
  let wait_time = 0;
4647
5080
  const fn = async () => {
4648
5081
  const lock = await GetRedisLock(key, config.lockMaxActive);
4649
- if (lock === false) {
5082
+ if (!lock) {
4650
5083
  if (config.lockWait !== false && ((config.lockMaxWaitTime ?? 0) === 0 || (wait_time + (config.lockRetryInterval ?? 100)) <= (config.lockMaxWaitTime ?? 0))) {
4651
5084
  logger.debug(`get lock ${key} fail, retry after ${config.lockRetryInterval ?? 100}ms...`);
4652
5085
  await sleep(config.lockRetryInterval ?? 100);
@@ -4727,7 +5160,7 @@ export async function clearMethodCache(key) {
4727
5160
  }
4728
5161
  async function clearChild(key, skipDel = false) {
4729
5162
  const db = getRedisDB();
4730
- if (skipDel === false) {
5163
+ if (!skipDel) {
4731
5164
  await db.del(`[cache]${key}`);
4732
5165
  }
4733
5166
  const childtype = await db.type(`[cache-child]${key}`);
@@ -4866,15 +5299,12 @@ class MUParser {
4866
5299
  if (line.startsWith('*')) {
4867
5300
  // 注释符号
4868
5301
  findComment = true;
4869
- continue;
4870
5302
  }
4871
5303
  else {
4872
5304
  if (line.length === 0) {
4873
- continue;
4874
5305
  }
4875
5306
  else if (line.startsWith('```') || line.startsWith('~~~')) {
4876
5307
  // 忽略以code block开头的符号
4877
- continue;
4878
5308
  }
4879
5309
  else {
4880
5310
  // 注释结束