baja-lite 1.3.46 → 1.3.48

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/code.js +38 -37
  2. package/package.json +6 -6
  3. package/sql.d.ts +1 -1
  4. package/sql.js +191 -187
package/code.js CHANGED
@@ -55,7 +55,7 @@ const templatePath = path.join(basepath, 'code-template');
55
55
  console.log(`
56
56
  **********************-----------
57
57
  配置文件:
58
- 请在项目根目录添加文件:baja.code.json!配置如下:
58
+ 请在项目根目录添加文件:baja.code.json!配置示例:
59
59
  {
60
60
  "host": "",
61
61
  "port": "",
@@ -91,40 +91,41 @@ console.log(`
91
91
  **********************-----------
92
92
  **********************-----------
93
93
  模板文件
94
- 请在项目根目录的code-template添加模板文件, 按照mustache(标签定义成了[ '<%', '%>' ])进行格式化,变量:
95
- title,
94
+ 请在项目根目录的code-template添加模板文件, 按照mustache(标签定义成了[ '<%', '%>' ])进行格式化,支持使用的变量:
95
+ ************* 以下假设表名为event_main_info,列名为sku_id,sku_name
96
+ title // 字符串,表的注释
96
97
 
97
- tableName, event_main_info
98
- className, eventMainInfo
99
- ClassName, EventMainInfo
100
- vueName, event-main-info
101
- splitVueName, event/main-info
102
- splitName, event/main/info
103
- SplitName, event/mainInfo
98
+ tableName // 字符串,event_main_info
99
+ className // 字符串,eventMainInfo
100
+ ClassName // 字符串,EventMainInfo
101
+ vueName // 字符串,event-main-info
102
+ splitVueName // 字符串,event/main-info
103
+ splitName // 字符串,event/main/info
104
+ SplitName // 字符串,event/mainInfo
104
105
 
105
- columns: [
106
- comment:
107
- name: sku_id
108
- Name: skuId
109
- NAME: SkuId
110
- Field
111
- Type
112
- ], Field(类型string),表示字段的注解, Type 表示JS类型
113
- columnNames_join: 'sku_id, sku_name'
114
- ColumnNames_join: 'sku_id skuId, sku_name skuName'
115
- columnNames_joinT: 't.sku_id, t.sku_name'
116
- ColumnNames_joinT: 't.sku_id skuId, t.sku_name skuName'
117
- columns_no_id: [], 同columns,没有ID而已
118
- columnNames_no_id: [],
106
+ columns // 数组, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,Type:表示JS类型}
107
+ column_names // 数组, 元素是列名字符串,格式是 sku_id,sku_name
108
+ ColumnNames // 数组, 元素是列名字符串,格式是 skuId,skuName
109
+ column_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
110
+ ColumnNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
111
+ column_names_joinT // 字符串,列名join的字符串,格式是 "t.sku_id,t.sku_name"
112
+ ColumnNames_joinT // 字符串,列名join的字符串,格式是 "t.skuId,t.skuName"
113
+ columns_no_id // 数组, 不含主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,Type:表示JS类型}
114
+ column_names_no_id // 数组, 不含主键, 元素是列名字符串,格式是 sku_id,sku_name
115
+ ColumnNames_no_id // 数组, 不含主键, 元素是列名字符串,格式是 skuId,skuName
116
+ column_names_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "sku_id,sku_name"
117
+ ColumnNames_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "skuId,skuName"
119
118
 
120
- ids: [], 参见 FieldOption,多一个参数Field,表示字段的注解, Type 表示JS类型
121
- idNames: [], 主键字段数组
122
- idNames_join: []
119
+ ids // 数组, 只有主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,Type:表示JS类型}
120
+ id_names // 数组, 只有主键, 元素是列名字符串,格式是 sku_id,sku_name
121
+ IdNames // 数组, 只有主键, 元素是列名字符串,格式是 skuId,skuName
122
+ id_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
123
+ IdNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
123
124
 
124
- modelName: 模块名称,可能为空字符串 event
125
- modelPath: 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
125
+ modelName // 推断出的模块名称,可能为空字符串, 如果表名为event_main_info, 则模块为 event
126
+ modelPath // 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
126
127
 
127
- logicDelete: 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
128
+ logicDelete // 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
128
129
  -----
129
130
  命令 table1,table2,table3:模块名称
130
131
  table=. 表示扫描全库表
@@ -275,21 +276,21 @@ try {
275
276
  splitName,
276
277
  SplitName,
277
278
  columns,
278
- columnNames: columns?.map(i => i.name),
279
+ column_names: columns?.map(i => i.name),
279
280
  ColumnNames: columns?.map(i => i.Name),
280
- columnNames_join: columns?.map(i => i.name).join(','),
281
+ column_names_join: columns?.map(i => i.name).join(','),
281
282
  ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
282
- columnNames_joinT: columns?.map(i => `t.${i.name}`).join(','),
283
+ column_names_joinT: columns?.map(i => `t.${i.name}`).join(','),
283
284
  ColumnNames_joinT: columns?.map(i => `t.${i.name} ${i.Name}`).join(','),
284
285
  columns_no_id: columns?.filter(i => !i.id),
285
- columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
286
+ column_names_no_id: columns?.filter(i => !i.id).map(i => i.name),
286
287
  ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
287
- columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
288
+ column_names_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
288
289
  ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
289
290
  ids: columns?.filter(i => i.id),
290
- idNames: columns?.filter(i => i.id).map(i => i.name),
291
+ id_names: columns?.filter(i => i.id).map(i => i.name),
291
292
  IdNames: columns?.filter(i => i.id).map(i => i.Name),
292
- idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
293
+ id_names_join: columns?.filter(i => i.id).map(i => i.name).join(','),
293
294
  IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
294
295
  modelName,
295
296
  modelPath,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.3.46",
3
+ "version": "1.3.48",
4
4
  "description": "some util for self",
5
- "homepage": "https://github.com/void-soul/util-man",
5
+ "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/void-soul/util-man.git"
8
+ "url": "https://github.com/void-soul/baja-lite.git"
9
9
  },
10
10
  "license": "MIT",
11
11
  "author": "void-soul",
@@ -44,12 +44,12 @@
44
44
  "iterare": "1.2.1",
45
45
  "lodash.get": "4.4.2",
46
46
  "mustache": "4.2.0",
47
- "pino": "9.6.0",
47
+ "pino": "9.7.0",
48
48
  "pino-pretty": "13.0.0",
49
49
  "reflect-metadata": "0.2.2",
50
50
  "request": "2.88.2",
51
51
  "request-promise": "4.2.6",
52
- "sql-formatter": "15.6.1",
52
+ "sql-formatter": "15.6.2",
53
53
  "sqlstring": "2.3.3",
54
54
  "tslib": "2.8.1"
55
55
  },
@@ -57,7 +57,7 @@
57
57
  "@types/better-sqlite3": "7.6.13",
58
58
  "@types/lodash.get": "4.4.9",
59
59
  "@types/mustache": "4.2.6",
60
- "@types/node": "22.15.18",
60
+ "@types/node": "22.15.21",
61
61
  "@types/pg-pool": "2.0.6",
62
62
  "@types/shelljs": "0.8.16",
63
63
  "@types/sqlstring": "2.3.2",
package/sql.d.ts CHANGED
@@ -1728,7 +1728,7 @@ declare class StreamQuery<T extends object> {
1728
1728
  }
1729
1729
  /**
1730
1730
  获取REDIS客户端,
1731
- # [查看库的API](https://github.com/redis/ioredis?tab=readme-ov-file)
1731
+ # [查看库的API](https://redis.github.io/ioredis/)
1732
1732
  # [REDIS API](http://doc.redisfans.com/)
1733
1733
  REDIS 的API 可以直接用,将方法名转为小写
1734
1734
  ```
package/sql.js CHANGED
@@ -236,10 +236,10 @@ class MysqlConnection {
236
236
  resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
237
237
  }
238
238
  catch (error) {
239
- logger.error(`
240
- error: ${error},
241
- sql: ${sql},
242
- params: ${params}
239
+ logger.error(`
240
+ error: ${error},
241
+ sql: ${sql},
242
+ params: ${params}
243
243
  `);
244
244
  reject(error);
245
245
  }
@@ -272,10 +272,10 @@ class MysqlConnection {
272
272
  resolve(null);
273
273
  }
274
274
  catch (error) {
275
- logger.error(`
276
- error: ${error},
277
- sql: ${sql},
278
- params: ${params}
275
+ logger.error(`
276
+ error: ${error},
277
+ sql: ${sql},
278
+ params: ${params}
279
279
  `);
280
280
  reject(error);
281
281
  }
@@ -306,10 +306,10 @@ class MysqlConnection {
306
306
  resolve(null);
307
307
  }
308
308
  catch (error) {
309
- logger.error(`
310
- error: ${error},
311
- sql: ${sql},
312
- params: ${params}
309
+ logger.error(`
310
+ error: ${error},
311
+ sql: ${sql},
312
+ params: ${params}
313
313
  `);
314
314
  reject(error);
315
315
  }
@@ -340,10 +340,10 @@ class MysqlConnection {
340
340
  resolve([]);
341
341
  }
342
342
  catch (error) {
343
- logger.error(`
344
- error: ${error},
345
- sql: ${sql},
346
- params: ${params}
343
+ logger.error(`
344
+ error: ${error},
345
+ sql: ${sql},
346
+ params: ${params}
347
347
  `);
348
348
  reject(error);
349
349
  }
@@ -372,10 +372,10 @@ class MysqlConnection {
372
372
  resolve(result);
373
373
  }
374
374
  catch (error) {
375
- logger.error(`
376
- error: ${error},
377
- sql: ${sql},
378
- params: ${params}
375
+ logger.error(`
376
+ error: ${error},
377
+ sql: ${sql},
378
+ params: ${params}
379
379
  `);
380
380
  reject(error);
381
381
  }
@@ -519,10 +519,10 @@ class PostgresqlConnection {
519
519
  resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
520
520
  }
521
521
  catch (error) {
522
- logger.error(`
523
- error: ${error},
524
- sql: ${sql},
525
- params: ${params}
522
+ logger.error(`
523
+ error: ${error},
524
+ sql: ${sql},
525
+ params: ${params}
526
526
  `);
527
527
  reject(error);
528
528
  }
@@ -559,10 +559,10 @@ class PostgresqlConnection {
559
559
  resolve(null);
560
560
  }
561
561
  catch (error) {
562
- logger.error(`
563
- error: ${error},
564
- sql: ${sql},
565
- params: ${params}
562
+ logger.error(`
563
+ error: ${error},
564
+ sql: ${sql},
565
+ params: ${params}
566
566
  `);
567
567
  reject(error);
568
568
  }
@@ -597,10 +597,10 @@ class PostgresqlConnection {
597
597
  resolve(null);
598
598
  }
599
599
  catch (error) {
600
- logger.error(`
601
- error: ${error},
602
- sql: ${sql},
603
- params: ${params}
600
+ logger.error(`
601
+ error: ${error},
602
+ sql: ${sql},
603
+ params: ${params}
604
604
  `);
605
605
  reject(error);
606
606
  }
@@ -635,10 +635,10 @@ class PostgresqlConnection {
635
635
  resolve([]);
636
636
  }
637
637
  catch (error) {
638
- logger.error(`
639
- error: ${error},
640
- sql: ${sql},
641
- params: ${params}
638
+ logger.error(`
639
+ error: ${error},
640
+ sql: ${sql},
641
+ params: ${params}
642
642
  `);
643
643
  reject(error);
644
644
  }
@@ -671,10 +671,10 @@ class PostgresqlConnection {
671
671
  resolve(rows);
672
672
  }
673
673
  catch (error) {
674
- logger.error(`
675
- error: ${error},
676
- sql: ${sql},
677
- params: ${params}
674
+ logger.error(`
675
+ error: ${error},
676
+ sql: ${sql},
677
+ params: ${params}
678
678
  `);
679
679
  reject(error);
680
680
  }
@@ -813,10 +813,10 @@ class SqliteConnection {
813
813
  return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
814
814
  }
815
815
  catch (error) {
816
- logger.error(`
817
- error: ${error},
818
- sql: ${sql},
819
- params: ${params}
816
+ logger.error(`
817
+ error: ${error},
818
+ sql: ${sql},
819
+ params: ${params}
820
820
  `);
821
821
  throw error;
822
822
  }
@@ -839,10 +839,10 @@ class SqliteConnection {
839
839
  return this[_daoConnection].prepare(sql).pluck().get(params ?? {});
840
840
  }
841
841
  catch (error) {
842
- logger.error(`
843
- error: ${error},
844
- sql: ${sql},
845
- params: ${params}
842
+ logger.error(`
843
+ error: ${error},
844
+ sql: ${sql},
845
+ params: ${params}
846
846
  `);
847
847
  throw error;
848
848
  }
@@ -864,10 +864,10 @@ class SqliteConnection {
864
864
  return this[_daoConnection].prepare(sql).get(params ?? {});
865
865
  }
866
866
  catch (error) {
867
- logger.error(`
868
- error: ${error},
869
- sql: ${sql},
870
- params: ${params}
867
+ logger.error(`
868
+ error: ${error},
869
+ sql: ${sql},
870
+ params: ${params}
871
871
  `);
872
872
  throw error;
873
873
  }
@@ -890,10 +890,10 @@ class SqliteConnection {
890
890
  return this[_daoConnection].prepare(sql).raw().all(params ?? {});
891
891
  }
892
892
  catch (error) {
893
- logger.error(`
894
- error: ${error},
895
- sql: ${sql},
896
- params: ${params}
893
+ logger.error(`
894
+ error: ${error},
895
+ sql: ${sql},
896
+ params: ${params}
897
897
  `);
898
898
  throw error;
899
899
  }
@@ -916,10 +916,10 @@ class SqliteConnection {
916
916
  return this[_daoConnection].prepare(sql).all(params ?? {});
917
917
  }
918
918
  catch (error) {
919
- logger.error(`
920
- error: ${error},
921
- sql: ${sql},
922
- params: ${params}
919
+ logger.error(`
920
+ error: ${error},
921
+ sql: ${sql},
922
+ params: ${params}
923
923
  `);
924
924
  throw error;
925
925
  }
@@ -932,15 +932,15 @@ export class Sqlite {
932
932
  constructor(db) {
933
933
  this[_daoDB] = db;
934
934
  this[_daoDB].pragma('journal_mode = WAL');
935
- this[_daoDB].exec(`
936
- CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
937
- DELETE FROM DUAL;
938
- INSERT INTO DUAL (______id ) VALUES ( 1 );
939
- CREATE TABLE IF NOT EXISTS TABLE_VERSION (
940
- ______tableName text NOT NULL,
941
- ______version text NOT NULL,
942
- PRIMARY KEY ( ______tableName )
943
- );
935
+ this[_daoDB].exec(`
936
+ CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
937
+ DELETE FROM DUAL;
938
+ INSERT INTO DUAL (______id ) VALUES ( 1 );
939
+ CREATE TABLE IF NOT EXISTS TABLE_VERSION (
940
+ ______tableName text NOT NULL,
941
+ ______version text NOT NULL,
942
+ PRIMARY KEY ( ______tableName )
943
+ );
944
944
  `);
945
945
  }
946
946
  createConnection(sync) {
@@ -1017,10 +1017,10 @@ export class SqliteRemoteConnection {
1017
1017
  resolve({ affectedRows, insertId: insertId ? BigInt(insertId) : 0n });
1018
1018
  }
1019
1019
  catch (error) {
1020
- logger.error(`
1021
- error: ${error},
1022
- sql: ${sql},
1023
- params: ${params}
1020
+ logger.error(`
1021
+ error: ${error},
1022
+ sql: ${sql},
1023
+ params: ${params}
1024
1024
  `);
1025
1025
  reject(error);
1026
1026
  }
@@ -1047,10 +1047,10 @@ export class SqliteRemoteConnection {
1047
1047
  resolve(r);
1048
1048
  }
1049
1049
  catch (error) {
1050
- logger.error(`
1051
- error: ${error},
1052
- sql: ${sql},
1053
- params: ${params}
1050
+ logger.error(`
1051
+ error: ${error},
1052
+ sql: ${sql},
1053
+ params: ${params}
1054
1054
  `);
1055
1055
  reject(error);
1056
1056
  }
@@ -1077,10 +1077,10 @@ export class SqliteRemoteConnection {
1077
1077
  resolve(r);
1078
1078
  }
1079
1079
  catch (error) {
1080
- logger.error(`
1081
- error: ${error},
1082
- sql: ${sql},
1083
- params: ${params}
1080
+ logger.error(`
1081
+ error: ${error},
1082
+ sql: ${sql},
1083
+ params: ${params}
1084
1084
  `);
1085
1085
  reject(error);
1086
1086
  }
@@ -1107,10 +1107,10 @@ export class SqliteRemoteConnection {
1107
1107
  resolve(r);
1108
1108
  }
1109
1109
  catch (error) {
1110
- logger.error(`
1111
- error: ${error},
1112
- sql: ${sql},
1113
- params: ${params}
1110
+ logger.error(`
1111
+ error: ${error},
1112
+ sql: ${sql},
1113
+ params: ${params}
1114
1114
  `);
1115
1115
  reject(error);
1116
1116
  }
@@ -1137,10 +1137,10 @@ export class SqliteRemoteConnection {
1137
1137
  resolve(r);
1138
1138
  }
1139
1139
  catch (error) {
1140
- logger.error(`
1141
- error: ${error},
1142
- sql: ${sql},
1143
- params: ${params}
1140
+ logger.error(`
1141
+ error: ${error},
1142
+ sql: ${sql},
1143
+ params: ${params}
1144
1144
  `);
1145
1145
  reject(error);
1146
1146
  }
@@ -1466,8 +1466,8 @@ class Build {
1466
1466
  if (MapName && Column) {
1467
1467
  const map = globalThis[_enum].EnumMap(MapName.trim());
1468
1468
  if (map) {
1469
- return ` CASE
1470
- ${Object.entries(map).map(([k, v]) => `WHEN ${Column} = '${k}' THEN '${v}'`).join(' ')}
1469
+ return ` CASE
1470
+ ${Object.entries(map).map(([k, v]) => `WHEN ${Column} = '${k}' THEN '${v}'`).join(' ')}
1471
1471
  END `;
1472
1472
  }
1473
1473
  }
@@ -1776,9 +1776,10 @@ function P(skipConn = false) {
1776
1776
  }
1777
1777
  catch (error) {
1778
1778
  try {
1779
- console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1779
+ console.error(`service ${propertyKey} have an error:${error}`);
1780
1780
  }
1781
1781
  catch (error) {
1782
+ console.error(`${option.tableName} service ${propertyKey} have an error:${error}`);
1782
1783
  }
1783
1784
  throw error;
1784
1785
  }
@@ -1817,7 +1818,8 @@ function P(skipConn = false) {
1817
1818
  resolve(result);
1818
1819
  }
1819
1820
  catch (error) {
1820
- console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1821
+ // console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`)
1822
+ console.error(`${option.tableName} service ${propertyKey} have an error:${error}`);
1821
1823
  reject(error);
1822
1824
  }
1823
1825
  finally {
@@ -1847,7 +1849,8 @@ function P(skipConn = false) {
1847
1849
  resolve(result);
1848
1850
  }
1849
1851
  catch (error) {
1850
- console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1852
+ // console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`)
1853
+ console.error(`${option.tableName} service ${propertyKey} have an error:${error}`);
1851
1854
  reject(error);
1852
1855
  }
1853
1856
  finally {
@@ -1877,7 +1880,8 @@ function P(skipConn = false) {
1877
1880
  resolve(result);
1878
1881
  }
1879
1882
  catch (error) {
1880
- console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1883
+ //console.error(`service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`)
1884
+ console.error(`${option.tableName} service ${propertyKey} have an error:${error}`);
1881
1885
  reject(error);
1882
1886
  }
1883
1887
  finally {
@@ -2131,9 +2135,9 @@ export class SqlService {
2131
2135
  return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2132
2136
  });
2133
2137
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2134
- const sql = formatDialect(`INSERT INTO
2135
- ${tableName}
2136
- (${columnNames})
2138
+ const sql = formatDialect(`INSERT INTO
2139
+ ${tableName}
2140
+ (${columnNames})
2137
2141
  ${questMarks.join(' UNION ALL ')};`, { dialect: formatDialects[option.dbType] });
2138
2142
  sqls.push({ sql, params });
2139
2143
  break;
@@ -2190,11 +2194,11 @@ export class SqlService {
2190
2194
  return `(${questMark.join(',')})`;
2191
2195
  });
2192
2196
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2193
- const sql = formatDialect(`
2194
- ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2195
- ${tableName}
2196
- (${columnNames})
2197
- VALUES ${questMarks};
2197
+ const sql = formatDialect(`
2198
+ ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2199
+ ${tableName}
2200
+ (${columnNames})
2201
+ VALUES ${questMarks};
2198
2202
  `, { dialect: formatDialects[option.dbType] });
2199
2203
  sqls.push({ sql, params });
2200
2204
  break;
@@ -2251,11 +2255,11 @@ export class SqlService {
2251
2255
  return `(${questMark.join(',')})`;
2252
2256
  });
2253
2257
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2254
- const sql = formatDialect(`
2255
- INSERT INTO
2256
- ${tableName}
2257
- (${columnNames})
2258
- VALUES ${questMarks};
2258
+ const sql = formatDialect(`
2259
+ INSERT INTO
2260
+ ${tableName}
2261
+ (${columnNames})
2262
+ VALUES ${questMarks};
2259
2263
  `, { dialect: formatDialects[option.dbType] });
2260
2264
  sqls.push({ sql, params });
2261
2265
  break;
@@ -2318,15 +2322,15 @@ export class SqlService {
2318
2322
  sqls.push(..._sqls);
2319
2323
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2320
2324
  sqls.push({
2321
- sql: formatDialect(`
2322
- INSERT INTO
2323
- ${tableTemp}
2324
- (${columnNames})
2325
- VALUES ${questMarks};
2325
+ sql: formatDialect(`
2326
+ INSERT INTO
2327
+ ${tableTemp}
2328
+ (${columnNames})
2329
+ VALUES ${questMarks};
2326
2330
  `, { dialect: formatDialects[option.dbType] }), params
2327
2331
  });
2328
2332
  sqls.push({
2329
- sql: formatDialect(`INSERT INTO ${option.tableName} (${columnNames})
2333
+ sql: formatDialect(`INSERT INTO ${option.tableName} (${columnNames})
2330
2334
  SELECT ${columnNames} FROM ${tableTemp};`, { dialect: formatDialects[option.dbType] })
2331
2335
  });
2332
2336
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
@@ -2517,19 +2521,19 @@ export class SqlService {
2517
2521
  if (option.mode === DeleteMode.Common) {
2518
2522
  const params = new Array();
2519
2523
  const whereSql = iterate(wheres).map(where => {
2520
- return `(
2524
+ return `(
2521
2525
  ${Object.entries(where).map(([K, V]) => {
2522
2526
  params.push(V);
2523
2527
  return `${this[_fields][K]?.C2()} = ?`;
2524
- }).join(' AND ')}
2528
+ }).join(' AND ')}
2525
2529
  )`;
2526
2530
  }).join(' OR ');
2527
2531
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2528
2532
  params.unshift(this[_deleteState]);
2529
2533
  sqls.push({
2530
- sql: formatDialect(`
2531
- UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2532
- WHERE ${whereSql};
2534
+ sql: formatDialect(`
2535
+ UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2536
+ WHERE ${whereSql};
2533
2537
  `, { dialect: formatDialects[option.dbType] }), params
2534
2538
  });
2535
2539
  }
@@ -2546,7 +2550,7 @@ export class SqlService {
2546
2550
  case DBType.Mysql: {
2547
2551
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2548
2552
  sqls.push({
2549
- 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 ')}
2553
+ 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 ')}
2550
2554
  SET a.${this[_fields][this[_stateFileName]]?.C2()} = ?;`, { dialect: formatDialects[option.dbType] }),
2551
2555
  params: [this[_deleteState]]
2552
2556
  });
@@ -2563,7 +2567,7 @@ export class SqlService {
2563
2567
  const columnNames = iterate(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2564
2568
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2565
2569
  sqls.push({
2566
- sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2570
+ sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2567
2571
  WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }),
2568
2572
  params: [this[_deleteState]]
2569
2573
  });
@@ -2653,7 +2657,7 @@ export class SqlService {
2653
2657
  if (option.mode === SelectMode.Common) {
2654
2658
  const params = new Array();
2655
2659
  const whereSql = formatDialect(iterate(wheres).map(where => this[_transformer](where, option)).map(where => {
2656
- return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2660
+ return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2657
2661
  ${Object.entries(where).map(([K, V]) => {
2658
2662
  params.push(V);
2659
2663
  return `${this[_fields][K]?.C2()} = ?`;
@@ -3025,11 +3029,11 @@ export class SqlService {
3025
3029
  const rtable = `${option.tableName}_${tableVersion.replace(/\./, '_')}`;
3026
3030
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${rtable};`);
3027
3031
  option.conn.execute(SyncMode.Sync, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3028
- option.conn.execute(SyncMode.Sync, `
3029
- CREATE TABLE IF NOT EXISTS ${tableES}(
3030
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3031
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3032
- );
3032
+ option.conn.execute(SyncMode.Sync, `
3033
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3034
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3035
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3036
+ );
3033
3037
  `);
3034
3038
  if (this[_index] && this[_index].length) {
3035
3039
  for (const index of this[_index]) {
@@ -3048,12 +3052,12 @@ export class SqlService {
3048
3052
  }
3049
3053
  else { // 表不存在
3050
3054
  // 创建表
3051
- option.conn.execute(SyncMode.Sync, `
3052
- CREATE TABLE IF NOT EXISTS ${tableES} (
3053
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3054
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3055
-
3056
- );
3055
+ option.conn.execute(SyncMode.Sync, `
3056
+ CREATE TABLE IF NOT EXISTS ${tableES} (
3057
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3058
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3059
+
3060
+ );
3057
3061
  `);
3058
3062
  if (this[_index] && this[_index].length) {
3059
3063
  for (const index of this[_index]) {
@@ -3084,11 +3088,11 @@ export class SqlService {
3084
3088
  const rtable = `${option.tableName}_${tableVersion.replace(/\./, '_')}`;
3085
3089
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${rtable};`);
3086
3090
  await option.conn.execute(SyncMode.Async, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3087
- await option.conn.execute(SyncMode.Async, `
3088
- CREATE TABLE IF NOT EXISTS ${tableES}(
3089
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3090
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3091
- );
3091
+ await option.conn.execute(SyncMode.Async, `
3092
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3093
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3094
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3095
+ );
3092
3096
  `);
3093
3097
  if (this[_index] && this[_index].length) {
3094
3098
  for (const index of this[_index]) {
@@ -3107,11 +3111,11 @@ export class SqlService {
3107
3111
  }
3108
3112
  else { // 表不存在
3109
3113
  // 创建表
3110
- await option.conn.execute(SyncMode.Async, `
3111
- CREATE TABLE IF NOT EXISTS ${tableES}(
3112
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3113
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3114
- );
3114
+ await option.conn.execute(SyncMode.Async, `
3115
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3116
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3117
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3118
+ );
3115
3119
  `);
3116
3120
  if (this[_index] && this[_index].length) {
3117
3121
  for (const index of this[_index]) {
@@ -3181,16 +3185,16 @@ export class SqlService {
3181
3185
  tableName = tableName ?? this[_tableName];
3182
3186
  switch (dbType) {
3183
3187
  case DBType.Mysql: {
3184
- let sql = formatDialect(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3185
- ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3186
- ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3187
- ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3188
+ let sql = formatDialect(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3189
+ ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3190
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3191
+ ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3188
3192
  ) ENGINE=MEMORY;`, { dialect: mysql });
3189
3193
  sqls.push({ sql });
3190
3194
  if (data && data.length > 0) {
3191
3195
  const params = [];
3192
3196
  let first = true;
3193
- sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3197
+ sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3194
3198
  ${(data).map(d => {
3195
3199
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3196
3200
  params.push(V);
@@ -3205,9 +3209,9 @@ export class SqlService {
3205
3209
  }
3206
3210
  case DBType.Sqlite:
3207
3211
  case DBType.SqliteRemote: {
3208
- let sql = formatDialect(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3209
- ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3210
- ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3212
+ let sql = formatDialect(`CREATE ${temp === true ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3213
+ ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3214
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3211
3215
  );`, { dialect: sqlite });
3212
3216
  sqls.push({ sql });
3213
3217
  if (indexs) {
@@ -3219,7 +3223,7 @@ export class SqlService {
3219
3223
  if (data && data.length > 0) {
3220
3224
  const params = [];
3221
3225
  let first = true;
3222
- sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3226
+ sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3223
3227
  ${(data).map(d => {
3224
3228
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3225
3229
  params.push(V);
@@ -3557,11 +3561,11 @@ class StreamQuery {
3557
3561
  max(key, legName, distinct) { this._columns.push(`MAX(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3558
3562
  min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}) ${legName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
3559
3563
  groupConcat(key, param) {
3560
- this._columns.push(`GROUP_CONCAT(
3561
- ${param && param.distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}
3562
- ${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `${this[_fields][String(i)]?.C2()} ASC`)} ` : ''}
3563
- ${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `${this[_fields][String(i)]?.C2()} DESC`)} ` : ''}
3564
- SEPARATOR '${param && param.separator || ','}'
3564
+ this._columns.push(`GROUP_CONCAT(
3565
+ ${param && param.distinct ? 'DISTINCT' : ''} ${this[_fields][String(key)]?.C2()}
3566
+ ${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `${this[_fields][String(i)]?.C2()} ASC`)} ` : ''}
3567
+ ${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `${this[_fields][String(i)]?.C2()} DESC`)} ` : ''}
3568
+ SEPARATOR '${param && param.separator || ','}'
3565
3569
  ) ${param && param.groupName || `${this[_fields][String(key)]?.C2()}`}`);
3566
3570
  return this;
3567
3571
  }
@@ -3589,14 +3593,14 @@ class StreamQuery {
3589
3593
  option.sync ?? (option.sync = SyncMode.Async);
3590
3594
  option.selectResult ?? (option.selectResult = SelectResult.RS_CS);
3591
3595
  const { where, params } = this._where();
3592
- let sql = `
3593
- SELECT
3594
- ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3595
- FROM ${option.tableName ?? this._service[_tableName]}
3596
- ${where ? ' WHERE ' : ''}
3597
- ${where}
3598
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3599
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3596
+ let sql = `
3597
+ SELECT
3598
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3599
+ FROM ${option.tableName ?? this._service[_tableName]}
3600
+ ${where ? ' WHERE ' : ''}
3601
+ ${where}
3602
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3603
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3600
3604
  `;
3601
3605
  if (this._startRow && this._pageSize) {
3602
3606
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3638,14 +3642,14 @@ class StreamQuery {
3638
3642
  size: 0,
3639
3643
  total: 0
3640
3644
  };
3641
- let sql = `
3642
- SELECT
3643
- ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3644
- FROM ${option.tableName ?? this._service[_tableName]}
3645
- ${where ? ' WHERE ' : ''}
3646
- ${where}
3647
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3648
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3645
+ let sql = `
3646
+ SELECT
3647
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
3648
+ FROM ${option.tableName ?? this._service[_tableName]}
3649
+ ${where ? ' WHERE ' : ''}
3650
+ ${where}
3651
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3652
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3649
3653
  `;
3650
3654
  if (this._startRow && this._pageSize) {
3651
3655
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3653,13 +3657,13 @@ class StreamQuery {
3653
3657
  else if (this._startRow) {
3654
3658
  sql += `LIMIT ${this._startRow}`;
3655
3659
  }
3656
- const sqlCount = `
3657
- SELECT COUNT(1)
3658
- FROM ${option.tableName ?? this._service[_tableName]}
3659
- ${where ? ' WHERE ' : ''}
3660
- ${where}
3661
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3662
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3660
+ const sqlCount = `
3661
+ SELECT COUNT(1)
3662
+ FROM ${option.tableName ?? this._service[_tableName]}
3663
+ ${where ? ' WHERE ' : ''}
3664
+ ${where}
3665
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3666
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3663
3667
  `;
3664
3668
  if (option.sync === SyncMode.Sync) {
3665
3669
  result.total = this._service.select({
@@ -3726,9 +3730,9 @@ class StreamQuery {
3726
3730
  }
3727
3731
  }
3728
3732
  if (sets.length > 0) {
3729
- const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
3730
- ${where ? ' WHERE ' : ''}
3731
- ${where}
3733
+ const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
3734
+ ${where ? ' WHERE ' : ''}
3735
+ ${where}
3732
3736
  `;
3733
3737
  if (option.sync === SyncMode.Async) {
3734
3738
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -3745,9 +3749,9 @@ class StreamQuery {
3745
3749
  option ?? (option = {});
3746
3750
  option.sync ?? (option.sync = SyncMode.Async);
3747
3751
  const { where, params } = this._where();
3748
- const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
3749
- ${where ? ' WHERE ' : ''}
3750
- ${where}
3752
+ const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
3753
+ ${where ? ' WHERE ' : ''}
3754
+ ${where}
3751
3755
  `;
3752
3756
  if (option.sync === SyncMode.Async) {
3753
3757
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -4520,7 +4524,7 @@ __decorate([
4520
4524
  ], StreamQuery.prototype, "excuteDelete", null);
4521
4525
  /**
4522
4526
  获取REDIS客户端,
4523
- # [查看库的API](https://github.com/redis/ioredis?tab=readme-ov-file)
4527
+ # [查看库的API](https://redis.github.io/ioredis/)
4524
4528
  # [REDIS API](http://doc.redisfans.com/)
4525
4529
  REDIS 的API 可以直接用,将方法名转为小写
4526
4530
  ```