baja-lite 1.4.7 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/boot.js +2 -2
  2. package/package.json +1 -1
  3. package/sql.d.ts +345 -346
  4. package/sql.js +381 -763
package/sql.js CHANGED
@@ -26,9 +26,7 @@ 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 () {
30
- return this.toString();
31
- };
29
+ BigInt.prototype.toJSON = function () { return this.toString(); };
32
30
  const BIGINT_EXT_TYPE = 0;
33
31
  export const extensionCodec = new ExtensionCodec();
34
32
  extensionCodec.register({
@@ -72,9 +70,9 @@ const _inTransaction = Symbol('inTransaction');
72
70
  const _daoDB = Symbol('daoDB');
73
71
  const _sqliteRemoteName = Symbol('sqliteRemoteName');
74
72
  const _SqlOption = Symbol('SqlOption');
73
+ export const _DataConvert = Symbol('DataConvert');
75
74
  const _resultMap = Symbol('resultMap');
76
75
  const _resultMap_SQLID = Symbol('resultMap_SQLID');
77
- export const _dataConvert = Symbol('dataConvert');
78
76
  export const _enum = Symbol('_enum');
79
77
  export const _GlobalSqlOption = Symbol('GlobalSqlOption');
80
78
  export const _EventBus = Symbol('EventBus');
@@ -104,6 +102,7 @@ export var MapperIfUndefined;
104
102
  MapperIfUndefined[MapperIfUndefined["Zero"] = 2] = "Zero";
105
103
  MapperIfUndefined[MapperIfUndefined["EmptyString"] = 3] = "EmptyString";
106
104
  })(MapperIfUndefined || (MapperIfUndefined = {}));
105
+ ;
107
106
  export var SyncMode;
108
107
  (function (SyncMode) {
109
108
  /** 同步执行 */
@@ -114,27 +113,27 @@ export var SyncMode;
114
113
  export var InsertMode;
115
114
  (function (InsertMode) {
116
115
  /**
117
- # 默认使用
118
- ** 支持单个、批量,语法 `INSERT INTO XX VALUES (第一条数据), (第二条数据);`
119
- ** 批量执行有性能优势,但无法利用数据库的sql预编译功能
120
- */
116
+ # 默认使用
117
+ ** 支持单个、批量,语法 `INSERT INTO XX VALUES (第一条数据), (第二条数据);`
118
+ ** 批量执行有性能优势,但无法利用数据库的sql预编译功能
119
+ */
121
120
  InsertMode[InsertMode["Insert"] = 0] = "Insert";
122
121
  /**
123
- # 利用临时表
124
- ## 执行步骤
125
- 1. 建立临时表(从正式表复制)
126
- 2. 数据全部进入临时表
127
- 3. 临时表数据转移到正式表: `INSERT INTO 正式表 SELECT * FROM 临时表`
128
- 4. 删除临时表
129
- ## 注意
130
- 1. 适用于:主键不会冲突、非自增
131
- 2. 临时表的结构复制正式表
122
+ # 利用临时表
123
+ ## 执行步骤
124
+ 1. 建立临时表(从正式表复制)
125
+ 2. 数据全部进入临时表
126
+ 3. 临时表数据转移到正式表: `INSERT INTO 正式表 SELECT * FROM 临时表`
127
+ 4. 删除临时表
128
+ ## 注意
129
+ 1. 适用于:主键不会冲突、非自增
130
+ 2. 临时表的结构复制正式表
132
131
  */
133
132
  InsertMode[InsertMode["InsertWithTempTable"] = 1] = "InsertWithTempTable";
134
133
  InsertMode[InsertMode["InsertIfNotExists"] = 2] = "InsertIfNotExists";
135
134
  /**
136
- # 插入或者更新
137
- 1. 判断依据是主键
135
+ # 插入或者更新
136
+ 1. 判断依据是主键
138
137
  */
139
138
  InsertMode[InsertMode["Replace"] = 3] = "Replace";
140
139
  })(InsertMode || (InsertMode = {}));
@@ -146,7 +145,7 @@ export var DeleteMode;
146
145
  `DELETE FROM WHERE (id = 1) OR (id = 2)`
147
146
  ### 例二
148
147
  `DELETE FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
149
- */
148
+ */
150
149
  DeleteMode[DeleteMode["Common"] = 0] = "Common";
151
150
  /*
152
151
  ## 借助临时表
@@ -163,7 +162,7 @@ export var SelectMode;
163
162
  `SELECT * FROM WHERE (id = 1) OR (id = 2)`
164
163
  ### 例二
165
164
  `SELECT * FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
166
- */
165
+ */
167
166
  SelectMode[SelectMode["Common"] = 0] = "Common";
168
167
  /*
169
168
  ## 借助临时表
@@ -216,6 +215,7 @@ export const _defOption = {
216
215
  skipNull: true,
217
216
  skipEmptyString: true
218
217
  };
218
+ ;
219
219
  class MysqlConnection {
220
220
  constructor(conn) {
221
221
  this[_b] = false;
@@ -226,10 +226,12 @@ class MysqlConnection {
226
226
  if (!sql) {
227
227
  return { affectedRows: 0, insertId: 0n };
228
228
  }
229
+ ;
229
230
  if (sync === SyncMode.Sync) {
230
231
  logger.warn('MYSQL not suppouted sync mode');
231
232
  return { affectedRows: 0, insertId: 0n };
232
233
  }
234
+ ;
233
235
  if (globalThis[_GlobalSqlOption].log === 'trace') {
234
236
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
235
237
  }
@@ -257,10 +259,12 @@ class MysqlConnection {
257
259
  if (!sql) {
258
260
  return null;
259
261
  }
262
+ ;
260
263
  if (sync === SyncMode.Sync) {
261
264
  logger.warn('MYSQL not suppouted sync mode');
262
265
  return null;
263
266
  }
267
+ ;
264
268
  if (globalThis[_GlobalSqlOption].log === 'trace') {
265
269
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
266
270
  }
@@ -291,10 +295,12 @@ class MysqlConnection {
291
295
  if (!sql) {
292
296
  return null;
293
297
  }
298
+ ;
294
299
  if (sync === SyncMode.Sync) {
295
300
  logger.warn('MYSQL not suppouted sync mode');
296
301
  return null;
297
302
  }
303
+ ;
298
304
  if (globalThis[_GlobalSqlOption].log === 'trace') {
299
305
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
300
306
  }
@@ -323,10 +329,12 @@ class MysqlConnection {
323
329
  if (!sql) {
324
330
  return [];
325
331
  }
332
+ ;
326
333
  if (sync === SyncMode.Sync) {
327
334
  logger.warn('MYSQL not suppouted sync mode');
328
335
  return [];
329
336
  }
337
+ ;
330
338
  if (globalThis[_GlobalSqlOption].log === 'trace') {
331
339
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
332
340
  }
@@ -355,10 +363,12 @@ class MysqlConnection {
355
363
  if (!sql) {
356
364
  return [];
357
365
  }
366
+ ;
358
367
  if (sync === SyncMode.Sync) {
359
368
  logger.warn('MYSQL not suppouted sync mode');
360
369
  return [];
361
370
  }
371
+ ;
362
372
  if (globalThis[_GlobalSqlOption].log === 'trace') {
363
373
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
364
374
  }
@@ -388,6 +398,7 @@ class MysqlConnection {
388
398
  catch (error) {
389
399
  }
390
400
  }
401
+ ;
391
402
  }
392
403
  }
393
404
  _b = _inTransaction;
@@ -405,6 +416,7 @@ export class Mysql {
405
416
  logger.error('MYSQL not suppouted sync mode');
406
417
  return null;
407
418
  }
419
+ ;
408
420
  return new Promise(async (resolve, reject) => {
409
421
  try {
410
422
  const connection = await this[_daoDB].getConnection();
@@ -421,6 +433,7 @@ export class Mysql {
421
433
  logger.warn('MYSQL not suppouted sync mode');
422
434
  return null;
423
435
  }
436
+ ;
424
437
  return new Promise(async (resolve, reject) => {
425
438
  let needCommit = false;
426
439
  let newConn = false;
@@ -473,6 +486,7 @@ export class Mysql {
473
486
  if (sync === SyncMode.Sync) {
474
487
  this[_daoDB]?.destroy();
475
488
  }
489
+ ;
476
490
  }
477
491
  backup(sync, name) {
478
492
  }
@@ -491,10 +505,12 @@ class PostgresqlConnection {
491
505
  if (!sql) {
492
506
  return { affectedRows: 0, insertId: 0n };
493
507
  }
508
+ ;
494
509
  if (sync === SyncMode.Sync) {
495
510
  logger.warn('Postgresql not suppouted sync mode');
496
511
  return { affectedRows: 0, insertId: 0n };
497
512
  }
513
+ ;
498
514
  if (globalThis[_GlobalSqlOption].log === 'trace') {
499
515
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
500
516
  }
@@ -526,10 +542,12 @@ class PostgresqlConnection {
526
542
  if (!sql) {
527
543
  return null;
528
544
  }
545
+ ;
529
546
  if (sync === SyncMode.Sync) {
530
547
  logger.warn('Postgresql not suppouted sync mode');
531
548
  return null;
532
549
  }
550
+ ;
533
551
  if (globalThis[_GlobalSqlOption].log === 'trace') {
534
552
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
535
553
  }
@@ -564,10 +582,12 @@ class PostgresqlConnection {
564
582
  if (!sql) {
565
583
  return null;
566
584
  }
585
+ ;
567
586
  if (sync === SyncMode.Sync) {
568
587
  logger.warn('Postgresql not suppouted sync mode');
569
588
  return null;
570
589
  }
590
+ ;
571
591
  if (globalThis[_GlobalSqlOption].log === 'trace') {
572
592
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
573
593
  }
@@ -600,10 +620,12 @@ class PostgresqlConnection {
600
620
  if (!sql) {
601
621
  return [];
602
622
  }
623
+ ;
603
624
  if (sync === SyncMode.Sync) {
604
625
  logger.warn('Postgresql not suppouted sync mode');
605
626
  return [];
606
627
  }
628
+ ;
607
629
  if (globalThis[_GlobalSqlOption].log === 'trace') {
608
630
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
609
631
  }
@@ -636,10 +658,12 @@ class PostgresqlConnection {
636
658
  if (!sql) {
637
659
  return [];
638
660
  }
661
+ ;
639
662
  if (sync === SyncMode.Sync) {
640
663
  logger.warn('Postgresql not suppouted sync mode');
641
664
  return [];
642
665
  }
666
+ ;
643
667
  if (globalThis[_GlobalSqlOption].log === 'trace') {
644
668
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
645
669
  }
@@ -673,6 +697,7 @@ class PostgresqlConnection {
673
697
  catch (error) {
674
698
  }
675
699
  }
700
+ ;
676
701
  }
677
702
  }
678
703
  _c = _inTransaction;
@@ -690,6 +715,7 @@ export class Postgresql {
690
715
  logger.error('Postgresql not suppouted sync mode');
691
716
  return null;
692
717
  }
718
+ ;
693
719
  return new Promise(async (resolve, reject) => {
694
720
  try {
695
721
  const connection = await this[_daoDB].connect();
@@ -706,6 +732,7 @@ export class Postgresql {
706
732
  logger.warn('Postgresql not suppouted sync mode');
707
733
  return null;
708
734
  }
735
+ ;
709
736
  return new Promise(async (resolve, reject) => {
710
737
  let needCommit = false;
711
738
  let newConn = false;
@@ -758,6 +785,7 @@ export class Postgresql {
758
785
  if (sync === SyncMode.Sync) {
759
786
  this[_daoDB]?.end();
760
787
  }
788
+ ;
761
789
  }
762
790
  backup(sync, name) {
763
791
  }
@@ -777,10 +805,12 @@ class SqliteConnection {
777
805
  if (!sql) {
778
806
  return { affectedRows: 0, insertId: 0n };
779
807
  }
808
+ ;
780
809
  if (sync === SyncMode.Async) {
781
810
  logger.warn(`SQLITE not suppoted async mode`);
782
811
  return { affectedRows: 0, insertId: 0n };
783
812
  }
813
+ ;
784
814
  if (globalThis[_GlobalSqlOption].log === 'trace') {
785
815
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
786
816
  }
@@ -806,10 +836,12 @@ class SqliteConnection {
806
836
  if (!sql) {
807
837
  return null;
808
838
  }
839
+ ;
809
840
  if (sync === SyncMode.Async) {
810
841
  logger.warn(`SQLITE not suppoted async mode`);
811
842
  return null;
812
843
  }
844
+ ;
813
845
  if (globalThis[_GlobalSqlOption].log === 'trace') {
814
846
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
815
847
  }
@@ -830,9 +862,11 @@ class SqliteConnection {
830
862
  if (!sql) {
831
863
  return null;
832
864
  }
865
+ ;
833
866
  if (sync === SyncMode.Async) {
834
867
  return null;
835
868
  }
869
+ ;
836
870
  if (globalThis[_GlobalSqlOption].log === 'trace') {
837
871
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
838
872
  }
@@ -853,10 +887,12 @@ class SqliteConnection {
853
887
  if (!sql) {
854
888
  return [];
855
889
  }
890
+ ;
856
891
  if (sync === SyncMode.Async) {
857
892
  logger.warn(`SQLITE not suppoted async mode`);
858
893
  return [];
859
894
  }
895
+ ;
860
896
  if (globalThis[_GlobalSqlOption].log === 'trace') {
861
897
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
862
898
  }
@@ -877,10 +913,12 @@ class SqliteConnection {
877
913
  if (!sql) {
878
914
  return [];
879
915
  }
916
+ ;
880
917
  if (sync === SyncMode.Async) {
881
918
  logger.warn(`SQLITE not suppoted async mode`);
882
919
  return [];
883
920
  }
921
+ ;
884
922
  if (globalThis[_GlobalSqlOption].log === 'trace') {
885
923
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
886
924
  }
@@ -904,37 +942,14 @@ export class Sqlite {
904
942
  this[_daoDB] = db;
905
943
  this[_daoDB].pragma('journal_mode = WAL');
906
944
  this[_daoDB].exec(`
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
- );
945
+ CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
946
+ DELETE FROM DUAL;
947
+ INSERT INTO DUAL (______id ) VALUES ( 1 );
948
+ CREATE TABLE IF NOT EXISTS TABLE_VERSION (
949
+ ______tableName text NOT NULL,
950
+ ______version text NOT NULL,
951
+ PRIMARY KEY ( ______tableName )
952
+ );
938
953
  `);
939
954
  }
940
955
  createConnection(sync) {
@@ -942,6 +957,7 @@ export class Sqlite {
942
957
  logger.error(`SQLITE not suppoted async mode`);
943
958
  return null;
944
959
  }
960
+ ;
945
961
  return new SqliteConnection(this[_daoDB]);
946
962
  }
947
963
  transaction(sync, fn, conn) {
@@ -949,10 +965,11 @@ export class Sqlite {
949
965
  logger.warn(`SQLITE not suppoted async mode`);
950
966
  return null;
951
967
  }
968
+ ;
952
969
  if (!conn) {
953
970
  conn = this.createConnection(SyncMode.Sync) ?? undefined;
954
971
  }
955
- if (!conn[_inTransaction]) {
972
+ if (conn[_inTransaction] !== true) {
956
973
  return this[_daoDB].transaction(() => {
957
974
  conn[_inTransaction] = true;
958
975
  const rt = fn(conn);
@@ -969,11 +986,13 @@ export class Sqlite {
969
986
  if (sync === SyncMode.Sync) {
970
987
  this[_daoDB].close();
971
988
  }
989
+ ;
972
990
  }
973
991
  backup(sync, name) {
974
992
  if (sync === SyncMode.Sync) {
975
993
  this[_daoDB].backup(name);
976
994
  }
995
+ ;
977
996
  }
978
997
  remove(sync) {
979
998
  }
@@ -991,10 +1010,12 @@ export class SqliteRemoteConnection {
991
1010
  if (!sql) {
992
1011
  return { affectedRows: 0, insertId: 0n };
993
1012
  }
1013
+ ;
994
1014
  if (sync === SyncMode.Sync) {
995
1015
  logger.warn('SqliteRemote not suppouted sync mode');
996
1016
  return { affectedRows: 0, insertId: 0n };
997
1017
  }
1018
+ ;
998
1019
  if (globalThis[_GlobalSqlOption].log === 'trace') {
999
1020
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1000
1021
  }
@@ -1019,10 +1040,12 @@ export class SqliteRemoteConnection {
1019
1040
  if (!sql) {
1020
1041
  return null;
1021
1042
  }
1043
+ ;
1022
1044
  if (sync === SyncMode.Sync) {
1023
1045
  logger.warn('SqliteRemote not suppouted sync mode');
1024
1046
  return null;
1025
1047
  }
1048
+ ;
1026
1049
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1027
1050
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1028
1051
  }
@@ -1047,10 +1070,12 @@ export class SqliteRemoteConnection {
1047
1070
  if (!sql) {
1048
1071
  return null;
1049
1072
  }
1073
+ ;
1050
1074
  if (sync === SyncMode.Sync) {
1051
1075
  logger.warn('SqliteRemote not suppouted sync mode');
1052
1076
  return null;
1053
1077
  }
1078
+ ;
1054
1079
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1055
1080
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1056
1081
  }
@@ -1075,10 +1100,12 @@ export class SqliteRemoteConnection {
1075
1100
  if (!sql) {
1076
1101
  return [];
1077
1102
  }
1103
+ ;
1078
1104
  if (sync === SyncMode.Sync) {
1079
1105
  logger.warn('SqliteRemote not suppouted sync mode');
1080
1106
  return [];
1081
1107
  }
1108
+ ;
1082
1109
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1083
1110
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1084
1111
  }
@@ -1103,10 +1130,12 @@ export class SqliteRemoteConnection {
1103
1130
  if (!sql) {
1104
1131
  return [];
1105
1132
  }
1133
+ ;
1106
1134
  if (sync === SyncMode.Sync) {
1107
1135
  logger.warn('SqliteRemote not suppouted sync mode');
1108
1136
  return [];
1109
1137
  }
1138
+ ;
1110
1139
  if (globalThis[_GlobalSqlOption].log === 'trace') {
1111
1140
  logger.trace(`${sql}\n,${JSON.stringify(params ?? '')}`);
1112
1141
  }
@@ -1140,6 +1169,7 @@ export class SqliteRemote {
1140
1169
  logger.error('SQLITEREMOTE not suppouted sync mode');
1141
1170
  return null;
1142
1171
  }
1172
+ ;
1143
1173
  return new Promise(async (resolve, reject) => {
1144
1174
  if (!this.connection) {
1145
1175
  this.connection = new SqliteRemoteConnection(this[_daoDB], this[_sqliteRemoteName]);
@@ -1160,11 +1190,13 @@ export class SqliteRemote {
1160
1190
  if (sync === SyncMode.Async) {
1161
1191
  return this[_daoDB]?.close(this[_sqliteRemoteName]);
1162
1192
  }
1193
+ ;
1163
1194
  }
1164
1195
  backup(sync, exportPath) {
1165
1196
  if (sync === SyncMode.Async) {
1166
1197
  return this[_daoDB]?.export(this[_sqliteRemoteName], exportPath);
1167
1198
  }
1199
+ ;
1168
1200
  }
1169
1201
  remove(sync) {
1170
1202
  }
@@ -1172,12 +1204,13 @@ export class SqliteRemote {
1172
1204
  if (sync === SyncMode.Async) {
1173
1205
  return this[_daoDB]?.restore(this[_sqliteRemoteName], importPath);
1174
1206
  }
1207
+ ;
1175
1208
  }
1176
1209
  }
1177
1210
  class Build {
1178
1211
  /**
1179
1212
  *
1180
- * @param isCount 是否是count查询
1213
+ * @param count 是否是count查询
1181
1214
  * @param isSum 是否是sum查询
1182
1215
  * @param param
1183
1216
  */
@@ -1199,20 +1232,20 @@ class Build {
1199
1232
  if (this.isCount) {
1200
1233
  return Build.page;
1201
1234
  }
1202
- else if (!this.isSum) {
1235
+ else if (this.isSum !== true) {
1203
1236
  return render(text);
1204
1237
  }
1205
1238
  };
1206
1239
  }
1207
1240
  /**
1208
- *
1209
- * 包含的内容只在汇总查询时有效,否则是空白
1210
- * @returns
1211
- * @memberof Build
1212
- */
1241
+ *
1242
+ * 包含的内容只在汇总查询时有效,否则是空白
1243
+ * @returns
1244
+ * @memberof Build
1245
+ */
1213
1246
  sum() {
1214
1247
  return (text, render) => {
1215
- if (!this.isSum) {
1248
+ if (this.isSum !== true) {
1216
1249
  return '';
1217
1250
  }
1218
1251
  else {
@@ -1282,7 +1315,7 @@ class Build {
1282
1315
  const datas = data.split(',');
1283
1316
  for (let i = 0; i < datas.length; i++) {
1284
1317
  if (datas[i]?.match(/\s|\t/) === null) {
1285
- datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b) => b.toUpperCase())}`;
1318
+ datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b, c) => b.toUpperCase())}`;
1286
1319
  }
1287
1320
  }
1288
1321
  return ` ${datas.join(',')} `;
@@ -1431,7 +1464,7 @@ class Build {
1431
1464
  * * t.problemtype = 列名
1432
1465
  *
1433
1466
  * ```
1434
- * {{#enum}} PROBLEM_TYPE(t.problemtype) {{/enum}}
1467
+ * {{#enumTag}} PROBLEM_TYPE(t.problemtype) {{/enumTag}}
1435
1468
  * ```
1436
1469
  */
1437
1470
  enum() {
@@ -1460,13 +1493,13 @@ class Build {
1460
1493
  }
1461
1494
  Build.page = 'COUNT(1) zccw1986 ';
1462
1495
  function replaceCdata(rawText) {
1463
- const cdataRegex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1464
- const matches = rawText.match(cdataRegex);
1496
+ var cdataRegex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1497
+ var matches = rawText.match(cdataRegex);
1465
1498
  if (matches != null && matches.length > 0) {
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];
1499
+ for (var z = 0; z < matches.length; z++) {
1500
+ var regex = new RegExp('(<!\\[CDATA\\[)([\\s\\S]*?)(\\]\\]>)', 'g');
1501
+ var m = regex.exec(matches[z]);
1502
+ var cdataText = m[2];
1470
1503
  cdataText = cdataText.replace(/\&/g, '&amp;');
1471
1504
  cdataText = cdataText.replace(/\</g, '&lt;');
1472
1505
  cdataText = cdataText.replace(/\>/g, '&gt;');
@@ -1608,15 +1641,14 @@ export class SqlCache {
1608
1641
  /**
1609
1642
  *
1610
1643
  * ```
1611
- // 第一个元素=列名,第二个元素是属性路径,
1612
- [
1613
- ['dit_id', ['id']], // 列名ditid,对应属性id
1614
- ['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
1615
- ]
1644
+ // 第一个元素=列名,第二个元素是属性路径,
1645
+ [
1646
+ ['dit_id', ['id']], // 列名ditid,对应属性id
1647
+ ['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
1648
+ ]
1616
1649
  * ```
1617
- * @param ams
1650
+ * @param am
1618
1651
  * @param keys
1619
- * @param key
1620
1652
  */
1621
1653
  readResultMap(ams, keys, key) {
1622
1654
  for (const am of ams) {
@@ -1685,14 +1717,14 @@ export class SqlCache {
1685
1717
  if (typeof sqlSource === 'function') {
1686
1718
  const _sql = sqlSource(options);
1687
1719
  let sql = mustache.render(_sql, buildParam, this.sqlFNMap);
1688
- if (!buildParam.OrderSeted && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1720
+ if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1689
1721
  sql += ` ORDER BY ${buildParam.OrderBy}`;
1690
1722
  }
1691
1723
  return sql;
1692
1724
  }
1693
1725
  else if (typeof sqlSource === 'string') {
1694
1726
  let sql = mustache.render(sqlSource, buildParam, this.sqlFNMap);
1695
- if (!buildParam.OrderSeted && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1727
+ if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1696
1728
  sql += ` ORDER BY ${buildParam.OrderBy}`;
1697
1729
  }
1698
1730
  return sql;
@@ -1700,7 +1732,7 @@ export class SqlCache {
1700
1732
  else if (typeof sqlSource === 'object') {
1701
1733
  const _sql = convert(sqlSource, options, matchSqlid, this.sqlMap);
1702
1734
  let sql = mustache.render(_sql, buildParam, this.sqlFNMap);
1703
- if (!buildParam.OrderSeted && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1735
+ if (buildParam.OrderSeted === false && buildParam.OrderBy && options.isCount !== true && options.isSum !== true) {
1704
1736
  sql += ` ORDER BY ${buildParam.OrderBy}`;
1705
1737
  }
1706
1738
  return sql;
@@ -1711,18 +1743,18 @@ export class SqlCache {
1711
1743
  // #endregion
1712
1744
  /**
1713
1745
 
1714
- ## 所有service中内置方法定义规则
1746
+ ## 所有service中内置方法定义规则
1715
1747
  ** 方法第一个参数必须是 sync: SyncMode
1716
1748
  ** 方法最后一个参数必须是 option
1717
1749
 
1718
- ## sync 表示是否是同步方法
1750
+ ## sync 表示是否是同步方法
1719
1751
 
1720
- 因为mysql是异步、sqlite是同步,导致必须通过一个标识来区分,否则将必须为两种数据库设置不同的service,失去了意义
1752
+ 因为mysql是异步、sqlite是同步,导致必须通过一个标识来区分,否则将必须为两种数据库设置不同的service,失去了意义
1721
1753
 
1722
- ## option 额外控制参数
1754
+ ## option 额外控制参数
1723
1755
 
1724
- ## length
1725
- 方法的参数数量
1756
+ ## length
1757
+ 方法的参数数量
1726
1758
  */
1727
1759
  function P(skipConn = false) {
1728
1760
  return (_target, propertyKey, descriptor) => {
@@ -1748,7 +1780,7 @@ function P(skipConn = false) {
1748
1780
  }
1749
1781
  Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!');
1750
1782
  // 连接共享
1751
- if (!skipConn && !option.conn) {
1783
+ if (skipConn === false && !option.conn) {
1752
1784
  option.conn = option.dao.createConnection(SyncMode.Sync);
1753
1785
  }
1754
1786
  else {
@@ -1760,12 +1792,7 @@ function P(skipConn = false) {
1760
1792
  return result;
1761
1793
  }
1762
1794
  catch (error) {
1763
- try {
1764
- console.error(`service ${propertyKey} have an error:${error}`);
1765
- }
1766
- catch (error) {
1767
- console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}`);
1768
- }
1795
+ console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1769
1796
  throw error;
1770
1797
  }
1771
1798
  finally {
@@ -1791,7 +1818,7 @@ function P(skipConn = false) {
1791
1818
  Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!');
1792
1819
  return new Promise(async (resolve, reject) => {
1793
1820
  // 连接共享
1794
- if (!skipConn && !option.conn) {
1821
+ if (skipConn === false && !option.conn) {
1795
1822
  (option).conn = await option.dao.createConnection(SyncMode.Async);
1796
1823
  }
1797
1824
  else {
@@ -1804,7 +1831,6 @@ function P(skipConn = false) {
1804
1831
  }
1805
1832
  catch (error) {
1806
1833
  console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1807
- // console.error(`${(option as any).sqlId ?? option!.tableName} service ${propertyKey} have an error:${error}`)
1808
1834
  reject(error);
1809
1835
  }
1810
1836
  finally {
@@ -1823,7 +1849,7 @@ function P(skipConn = false) {
1823
1849
  return new Promise(async (resolve, reject) => {
1824
1850
  try {
1825
1851
  // 连接共享
1826
- if (!skipConn && !option.conn) {
1852
+ if (skipConn === false && !option.conn) {
1827
1853
  (option).conn = await option.dao.createConnection(SyncMode.Async);
1828
1854
  }
1829
1855
  else {
@@ -1835,7 +1861,6 @@ function P(skipConn = false) {
1835
1861
  }
1836
1862
  catch (error) {
1837
1863
  console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1838
- // console.error(`${(option as any).sqlId ?? option!.tableName} service ${propertyKey} have an error:${error}`)
1839
1864
  reject(error);
1840
1865
  }
1841
1866
  finally {
@@ -1854,7 +1879,7 @@ function P(skipConn = false) {
1854
1879
  return new Promise(async (resolve, reject) => {
1855
1880
  try {
1856
1881
  // 连接共享
1857
- if (!skipConn && !option.conn) {
1882
+ if (skipConn === false && !option.conn) {
1858
1883
  (option).conn = await option.dao.createConnection(SyncMode.Async);
1859
1884
  }
1860
1885
  else {
@@ -1866,7 +1891,6 @@ function P(skipConn = false) {
1866
1891
  }
1867
1892
  catch (error) {
1868
1893
  console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1869
- // console.error(`${(option as any).sqlId ?? option!.tableName} service ${propertyKey} have an error:${error}`)
1870
1894
  reject(error);
1871
1895
  }
1872
1896
  finally {
@@ -1887,7 +1911,7 @@ const FieldFilter = (K, V, def, uuidColumn, option) => {
1887
1911
  let ret = 0;
1888
1912
  // 如果是插入操作且字段是UUID,则不进行空值检查
1889
1913
  // 只有在非插入或者非UUID时,进行空置检查
1890
- if (option?.insert === true && uuidColumn) {
1914
+ if (option?.insert && uuidColumn) {
1891
1915
  ret = 1;
1892
1916
  if (V === undefined || emptyString(`${V ?? ''}`)) {
1893
1917
  V = null;
@@ -1897,19 +1921,19 @@ const FieldFilter = (K, V, def, uuidColumn, option) => {
1897
1921
  if (V === null) {
1898
1922
  if (option?.skipNull !== true) {
1899
1923
  ret = 1;
1900
- V = option?.insert === true && def && def.hasOwnProperty(K) ? def[K] : null;
1924
+ V = option?.insert && def && def.hasOwnProperty(K) ? def[K] : null;
1901
1925
  }
1902
1926
  }
1903
1927
  else if (V === undefined) {
1904
1928
  if (option?.skipUndefined !== true) {
1905
1929
  ret = 1;
1906
- V = option?.insert === true && def && def.hasOwnProperty(K) ? def[K] : null;
1930
+ V = option?.insert && def && def.hasOwnProperty(K) ? def[K] : null;
1907
1931
  }
1908
1932
  }
1909
1933
  else if (emptyString(`${V ?? ''}`)) {
1910
1934
  if (option?.skipEmptyString !== true) {
1911
1935
  ret = 1;
1912
- V = option?.insert === true && def && def.hasOwnProperty(K) ? def[K] : '';
1936
+ V = option?.insert && def && def.hasOwnProperty(K) ? def[K] : '';
1913
1937
  }
1914
1938
  }
1915
1939
  else {
@@ -1966,8 +1990,8 @@ export const DB = (config) => {
1966
1990
  this[_x] = __stateFileName;
1967
1991
  this[_y] = __deleteState;
1968
1992
  this[_z] = (data, option) => {
1969
- return Object.fromEntries(iterate(option?.skipId === true ? __columnsNoId : __columns)
1970
- .map(K => [K, FieldFilter(K, data[K], __def, __fields[K].uuid === true || __fields[K].uuidShort === true, option)])
1993
+ return Object.fromEntries(iterate(option?.skipId ? __columnsNoId : __columns)
1994
+ .map(K => [K, FieldFilter(K, data[K], __def, __fields[K].uuid || __fields[K].uuidShort, option)])
1971
1995
  .filter(data => {
1972
1996
  if (data[1][0] === 1) {
1973
1997
  if (__fields[data[0]].Data2SQL) {
@@ -2010,16 +2034,16 @@ export const DB = (config) => {
2010
2034
  };
2011
2035
  };
2012
2036
  /**
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
- ```
2037
+ js项目中实体类注解替代品,只要确保函数被执行即可,举例:
2038
+ ```
2039
+ // 声明一个class
2040
+ export class AmaFuck {}
2041
+ DeclareClass(AmaFuck, [
2042
+ { type: "String", name: "SellerSKU" },
2043
+ { type: "String", name: "SellerSKU2" },
2044
+ { type: "String", name: "site" }
2045
+ ]);
2046
+ ```
2023
2047
  */
2024
2048
  export function DeclareClass(clz, FieldOptions) {
2025
2049
  for (const item of FieldOptions) {
@@ -2030,13 +2054,13 @@ export function DeclareClass(clz, FieldOptions) {
2030
2054
  JS项目中,service注解代替,举例:
2031
2055
  ```
2032
2056
  // 声明一个service,注意这里的let
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
- });
2057
+ export let AmaService = class AmaService extends SqlService {};
2058
+ AmaService = DeclareService(AmaService, {
2059
+ tableName: "ama_fuck2",
2060
+ clz: AmaFuck,
2061
+ dbType: DBType.Sqlite,
2062
+ sqliteVersion: "0.0.3"
2063
+ });
2040
2064
  ```
2041
2065
  */
2042
2066
  export function DeclareService(clz, config) {
@@ -2045,11 +2069,11 @@ export function DeclareService(clz, config) {
2045
2069
  /**
2046
2070
  ## 数据库服务
2047
2071
  ### 注解DB
2048
-
2072
+
2049
2073
  ### 泛型 T,同DB注解中的clz
2050
2074
  ** 服务中所有方法默认以该类型为准
2051
2075
  **
2052
-
2076
+
2053
2077
  */
2054
2078
  export class SqlService {
2055
2079
  _insert(datas, option) {
@@ -2117,14 +2141,13 @@ export class SqlService {
2117
2141
  ? this[_def][column]
2118
2142
  : null);
2119
2143
  }
2120
- return `SELECT ${questMark.join(',')}
2121
- FROM DUAL
2122
- WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2144
+ return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2123
2145
  });
2124
2146
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2125
- const sql = formatDialect(`INSERT INTO ${tableName}
2126
- (${columnNames})
2127
- ${questMarks.join(' UNION ALL ')};`, { dialect: formatDialects[option.dbType] });
2147
+ const sql = formatDialect(`INSERT INTO
2148
+ ${tableName}
2149
+ (${columnNames})
2150
+ ${questMarks.join(' UNION ALL ')};`, { dialect: formatDialects[option.dbType] });
2128
2151
  sqls.push({ sql, params });
2129
2152
  break;
2130
2153
  }
@@ -2181,14 +2204,10 @@ export class SqlService {
2181
2204
  });
2182
2205
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2183
2206
  const sql = formatDialect(`
2184
- ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'}
2185
- REPLACE INTO
2207
+ ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2186
2208
  ${tableName}
2187
- (
2188
- ${columnNames}
2189
- )
2190
- VALUES
2191
- ${questMarks};
2209
+ (${columnNames})
2210
+ VALUES ${questMarks};
2192
2211
  `, { dialect: formatDialects[option.dbType] });
2193
2212
  sqls.push({ sql, params });
2194
2213
  break;
@@ -2246,8 +2265,9 @@ export class SqlService {
2246
2265
  });
2247
2266
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2248
2267
  const sql = formatDialect(`
2249
- INSERT INTO ${tableName}
2250
- (${columnNames})
2268
+ INSERT INTO
2269
+ ${tableName}
2270
+ (${columnNames})
2251
2271
  VALUES ${questMarks};
2252
2272
  `, { dialect: formatDialects[option.dbType] });
2253
2273
  sqls.push({ sql, params });
@@ -2312,15 +2332,15 @@ export class SqlService {
2312
2332
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2313
2333
  sqls.push({
2314
2334
  sql: formatDialect(`
2315
- INSERT INTO ${tableTemp}
2316
- (${columnNames})
2335
+ INSERT INTO
2336
+ ${tableTemp}
2337
+ (${columnNames})
2317
2338
  VALUES ${questMarks};
2318
2339
  `, { dialect: formatDialects[option.dbType] }), params
2319
2340
  });
2320
2341
  sqls.push({
2321
2342
  sql: formatDialect(`INSERT INTO ${option.tableName} (${columnNames})
2322
- SELECT ${columnNames}
2323
- FROM ${tableTemp};`, { dialect: formatDialects[option.dbType] })
2343
+ SELECT ${columnNames} FROM ${tableTemp};`, { dialect: formatDialects[option.dbType] })
2324
2344
  });
2325
2345
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2326
2346
  break;
@@ -2346,13 +2366,13 @@ export class SqlService {
2346
2366
  }
2347
2367
  }
2348
2368
  return result;
2349
- }, { everyLength: option?.every === true ? 1 : option?.maxDeal });
2369
+ }, { everyLength: option?.every ? 1 : option?.maxDeal });
2350
2370
  if (isArray)
2351
2371
  return result;
2352
2372
  else
2353
2373
  return result[0];
2354
2374
  };
2355
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2375
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2356
2376
  return fn();
2357
2377
  }
2358
2378
  else {
@@ -2371,10 +2391,10 @@ export class SqlService {
2371
2391
  }
2372
2392
  }
2373
2393
  return result;
2374
- }, { everyLength: option?.every === true ? 1 : option?.maxDeal });
2394
+ }, { everyLength: option?.every ? 1 : option?.maxDeal });
2375
2395
  return result;
2376
2396
  };
2377
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2397
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2378
2398
  return fn();
2379
2399
  }
2380
2400
  else {
@@ -2396,7 +2416,7 @@ export class SqlService {
2396
2416
  }, { everyLength: 1 });
2397
2417
  return result[0];
2398
2418
  };
2399
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2419
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2400
2420
  return fn();
2401
2421
  }
2402
2422
  else {
@@ -2427,8 +2447,7 @@ export class SqlService {
2427
2447
  }
2428
2448
  });
2429
2449
  }
2430
- const sql = formatDialect(`UPDATE ${tableName}
2431
- SET ${iterate(this[_columnsNoId])
2450
+ const sql = formatDialect(`UPDATE ${tableName} SET ${iterate(this[_columnsNoId])
2432
2451
  .filter(K => columnMaps[K].where.length > 0)
2433
2452
  .map(K => {
2434
2453
  params.push(...columnMaps[K].params);
@@ -2458,7 +2477,7 @@ export class SqlService {
2458
2477
  }, { everyLength: option?.maxDeal });
2459
2478
  return result.length > 0 ? result.reduce((a, b) => a + b) : 0;
2460
2479
  };
2461
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2480
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2462
2481
  return fn();
2463
2482
  }
2464
2483
  else {
@@ -2480,7 +2499,7 @@ export class SqlService {
2480
2499
  }, { everyLength: option?.maxDeal });
2481
2500
  return result.length > 0 ? result.reduce((a, b) => a + b) : 0;
2482
2501
  };
2483
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2502
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2484
2503
  return fn();
2485
2504
  }
2486
2505
  else {
@@ -2522,54 +2541,32 @@ export class SqlService {
2522
2541
  params.unshift(this[_deleteState]);
2523
2542
  sqls.push({
2524
2543
  sql: formatDialect(`
2525
- UPDATE ${tableNameESC}
2526
- SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2527
- WHERE ${whereSql};
2528
- `, { dialect: formatDialects[option.dbType] }), params
2544
+ UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2545
+ WHERE ${whereSql};
2546
+ `, { dialect: formatDialects[option.dbType] }), params
2529
2547
  });
2530
2548
  }
2531
2549
  else {
2532
- sqls.push({
2533
- sql: formatDialect(`DELETE
2534
- FROM ${tableNameESC}
2535
- WHERE ${whereSql};`, { dialect: formatDialects[option.dbType] }), params
2536
- });
2550
+ sqls.push({ sql: formatDialect(`DELETE FROM ${tableNameESC} WHERE ${whereSql};`, { dialect: formatDialects[option.dbType] }), params });
2537
2551
  }
2538
2552
  }
2539
2553
  else {
2540
2554
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2541
2555
  const delWhere = Object.keys(wheres[0]);
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
+ const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: delWhere, data: wheres, index: 'all', id: 'none' });
2550
2557
  sqls.push(..._sqls);
2551
2558
  switch (option.dbType) {
2552
2559
  case DBType.Mysql: {
2553
2560
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2554
2561
  sqls.push({
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] }),
2562
+ 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 ')}
2563
+ SET a.${this[_fields][this[_stateFileName]]?.C2()} = ?;`, { dialect: formatDialects[option.dbType] }),
2558
2564
  params: [this[_deleteState]]
2559
2565
  });
2560
2566
  }
2561
2567
  else {
2562
2568
  sqls.push({
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
+ 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] })
2573
2570
  });
2574
2571
  }
2575
2572
  break;
@@ -2579,18 +2576,13 @@ export class SqlService {
2579
2576
  const columnNames = iterate(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2580
2577
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2581
2578
  sqls.push({
2582
- sql: formatDialect(`UPDATE ${tableNameESC}
2583
- SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2584
- WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }),
2579
+ sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2580
+ WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }),
2585
2581
  params: [this[_deleteState]]
2586
2582
  });
2587
2583
  }
2588
2584
  else {
2589
- sqls.push({
2590
- sql: formatDialect(`DELETE
2591
- FROM ${tableNameESC}
2592
- WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] })
2593
- });
2585
+ sqls.push({ sql: formatDialect(`DELETE FROM ${tableNameESC} WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }) });
2594
2586
  }
2595
2587
  break;
2596
2588
  }
@@ -2606,7 +2598,7 @@ export class SqlService {
2606
2598
  }
2607
2599
  return result;
2608
2600
  };
2609
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2601
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2610
2602
  return fn();
2611
2603
  }
2612
2604
  else {
@@ -2622,7 +2614,7 @@ export class SqlService {
2622
2614
  }
2623
2615
  return result;
2624
2616
  };
2625
- if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction] === true) {
2617
+ if (option.dbType === DBType.SqliteRemote || option?.conn?.[_inTransaction]) {
2626
2618
  return fn();
2627
2619
  }
2628
2620
  else {
@@ -2674,9 +2666,8 @@ export class SqlService {
2674
2666
  if (option.mode === SelectMode.Common) {
2675
2667
  const params = new Array();
2676
2668
  const whereSql = formatDialect(iterate(wheres).map(where => this[_transformer](where, option)).map(where => {
2677
- return `SELECT ${columns}
2678
- FROM ${tableNameESC} a
2679
- WHERE ${Object.entries(where).map(([K, V]) => {
2669
+ return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2670
+ ${Object.entries(where).map(([K, V]) => {
2680
2671
  params.push(V);
2681
2672
  return `${this[_fields][K]?.C2()} = ?`;
2682
2673
  }).join(' AND ')}`;
@@ -2687,21 +2678,10 @@ export class SqlService {
2687
2678
  else {
2688
2679
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2689
2680
  const delWhere = Object.keys(wheres[0]);
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
+ const _sqls = this._createTable({ tableName: tableTemp, temp: true, columns: delWhere, data: wheres, index: 'all', id: 'none' });
2698
2682
  sqls.push(..._sqls);
2699
2683
  resultIndex = sqls.length;
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
+ 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] }) });
2705
2685
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
2706
2686
  }
2707
2687
  if (option.sync === SyncMode.Sync) {
@@ -2743,8 +2723,8 @@ export class SqlService {
2743
2723
  if (dataConvert) {
2744
2724
  const key = Object.keys(result[0])[0];
2745
2725
  const value = Object.values(result[0])[0];
2746
- if (key && dataConvert[key] && globalThis[_dataConvert][dataConvert[key]]) {
2747
- return globalThis[_dataConvert][dataConvert[key]](value);
2726
+ if (key && dataConvert[key] && globalThis[_DataConvert][dataConvert[key]]) {
2727
+ return globalThis[_DataConvert][dataConvert[key]](value);
2748
2728
  }
2749
2729
  }
2750
2730
  return Object.values(result[0])[0];
@@ -2758,8 +2738,8 @@ export class SqlService {
2758
2738
  if (dataConvert) {
2759
2739
  const key = Object.keys(result[0])[0];
2760
2740
  const value = Object.values(result[0])[0];
2761
- if (key && dataConvert[key] && globalThis[_dataConvert][dataConvert[key]]) {
2762
- return globalThis[_dataConvert][dataConvert[key]](value);
2741
+ if (key && dataConvert[key] && globalThis[_DataConvert][dataConvert[key]]) {
2742
+ return globalThis[_DataConvert][dataConvert[key]](value);
2763
2743
  }
2764
2744
  }
2765
2745
  return Object.values(result[0])[0];
@@ -2776,9 +2756,9 @@ export class SqlService {
2776
2756
  }
2777
2757
  else {
2778
2758
  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;
2759
+ const __dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map(([k, v]) => [k, globalThis[_DataConvert][v]])) : undefined;
2760
+ if (hump || __dataConvert) {
2761
+ return C2P2(result[0], hump, __dataConvert) ?? null;
2782
2762
  }
2783
2763
  else {
2784
2764
  return result[0] ?? null;
@@ -2793,9 +2773,9 @@ export class SqlService {
2793
2773
  }
2794
2774
  else {
2795
2775
  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;
2776
+ const __dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map(([k, v]) => [k, globalThis[_DataConvert][v]])) : undefined;
2777
+ if (hump || __dataConvert) {
2778
+ return C2P2(data, hump, __dataConvert) ?? null;
2799
2779
  }
2800
2780
  else {
2801
2781
  return data;
@@ -2806,8 +2786,8 @@ export class SqlService {
2806
2786
  try {
2807
2787
  if (dataConvert) {
2808
2788
  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]));
2789
+ if (key && dataConvert[key] && globalThis[_DataConvert][dataConvert[key]]) {
2790
+ return result.map((r) => globalThis[_DataConvert][dataConvert[key]](Object.values(r)[0]));
2811
2791
  }
2812
2792
  }
2813
2793
  return result.map((r) => Object.values(r)[0]);
@@ -2822,9 +2802,9 @@ export class SqlService {
2822
2802
  }
2823
2803
  else {
2824
2804
  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();
2805
+ const __dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map(([k, v]) => [k, globalThis[_DataConvert][v]])) : undefined;
2806
+ if (hump || __dataConvert) {
2807
+ return iterate(result).map((r) => C2P2(r, hump, __dataConvert)).toArray();
2828
2808
  }
2829
2809
  else {
2830
2810
  return result;
@@ -2835,8 +2815,8 @@ export class SqlService {
2835
2815
  try {
2836
2816
  if (dataConvert) {
2837
2817
  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])));
2818
+ if (key && dataConvert[key] && globalThis[_DataConvert][dataConvert[key]]) {
2819
+ return new ArrayList(result.map((r) => globalThis[_DataConvert][dataConvert[key]](Object.values(r)[0])));
2840
2820
  }
2841
2821
  }
2842
2822
  return new ArrayList(result.map((r) => Object.values(r)[0]));
@@ -2855,9 +2835,9 @@ export class SqlService {
2855
2835
  }
2856
2836
  else {
2857
2837
  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());
2838
+ const __dataConvert = dataConvert ? Object.fromEntries(Object.entries(dataConvert).map(([k, v]) => [k, globalThis[_DataConvert][v]])) : undefined;
2839
+ if (hump || __dataConvert) {
2840
+ return new ArrayList(iterate(result).map((r) => C2P2(r, hump, __dataConvert)).toArray());
2861
2841
  }
2862
2842
  else {
2863
2843
  return new ArrayList();
@@ -2874,10 +2854,7 @@ export class SqlService {
2874
2854
  option.mapper = globalThis[_resultMap_SQLID][option.sqlId];
2875
2855
  }
2876
2856
  const _params = Object.assign({}, option.context, option.params);
2877
- option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2878
- ctx: option.context,
2879
- isCount: option.isCount, ..._params
2880
- }));
2857
+ option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: option.isCount, ..._params }));
2881
2858
  const { sql, params } = this._generSql(option.dbType, option.sql, _params);
2882
2859
  if (option.sync === SyncMode.Sync) {
2883
2860
  const result = option.conn.query(SyncMode.Sync, sql, params);
@@ -2944,7 +2921,7 @@ export class SqlService {
2944
2921
  };
2945
2922
  option.pageNumber ?? (option.pageNumber = 1);
2946
2923
  option.pageSize ?? (option.pageSize = 0);
2947
- if (option.hump === true || (option.hump === undefined && globalThis[_Hump] === true) && option.sortName) {
2924
+ if (option.hump || (option.hump === undefined && globalThis[_Hump]) && option.sortName) {
2948
2925
  option.sortName = P2C(option.sortName);
2949
2926
  }
2950
2927
  Object.assign(option.params, {
@@ -2953,18 +2930,11 @@ export class SqlService {
2953
2930
  sortName: option.sortName ?? undefined,
2954
2931
  sortType: option.sortType ?? undefined
2955
2932
  });
2956
- let sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2957
- ctx: option.context,
2958
- isCount: false, ...option.params
2959
- });
2933
+ let sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, ...option.params });
2960
2934
  let sqlSum = '';
2961
2935
  let sqlCount = '';
2962
- if (option.sumSelf === true) {
2963
- sqlSum = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2964
- ctx: option.context,
2965
- isCount: false,
2966
- isSum: true, ...option.params
2967
- });
2936
+ if (option.sumSelf) {
2937
+ sqlSum = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, isSum: true, ...option.params });
2968
2938
  }
2969
2939
  if (option.limitSelf !== true) {
2970
2940
  if (option.countSelf !== true) {
@@ -2974,19 +2944,11 @@ export class SqlService {
2974
2944
  }
2975
2945
  }
2976
2946
  if (option.pageSize > 0) {
2977
- if (option.countSelf === true) {
2978
- sqlCount = globalThis[_sqlCache].load(this._matchSqlid(`${option.sqlId}_count`), {
2979
- ctx: option.context,
2980
- isCount: true,
2981
- isSum: false, ...option.params
2982
- });
2947
+ if (option.countSelf) {
2948
+ sqlCount = globalThis[_sqlCache].load(this._matchSqlid(`${option.sqlId}_count`), { ctx: option.context, isCount: true, isSum: false, ...option.params });
2983
2949
  }
2984
2950
  else {
2985
- sqlCount = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), {
2986
- ctx: option.context,
2987
- isCount: true,
2988
- isSum: false, ...option.params
2989
- });
2951
+ sqlCount = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: true, isSum: false, ...option.params });
2990
2952
  }
2991
2953
  }
2992
2954
  if (option.sync === SyncMode.Sync) {
@@ -3109,7 +3071,6 @@ export class SqlService {
3109
3071
  }
3110
3072
  const lastVersion = this[_sqlite_version] ?? '0.0.1';
3111
3073
  // 检查表
3112
- // language=SQL format=false
3113
3074
  const tableCheckResult = option.conn.pluck(SyncMode.Sync, `SELECT COUNT(1) t FROM sqlite_master WHERE TYPE = 'table' AND name = ?`, [option.tableName]);
3114
3075
  if (tableCheckResult) {
3115
3076
  // 旧版本
@@ -3124,8 +3085,7 @@ export class SqlService {
3124
3085
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${rtable};`);
3125
3086
  option.conn.execute(SyncMode.Sync, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3126
3087
  option.conn.execute(SyncMode.Sync, `
3127
- CREATE TABLE IF NOT EXISTS ${tableES}
3128
- (
3088
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3129
3089
  ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3130
3090
  ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3131
3091
  );
@@ -3135,12 +3095,8 @@ export class SqlService {
3135
3095
  option.conn.execute(SyncMode.Sync, `CREATE INDEX ${`${index}_${Math.random()}`.replace(/\./, '')} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
3136
3096
  }
3137
3097
  }
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};`);
3098
+ option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3099
+ option.conn.execute(SyncMode.Sync, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3144
3100
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${rtable};`);
3145
3101
  // 更新完毕,保存版本号
3146
3102
  option.conn.execute(SyncMode.Sync, 'UPDATE TABLE_VERSION SET ______version = ? WHERE ______tableName = ?', [option.tableName, lastVersion]);
@@ -3152,11 +3108,10 @@ export class SqlService {
3152
3108
  else { // 表不存在
3153
3109
  // 创建表
3154
3110
  option.conn.execute(SyncMode.Sync, `
3155
- CREATE TABLE IF NOT EXISTS ${tableES}
3156
- (
3111
+ CREATE TABLE IF NOT EXISTS ${tableES} (
3157
3112
  ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3158
3113
  ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3159
-
3114
+
3160
3115
  );
3161
3116
  `);
3162
3117
  if (this[_index] && this[_index].length) {
@@ -3175,10 +3130,7 @@ export class SqlService {
3175
3130
  }
3176
3131
  const lastVersion = this[_sqlite_version] ?? '0.0.1';
3177
3132
  // 检查表
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]);
3133
+ const tableCheckResult = await option.conn.pluck(SyncMode.Async, `SELECT COUNT(1) t FROM sqlite_master WHERE TYPE = 'table' AND name = ?`, [option.tableName]);
3182
3134
  if (tableCheckResult) {
3183
3135
  // 旧版本
3184
3136
  const tableVersion = await option.conn.pluck(SyncMode.Async, 'SELECT ______version v from TABLE_VERSION WHERE ______tableName = ?', [option.tableName]);
@@ -3192,23 +3144,18 @@ export class SqlService {
3192
3144
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${rtable};`);
3193
3145
  await option.conn.execute(SyncMode.Async, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3194
3146
  await option.conn.execute(SyncMode.Async, `
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
- `);
3147
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3148
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3149
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3150
+ );
3151
+ `);
3201
3152
  if (this[_index] && this[_index].length) {
3202
3153
  for (const index of this[_index]) {
3203
3154
  await option.conn.execute(SyncMode.Async, `CREATE INDEX ${`${index}_${Math.random()}`.replace(/\./, '')} ON ${tableES} ("${this[_fields][index]?.C2()}");`);
3204
3155
  }
3205
3156
  }
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};`);
3157
+ await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3158
+ await option.conn.execute(SyncMode.Async, `INSERT INTO ${tableES} (${columns}) SELECT ${columns} FROM ${rtable};`);
3212
3159
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${rtable};`);
3213
3160
  // 更新完毕,保存版本号
3214
3161
  await option.conn.execute(SyncMode.Async, 'UPDATE TABLE_VERSION SET ______version = ? WHERE ______tableName = ?', [option.tableName, lastVersion]);
@@ -3220,12 +3167,11 @@ export class SqlService {
3220
3167
  else { // 表不存在
3221
3168
  // 创建表
3222
3169
  await option.conn.execute(SyncMode.Async, `
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
- `);
3170
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3171
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3172
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3173
+ );
3174
+ `);
3229
3175
  if (this[_index] && this[_index].length) {
3230
3176
  for (const index of this[_index]) {
3231
3177
  await option.conn.execute(SyncMode.Async, `CREATE INDEX ${`${index}_${Math.random()}`.replace(/\./, '')} ON ${option.tableName} ("${this[_fields][index]?.C2()}");`);
@@ -3251,16 +3197,16 @@ export class SqlService {
3251
3197
  }
3252
3198
  }
3253
3199
  /**
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
3200
+ #创建表
3201
+ ** `tableName` 表名称
3202
+ ** `temp` 是否是临时表,默认true
3203
+ ** `columns` 字符串数组,默认是当前实体类全部字段,通过`columns` 可以创建部分字段临时表
3204
+ ** `id` 表的主键设置 4种:
3205
+ 1. `auto`: `columns`中已经在当前实体类配置的ID作为主键 `默认`
3206
+ 2. `all`: `columns`中所有字段全部当主键
3207
+ 3. `none`: 没有主键
3208
+ 4. 自定义字段名称:字符串数组
3209
+ ** `index` 表的索引,设置方式同ID
3264
3210
  */
3265
3211
  _createTable({ tableName, temp = true, columns, data, id = 'auto', index = 'auto', dbType } = {}) {
3266
3212
  const sqls = [];
@@ -3294,23 +3240,17 @@ export class SqlService {
3294
3240
  tableName = tableName ?? this[_tableName];
3295
3241
  switch (dbType) {
3296
3242
  case DBType.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 });
3243
+ let sql = formatDialect(`CREATE ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3244
+ ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3245
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3246
+ ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3247
+ ) ENGINE=MEMORY;`, { dialect: mysql });
3308
3248
  sqls.push({ sql });
3309
3249
  if (data && data.length > 0) {
3310
3250
  const params = [];
3311
3251
  let first = true;
3312
3252
  sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3313
- ${(data).map(d => {
3253
+ ${(data).map(d => {
3314
3254
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3315
3255
  params.push(V);
3316
3256
  return `? ${first ? this[_fields][K]?.C2() : ''}`;
@@ -3324,12 +3264,9 @@ export class SqlService {
3324
3264
  }
3325
3265
  case DBType.Sqlite:
3326
3266
  case DBType.SqliteRemote: {
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(',')}) ` : ''}
3267
+ let sql = formatDialect(`CREATE ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3268
+ ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3269
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3333
3270
  );`, { dialect: sqlite });
3334
3271
  sqls.push({ sql });
3335
3272
  if (indexs) {
@@ -3342,7 +3279,7 @@ export class SqlService {
3342
3279
  const params = [];
3343
3280
  let first = true;
3344
3281
  sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3345
- ${(data).map(d => {
3282
+ ${(data).map(d => {
3346
3283
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3347
3284
  params.push(V);
3348
3285
  return `? ${first ? this[_fields][K]?.C2() : ''}`;
@@ -3376,7 +3313,7 @@ export class SqlService {
3376
3313
  }
3377
3314
  _generSql(dbType, _sql, _params) {
3378
3315
  const params = [];
3379
- const sql = formatDialect(_sql?.replace(/:(\w+)/g, (txt, key) => {
3316
+ const sql = formatDialect(_sql?.replace(/\:(\w+)/g, (txt, key) => {
3380
3317
  let V = LGet(_params, key);
3381
3318
  if (V !== undefined) {
3382
3319
  return this._setParam(V, params);
@@ -3535,16 +3472,10 @@ class StreamQuery {
3535
3472
  /**
3536
3473
  * AND(key1 = :value OR key2 = :value)
3537
3474
  * @param keys [key1, key2, ...]
3538
- * @param keys
3539
- * @param value
3540
3475
  */
3541
- eqs(keys, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3542
- return this.__(keys, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip });
3543
- }
3476
+ eqs(keys, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this.__(keys, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3544
3477
  /*** AND key = :value */
3545
- eq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3546
- return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip });
3547
- }
3478
+ eq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3548
3479
  /*** AND key1 = :value1 AND key2 = :value2 */
3549
3480
  eqT(t, { name: paramName = '', breakExcuteIfSkip = false } = {}) {
3550
3481
  let exe = false;
@@ -3578,272 +3509,113 @@ class StreamQuery {
3578
3509
  exe = true;
3579
3510
  }
3580
3511
  }
3581
- if (breakExcuteIfSkip && !exe) {
3512
+ if (breakExcuteIfSkip && exe === false) {
3582
3513
  this.if_exec = false;
3583
3514
  }
3584
3515
  return this;
3585
3516
  }
3586
3517
  /*** AND key <> :value */
3587
- notEq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3588
- return this._(key, value, '<>', { paramName, skipEmptyString, breakExcuteIfSkip });
3589
- }
3518
+ notEq(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '<>', { paramName, skipEmptyString, breakExcuteIfSkip }); }
3590
3519
  /** AND key1 = key2 */
3591
- eqWith(key1, key2) {
3592
- return this._key(key1, key2, '=');
3593
- }
3520
+ eqWith(key1, key2) { return this._key(key1, key2, '='); }
3594
3521
  /** AND key1 <> key2 */
3595
- notEqWith(key1, key2) {
3596
- return this._key(key1, key2, '<>');
3597
- }
3522
+ notEqWith(key1, key2) { return this._key(key1, key2, '<>'); }
3598
3523
  /** AND key REGEXP :regexp */
3599
- regexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) {
3600
- return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3601
- }
3524
+ regexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3602
3525
  /** AND key NOT REGEXP :regexp */
3603
- notRegexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) {
3604
- return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, not: 'NOT', breakExcuteIfSkip });
3605
- }
3526
+ notRegexp(key, regexp, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, not: 'NOT', breakExcuteIfSkip }); }
3606
3527
  /** AND (key1 << 8) + key2 = value */
3607
- shiftEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3608
- return this._shift(key1, key2, value, '=', { paramName, breakExcuteIfSkip });
3609
- }
3528
+ shiftEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '=', { paramName, breakExcuteIfSkip }); }
3610
3529
  /** AND (key1 << 8) + key2 <> value */
3611
- shiftNotEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3612
- return this._shift(key1, key2, value, '<>', { paramName, breakExcuteIfSkip });
3613
- }
3530
+ shiftNotEq(key1, key2, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '<>', { paramName, breakExcuteIfSkip }); }
3614
3531
  /** AND key > :value */
3615
- grate(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3616
- return this._(key, value, '>', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3617
- }
3532
+ grate(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3618
3533
  /** AND key >= :value */
3619
- grateEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3620
- return this._(key, value, '>=', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3621
- }
3534
+ grateEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3622
3535
  /** AND key1 > key2 */
3623
- grateWith(key1, key2) {
3624
- return this._key(key1, key2, '>');
3625
- }
3536
+ grateWith(key1, key2) { return this._key(key1, key2, '>'); }
3626
3537
  /** AND key1 >= key2 */
3627
- grateEqWith(key1, key2) {
3628
- return this._key(key1, key2, '>=');
3629
- }
3538
+ grateEqWith(key1, key2) { return this._key(key1, key2, '>='); }
3630
3539
  /** AND key < :value */
3631
- less(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3632
- return this._(key, value, '<', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3633
- }
3540
+ less(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3634
3541
  /** AND key <= :value */
3635
- lessEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3636
- return this._(key, value, '<=', { paramName, skipEmptyString: true, breakExcuteIfSkip });
3637
- }
3542
+ lessEq(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
3638
3543
  /** AND key1 < key2 */
3639
- lessWith(key1, key2) {
3640
- return this._key(key1, key2, '<');
3641
- }
3544
+ lessWith(key1, key2) { return this._key(key1, key2, '<'); }
3642
3545
  /** AND key1 <= key2 */
3643
- lessEqWith(key1, key2) {
3644
- return this._key(key1, key2, '<=');
3645
- }
3546
+ lessEqWith(key1, key2) { return this._key(key1, key2, '<='); }
3646
3547
  /** AND key LIKE CONCAT('%', :value, '%') */
3647
- like(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3648
- return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip });
3649
- }
3548
+ like(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip }); }
3650
3549
  /** AND key NOT LIKE CONCAT('%', :value, '%') */
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
- }
3550
+ notLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip }); }
3661
3551
  /** AND key NOT LIKE CONCAT('%', :value) */
3662
- leftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3663
- return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip });
3664
- }
3552
+ leftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip }); }
3665
3553
  /** AND key LIKE CONCAT('%', :value) */
3666
- notLeftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3667
- return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip });
3668
- }
3554
+ notLeftLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip }); }
3669
3555
  /** AND key LIKE CONCAT(:value, '%') */
3670
- rightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3671
- return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip });
3672
- }
3556
+ rightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip }); }
3673
3557
  /** AND key NOT LIKE CONCAT(:value, '%') */
3674
- notRightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3675
- return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip });
3676
- }
3558
+ notRightLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip }); }
3677
3559
  /** AND key NOT LIKE :value */
3678
- PreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3679
- return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip });
3680
- }
3560
+ PreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3681
3561
  /** AND key LIKE :value */
3682
- notPreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3683
- return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3684
- }
3562
+ notPreciseLike(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3685
3563
  /** AND key GLOB CONCAT('%', :value, '%') */
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
- }
3564
+ glob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3696
3565
  /** AND key NOT GLOB CONCAT('%', :value, '%') */
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
- }
3566
+ notGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3708
3567
  /** AND key GLOB CONCAT('%', :value) */
3709
- leftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3710
- return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip, op: 'GLOB' });
3711
- }
3568
+ leftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3712
3569
  /** AND key NOT GLOB CONCAT('%', :value) */
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
- }
3570
+ notLeftGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3723
3571
  /** AND key GLOB CONCAT(:value, '%') */
3724
- rightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3725
- return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip, op: 'GLOB' });
3726
- }
3572
+ rightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
3727
3573
  /** AND key NOT GLOB CONCAT(:value, '%') */
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
- }
3574
+ notRightGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3738
3575
  /** AND key GLOB :value */
3739
- PreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3740
- return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip, op: 'GLOB' });
3741
- }
3576
+ PreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip, op: 'GLOB' }); }
3742
3577
  /** AND key NOT GLOB :value */
3743
- notPreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3744
- return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip, op: 'GLOB' });
3745
- }
3578
+ notPreciseGlob(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
3746
3579
  /** AND key IN :value */
3747
- in(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3748
- return this._in(key, value, { paramName, breakExcuteIfSkip });
3749
- }
3580
+ in(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, breakExcuteIfSkip }); }
3750
3581
  /** AND key NOT IN :value */
3751
- notIn(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3752
- return this._in(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3753
- }
3582
+ notIn(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3754
3583
  /** AND :value IN (key1, key2, ...) */
3755
- in2(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3756
- return this._in2(key, value, { paramName, breakExcuteIfSkip });
3757
- }
3584
+ in2(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._in2(key, value, { paramName, breakExcuteIfSkip }); }
3758
3585
  /** AND :value NOT IN (key1, key2, ...) */
3759
- notIn2(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3760
- return this._in2(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3761
- }
3586
+ notIn2(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._in2(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3762
3587
  /** AND key IS NULL */
3763
- isNULL(key) {
3764
- return this._null(key);
3765
- }
3588
+ isNULL(key) { return this._null(key); }
3766
3589
  /** AND key IS NOT NULL */
3767
- isNotNULL(key) {
3768
- return this._null(key, 'NOT');
3769
- }
3590
+ isNotNULL(key) { return this._null(key, 'NOT'); }
3770
3591
  /** AND key BETWEEN :value1 AND :value2 */
3771
- between(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3772
- return this._between(key, value1, value2, { paramName, skipEmptyString, breakExcuteIfSkip });
3773
- }
3592
+ between(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3774
3593
  /** AND key NOT BETWEEN :value1 AND :value2 */
3775
- notBetween(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3776
- return this._between(key, value1, value2, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3777
- }
3594
+ notBetween(key, value1, value2, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3778
3595
  /** AND POW(2, key) & :value */
3779
- pow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3780
- return this._pow(key, value, { paramName, breakExcuteIfSkip });
3781
- }
3596
+ pow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, breakExcuteIfSkip }); }
3782
3597
  /** AND NOT POW(2, key) & :value */
3783
- notPow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) {
3784
- return this._pow(key, value, { paramName, not: 'NOT', breakExcuteIfSkip });
3785
- }
3598
+ notPow(key, value, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, not: 'NOT', breakExcuteIfSkip }); }
3786
3599
  /** AND POW(2, key1) & key2 */
3787
- powWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) {
3788
- return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, breakExcuteIfSkip });
3789
- }
3600
+ powWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, breakExcuteIfSkip }); }
3790
3601
  /** AND NOT POW(2, key1) & key2 */
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
- }
3602
+ notPowWith(key, values, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, not: 'NOT', breakExcuteIfSkip }); }
3798
3603
  /** AND MATCH(key1, key2, key3) AGAINST (:value) */
3799
- match(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3800
- return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip });
3801
- }
3604
+ match(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3802
3605
  /** AND NOT MATCH(key1, key2, key3) AGAINST (:value) */
3803
- notMatch(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3804
- return this._match(value, keys, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3805
- }
3606
+ notMatch(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3806
3607
  /** AND MATCH(key1, key2, key3) AGAINST (:value) 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
- }
3608
+ matchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'IN BOOLEAN MODE' }); }
3810
3609
  /** AND NOT MATCH(key1, key2, key3) AGAINST (:value) 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
- }
3610
+ notMatchBoolean(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'IN BOOLEAN MODE' }); }
3820
3611
  /** AND MATCH(key1, key2, key3) AGAINST (:value) 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
- }
3612
+ matchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'WITH QUERY EXPANSION' }); }
3829
3613
  /** AND NOT MATCH(key1, key2, key3) AGAINST (:value) 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
- }
3614
+ notMatchQuery(value, keys, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'WITH QUERY EXPANSION' }); }
3839
3615
  /** AND NOT LOCATE(key, :value) > 0 */
3840
- includes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3841
- return this._includes(key, value, { paramName, skipEmptyString, breakExcuteIfSkip });
3842
- }
3616
+ includes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
3843
3617
  /** AND NOT LOCATE(key, :value) = 0 */
3844
- notIncludes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
3845
- return this._includes(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip });
3846
- }
3618
+ notIncludes(key, value, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
3847
3619
  and(fn) {
3848
3620
  if (fn instanceof StreamQuery) {
3849
3621
  this._andQuerys.push(fn);
@@ -3879,76 +3651,29 @@ class StreamQuery {
3879
3651
  return this;
3880
3652
  }
3881
3653
  /** GROUP BY key1, key2, ... */
3882
- groupBy(...keys) {
3883
- this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`));
3884
- return this;
3885
- }
3654
+ groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3886
3655
  /** GROUP BY key1, key2, ... */
3887
- groupBy2(...keys) {
3888
- this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`));
3889
- return this;
3890
- }
3656
+ groupBy2(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3891
3657
  /** ORDER BY key1 ASC, key2 ASC, ... */
3892
- asc(...keys) {
3893
- this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`));
3894
- return this;
3895
- }
3658
+ asc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3896
3659
  /** ORDER BY key1 ASC, key2 ASC, ... */
3897
- asc2(...keys) {
3898
- this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`));
3899
- return this;
3900
- }
3660
+ asc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3901
3661
  /** ORDER BY key1 DESC, key2 DESC, ... */
3902
- desc(...keys) {
3903
- this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`));
3904
- return this;
3905
- }
3662
+ desc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`)); return this; }
3906
3663
  /** ORDER BY key1 DESC, key2 DESC, ... */
3907
- desc2(...keys) {
3908
- this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`));
3909
- return this;
3910
- }
3664
+ desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3911
3665
  /** LIMIT :startRow, :pageSize */
3912
- limit(startRow, pageSize) {
3913
- this._startRow = startRow;
3914
- this._pageSize = pageSize;
3915
- return this;
3916
- }
3666
+ limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
3917
3667
  /** LIMIT ((:pageNumber || 1) - 1) * :pageSize, :pageSize */
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
- }
3668
+ page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
3669
+ distinct(on = true) { this._distinct = on; return this; }
3927
3670
  /** COUNT(DISTINCT key) */
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
- }
3671
+ countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3672
+ count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
3673
+ sum(key, legName, distinct) { this._columns.push(`SUM(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3674
+ avg(key, legName, distinct) { this._columns.push(`AVG(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3675
+ max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3676
+ min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3952
3677
  /** GROUP_CONCAT([DISTINCT] key [ORDER BY :asc ASC] [ORDER BY :asc DESC] [SEPARATOR :separator]) */
3953
3678
  groupConcat(key, param) {
3954
3679
  this._columns.push(`GROUP_CONCAT(
@@ -3959,25 +3684,10 @@ class StreamQuery {
3959
3684
  ) ${param && param.groupName || `${this[_fields][String(key)]?.C2()}`}`);
3960
3685
  return this;
3961
3686
  }
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
- }
3687
+ select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
3688
+ select2(sql, param) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
3689
+ update(key, value) { this._updates ?? (this._updates = {}); this._updates[this[_fields][String(key)]?.C2()] = value; return this; }
3690
+ update2(sql, param) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
3981
3691
  updateT(t) {
3982
3692
  this._updates ?? (this._updates = {});
3983
3693
  for (const [key, value] of Object.entries(t)) {
@@ -4000,9 +3710,13 @@ class StreamQuery {
4000
3710
  option.selectResult ?? (option.selectResult = SelectResult.RS_CS);
4001
3711
  const { where, params } = this._where();
4002
3712
  let sql = `
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(',')} ` : ''}
3713
+ SELECT
3714
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3715
+ FROM ${option.tableName ?? this._service[_tableName]}
3716
+ ${where ? ' WHERE ' : ''}
3717
+ ${where}
3718
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3719
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
4006
3720
  `;
4007
3721
  if (this._startRow && this._pageSize) {
4008
3722
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -4012,138 +3726,26 @@ class StreamQuery {
4012
3726
  }
4013
3727
  if (option.sync === SyncMode.Async) {
4014
3728
  switch (option.selectResult) {
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
- });
3729
+ case SelectResult.RS_CS: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS, sql, params });
3730
+ case SelectResult.RS_C: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C, sql, params });
3731
+ case SelectResult.RS_CS_List: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS_List, sql, params });
3732
+ case SelectResult.RS_C_List: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C_List, sql, params });
3733
+ case SelectResult.R_CS_Assert: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_Assert, sql, params });
3734
+ case SelectResult.R_C_Assert: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_Assert, sql, params });
3735
+ case SelectResult.R_CS_NotSure: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_NotSure, sql, params });
3736
+ case SelectResult.R_C_NotSure: return this._service.select({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_NotSure, sql, params });
4079
3737
  }
4080
3738
  }
4081
3739
  else {
4082
3740
  switch (option.selectResult) {
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
- });
3741
+ case SelectResult.RS_CS: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS, sql, params });
3742
+ case SelectResult.RS_C: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C, sql, params });
3743
+ case SelectResult.RS_CS_List: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS_List, sql, params });
3744
+ case SelectResult.RS_C_List: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C_List, sql, params });
3745
+ case SelectResult.R_CS_Assert: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_Assert, sql, params });
3746
+ case SelectResult.R_C_Assert: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_Assert, sql, params });
3747
+ case SelectResult.R_CS_NotSure: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_NotSure, sql, params });
3748
+ case SelectResult.R_C_NotSure: return this._service.select({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_NotSure, sql, params });
4147
3749
  }
4148
3750
  }
4149
3751
  }
@@ -4157,9 +3759,13 @@ class StreamQuery {
4157
3759
  total: 0
4158
3760
  };
4159
3761
  let sql = `
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(',')} ` : ''}
3762
+ SELECT
3763
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3764
+ FROM ${option.tableName ?? this._service[_tableName]}
3765
+ ${where ? ' WHERE ' : ''}
3766
+ ${where}
3767
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3768
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
4163
3769
  `;
4164
3770
  if (this._startRow && this._pageSize) {
4165
3771
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -4169,8 +3775,11 @@ class StreamQuery {
4169
3775
  }
4170
3776
  const sqlCount = `
4171
3777
  SELECT COUNT(1)
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(',')} ` : ''}
3778
+ FROM ${option.tableName ?? this._service[_tableName]}
3779
+ ${where ? ' WHERE ' : ''}
3780
+ ${where}
3781
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3782
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
4174
3783
  `;
4175
3784
  if (option.sync === SyncMode.Sync) {
4176
3785
  result.total = this._service.select({
@@ -4237,9 +3846,9 @@ class StreamQuery {
4237
3846
  }
4238
3847
  }
4239
3848
  if (sets.length > 0) {
4240
- const sql = `UPDATE ${option.tableName ?? this._service[_tableName]}
4241
- SET ${sets.join(',')}
4242
- ${where ? ' WHERE ' : ''} ${where}
3849
+ const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
3850
+ ${where ? ' WHERE ' : ''}
3851
+ ${where}
4243
3852
  `;
4244
3853
  if (option.sync === SyncMode.Async) {
4245
3854
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -4256,8 +3865,9 @@ class StreamQuery {
4256
3865
  option ?? (option = {});
4257
3866
  option.sync ?? (option.sync = SyncMode.Async);
4258
3867
  const { where, params } = this._where();
4259
- const sql = `DELETE
4260
- FROM ${option.tableName ?? this._service[_tableName]} ${where ? ' WHERE ' : ''} ${where}
3868
+ const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
3869
+ ${where ? ' WHERE ' : ''}
3870
+ ${where}
4261
3871
  `;
4262
3872
  if (option.sync === SyncMode.Async) {
4263
3873
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -4346,7 +3956,11 @@ class StreamQuery {
4346
3956
  }
4347
3957
  _between(key, value1, value2, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
4348
3958
  if (value1 === null
4349
- || value1 === undefined || (emptyString(`${value1 ?? ''}`) && skipEmptyString) || value2 === null || value2 === undefined || (emptyString(`${value2 ?? ''}`) && skipEmptyString)) {
3959
+ || value1 === undefined
3960
+ || (emptyString(`${value1 ?? ''}`) && skipEmptyString)
3961
+ || value2 === null
3962
+ || value2 === undefined
3963
+ || (emptyString(`${value2 ?? ''}`) && skipEmptyString)) {
4350
3964
  if (breakExcuteIfSkip) {
4351
3965
  this.if_exec = false;
4352
3966
  }
@@ -4384,7 +3998,7 @@ class StreamQuery {
4384
3998
  }
4385
3999
  }
4386
4000
  }
4387
- else if (!breakExcuteIfSkip) {
4001
+ else if (breakExcuteIfSkip !== true) {
4388
4002
  this.if_exec = false;
4389
4003
  }
4390
4004
  return this;
@@ -4404,7 +4018,7 @@ class StreamQuery {
4404
4018
  }
4405
4019
  }
4406
4020
  }
4407
- else if (!breakExcuteIfSkip) {
4021
+ else if (breakExcuteIfSkip !== true) {
4408
4022
  this.if_exec = false;
4409
4023
  }
4410
4024
  return this;
@@ -5072,6 +4686,7 @@ export async function GetRedisLock(key, lockMaxActive) {
5072
4686
  }
5073
4687
  }
5074
4688
  }
4689
+ ;
5075
4690
  /** 对FN加锁、缓存执行 */
5076
4691
  export async function excuteWithLock(config, fn__) {
5077
4692
  const key = `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
@@ -5079,7 +4694,7 @@ export async function excuteWithLock(config, fn__) {
5079
4694
  let wait_time = 0;
5080
4695
  const fn = async () => {
5081
4696
  const lock = await GetRedisLock(key, config.lockMaxActive);
5082
- if (!lock) {
4697
+ if (lock === false) {
5083
4698
  if (config.lockWait !== false && ((config.lockMaxWaitTime ?? 0) === 0 || (wait_time + (config.lockRetryInterval ?? 100)) <= (config.lockMaxWaitTime ?? 0))) {
5084
4699
  logger.debug(`get lock ${key} fail, retry after ${config.lockRetryInterval ?? 100}ms...`);
5085
4700
  await sleep(config.lockRetryInterval ?? 100);
@@ -5160,7 +4775,7 @@ export async function clearMethodCache(key) {
5160
4775
  }
5161
4776
  async function clearChild(key, skipDel = false) {
5162
4777
  const db = getRedisDB();
5163
- if (!skipDel) {
4778
+ if (skipDel === false) {
5164
4779
  await db.del(`[cache]${key}`);
5165
4780
  }
5166
4781
  const childtype = await db.type(`[cache-child]${key}`);
@@ -5299,12 +4914,15 @@ class MUParser {
5299
4914
  if (line.startsWith('*')) {
5300
4915
  // 注释符号
5301
4916
  findComment = true;
4917
+ continue;
5302
4918
  }
5303
4919
  else {
5304
4920
  if (line.length === 0) {
4921
+ continue;
5305
4922
  }
5306
4923
  else if (line.startsWith('```') || line.startsWith('~~~')) {
5307
4924
  // 忽略以code block开头的符号
4925
+ continue;
5308
4926
  }
5309
4927
  else {
5310
4928
  // 注释结束