baja-lite 1.6.3 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/code.js CHANGED
@@ -108,109 +108,109 @@ if (config === null) {
108
108
  config = checkPath(basepath);
109
109
  }
110
110
  function help1() {
111
- console.log(`
112
- **********************-----------
113
- ${info2('配置文件:')}
114
- 请在项目根目录添加文件:${warn2('baja.code.json')} 或者 ${warn2('baja.code.js(export defult {})')}
115
- ${info2('配置示例:')}
116
- {
117
-
118
- "host": "",
119
- "port": "",
120
- "user": "",
121
- "password": "",
122
- "database": "",
123
-
124
- "command": {
125
- "entity": "src/{vueName}/{vueName}.entity.ts",
126
- "controller": "src/{vueName}/{vueName}.controller.ts",
127
- "service": "src/{vueName}/{vueName}.service.ts",
128
- "sql": "src/sql/{vueName}.mu",
129
- "module": "src/{vueName}/{vueName}.module.ts"
130
- },
131
- "commands": {
132
- "s": ["entity", "controller", "service", "sql", "module"]
133
- }
134
- "commands": {
135
- "s": ["entity", "controller", "service", "sql", "module"]
136
- },
137
- "output": "{ClassName}Module",
138
- "id"? : "uuidShort: true, notNull: true, uuid: true",
139
- "logicDeleteK"?: "逻辑删除字段名",
140
- "logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
141
- "NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'",
142
- "skipColumns"?: ["跳过的列名1", "跳过的列名2"],
143
- "custom"?: (列名:string) => string; 该属性支持为每个数据库列自定义一个名称,例如 字段名为 ci_name 可通过custom改造为 Ci Name
144
- }
145
- ${warn2(`command`)}是生成命令,这里声明命令同时定义文件生成路径, 同时要求在模板中必须有对应模板. ${info2('路径是相对于项目根目录的相对路径')}.
146
- ${warn2('commands')}是组合命令,上面的配置表示输入${error2('s')}同时生成:${success2('"entity", "controller", "service", "sql", "module"这几个模块')}
147
- ${warn2('output')} 是生成后打印出的内容
111
+ console.log(`
112
+ **********************-----------
113
+ ${info2('配置文件:')}
114
+ 请在项目根目录添加文件:${warn2('baja.code.json')} 或者 ${warn2('baja.code.js(export defult {})')}
115
+ ${info2('配置示例:')}
116
+ {
117
+
118
+ "host": "",
119
+ "port": "",
120
+ "user": "",
121
+ "password": "",
122
+ "database": "",
123
+
124
+ "command": {
125
+ "entity": "src/{vueName}/{vueName}.entity.ts",
126
+ "controller": "src/{vueName}/{vueName}.controller.ts",
127
+ "service": "src/{vueName}/{vueName}.service.ts",
128
+ "sql": "src/sql/{vueName}.mu",
129
+ "module": "src/{vueName}/{vueName}.module.ts"
130
+ },
131
+ "commands": {
132
+ "s": ["entity", "controller", "service", "sql", "module"]
133
+ }
134
+ "commands": {
135
+ "s": ["entity", "controller", "service", "sql", "module"]
136
+ },
137
+ "output": "{ClassName}Module",
138
+ "id"? : "uuidShort: true, notNull: true, uuid: true",
139
+ "logicDeleteK"?: "逻辑删除字段名",
140
+ "logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
141
+ "NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'",
142
+ "skipColumns"?: ["跳过的列名1", "跳过的列名2"],
143
+ "custom"?: (列名:string) => string; 该属性支持为每个数据库列自定义一个名称,例如 字段名为 ci_name 可通过custom改造为 Ci Name
144
+ }
145
+ ${warn2(`command`)}是生成命令,这里声明命令同时定义文件生成路径, 同时要求在模板中必须有对应模板. ${info2('路径是相对于项目根目录的相对路径')}.
146
+ ${warn2('commands')}是组合命令,上面的配置表示输入${error2('s')}同时生成:${success2('"entity", "controller", "service", "sql", "module"这几个模块')}
147
+ ${warn2('output')} 是生成后打印出的内容
148
148
  `);
149
149
  }
150
150
  function help2() {
151
- console.log(`
152
- ${error2('模板文件说明')}
153
- 使用${error2('mustache')}
154
- ${warn2('模板变量输出')}${info2('<% 变量 %>')}
155
- ${warn2('模板转义')}${info2('<%& 变量 %>')}
156
- ${warn2('模板循环')}${info2('<%# 变量 %> <%/变量%>')}
157
- ${warn2('模板路径')} 项目根目录的${error2('code-template')}
158
- ${warn2('模板使用')} 在配置文件中的command下定义命令,每个命令的key
159
- ${error2('变量说明')}
160
- ---------------------------------------------------------------------------------------------------------------
161
- ************* 以下假设表名为${error2('event_main_info')},列名为${error2('sku_id,sku_name')}
162
- title // 字符串,表的注释
163
-
164
- tableName // 字符串,event_main_info
165
- className // 字符串,eventMainInfo
166
- ClassName // 字符串,EventMainInfo
167
- vueName // 字符串,event-main-info
168
- splitVueName // 字符串,event/main-info
169
- splitName // 字符串,event/main/info
170
- SplitName // 字符串,event/mainInfo
171
-
172
- columns // 数组, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name、JSFieldName 分别表示JS的注解,Type:表示JS类
173
- 型,custom:自定义列名}
174
- column_names // 数组, 元素是列名字符串,格式是 sku_id,sku_name
175
- ColumnNames // 数组, 元素是列名字符串,格式是 skuId,skuName
176
- column_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
177
- ColumnNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
178
-
179
- column_names_joinT // 字符串,列名join的字符串,格式是 "t.sku_id,t.sku_name"
180
- ColumnNames_joinT // 字符串,列名join的字符串,格式是 "t.skuId,t.skuName"
181
-
182
- columns_no_id // 数组, 不含主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型
183
- }
184
- column_names_no_id // 数组, 不含主键, 元素是列名字符串,格式是 sku_id,sku_name
185
- ColumnNames_no_id // 数组, 不含主键, 元素是列名字符串,格式是 skuId,skuName
186
- column_names_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "sku_id,sku_name"
187
- ColumnNames_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "skuId,skuName"
188
-
189
-
190
- columns_no_skip // 数组, 不含跳过的列,元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型}
191
- column_names_no_skip // 数组, 不含跳过的列, 元素是列名字符串,格式是 sku_id,sku_name
192
- ColumnNames_no_skip // 数组, 不含跳过的列, 元素是列名字符串,格式是 skuId,skuName
193
- column_names_no_skip_join // 数组, 不含跳过的列, 元素是列名字符串,格式是 "sku_id,sku_name"
194
- ColumnNames_no_skip_join // 数组, 不含跳过的列, 元素是列名字符串,格式是 "skuId,skuName"
195
-
196
- ids // 数组, 只有主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型}
197
- id_names // 数组, 只有主键, 元素是列名字符串,格式是 sku_id,sku_name
198
- IdNames // 数组, 只有主键, 元素是列名字符串,格式是 skuId,skuName
199
- id_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
200
- IdNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
201
-
202
- modelName // 推断出的模块名称,可能为空字符串, 如果表名为event_main_info, 则模块为 event
203
- modelPath // 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
204
-
205
- logicDelete // 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
206
- ---------------------------------------------------------------------------------------------------------------
207
- ${warn2('特殊命令')}
208
- ${warn2('多表操作')} .命令 table1,table2,table3:模块名称 ${info2(':模块名称 可以省略')}
209
- ${warn2('全库操作')} .命令 . ${info2('注意:.表示全表')}
210
- ${warn2('覆盖生成')} .force
211
- ${warn2('配置说明')} .help1
212
- ${warn2('模板说明')} .help2
213
- -----
151
+ console.log(`
152
+ ${error2('模板文件说明')}
153
+ 使用${error2('mustache')}
154
+ ${warn2('模板变量输出')}${info2('<% 变量 %>')}
155
+ ${warn2('模板转义')}${info2('<%& 变量 %>')}
156
+ ${warn2('模板循环')}${info2('<%# 变量 %> <%/变量%>')}
157
+ ${warn2('模板路径')} 项目根目录的${error2('code-template')}
158
+ ${warn2('模板使用')} 在配置文件中的command下定义命令,每个命令的key
159
+ ${error2('变量说明')}
160
+ ---------------------------------------------------------------------------------------------------------------
161
+ ************* 以下假设表名为${error2('event_main_info')},列名为${error2('sku_id,sku_name')}
162
+ title // 字符串,表的注释
163
+
164
+ tableName // 字符串,event_main_info
165
+ className // 字符串,eventMainInfo
166
+ ClassName // 字符串,EventMainInfo
167
+ vueName // 字符串,event-main-info
168
+ splitVueName // 字符串,event/main-info
169
+ splitName // 字符串,event/main/info
170
+ SplitName // 字符串,event/mainInfo
171
+
172
+ columns // 数组, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name、JSFieldName 分别表示JS的注解,Type:表示JS类
173
+ 型,custom:自定义列名}
174
+ column_names // 数组, 元素是列名字符串,格式是 sku_id,sku_name
175
+ ColumnNames // 数组, 元素是列名字符串,格式是 skuId,skuName
176
+ column_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
177
+ ColumnNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
178
+
179
+ column_names_joinT // 字符串,列名join的字符串,格式是 "t.sku_id,t.sku_name"
180
+ ColumnNames_joinT // 字符串,列名join的字符串,格式是 "t.skuId,t.skuName"
181
+
182
+ columns_no_id // 数组, 不含主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型
183
+ }
184
+ column_names_no_id // 数组, 不含主键, 元素是列名字符串,格式是 sku_id,sku_name
185
+ ColumnNames_no_id // 数组, 不含主键, 元素是列名字符串,格式是 skuId,skuName
186
+ column_names_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "sku_id,sku_name"
187
+ ColumnNames_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "skuId,skuName"
188
+
189
+
190
+ columns_no_skip // 数组, 不含跳过的列,元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型}
191
+ column_names_no_skip // 数组, 不含跳过的列, 元素是列名字符串,格式是 sku_id,sku_name
192
+ ColumnNames_no_skip // 数组, 不含跳过的列, 元素是列名字符串,格式是 skuId,skuName
193
+ column_names_no_skip_join // 数组, 不含跳过的列, 元素是列名字符串,格式是 "sku_id,sku_name"
194
+ ColumnNames_no_skip_join // 数组, 不含跳过的列, 元素是列名字符串,格式是 "skuId,skuName"
195
+
196
+ ids // 数组, 只有主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型}
197
+ id_names // 数组, 只有主键, 元素是列名字符串,格式是 sku_id,sku_name
198
+ IdNames // 数组, 只有主键, 元素是列名字符串,格式是 skuId,skuName
199
+ id_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
200
+ IdNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
201
+
202
+ modelName // 推断出的模块名称,可能为空字符串, 如果表名为event_main_info, 则模块为 event
203
+ modelPath // 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
204
+
205
+ logicDelete // 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
206
+ ---------------------------------------------------------------------------------------------------------------
207
+ ${warn2('特殊命令')}
208
+ ${warn2('多表操作')} .命令 table1,table2,table3:模块名称 ${info2(':模块名称 可以省略')}
209
+ ${warn2('全库操作')} .命令 . ${info2('注意:.表示全表')}
210
+ ${warn2('覆盖生成')} .force
211
+ ${warn2('配置说明')} .help1
212
+ ${warn2('模板说明')} .help2
213
+ -----
214
214
  `);
215
215
  }
216
216
  if (config === null) {
@@ -256,8 +256,8 @@ try {
256
256
  async function getTables(tableName) {
257
257
  const conn = await pool.getConnection();
258
258
  const params = [configData.database];
259
- let sql = `
260
- SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
259
+ let sql = `
260
+ SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
261
261
  WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
262
262
  if (tableName !== '.') {
263
263
  sql += ` AND TABLE_NAME IN (?)`;
@@ -269,17 +269,17 @@ try {
269
269
  }
270
270
  async function getColumns(tableName) {
271
271
  const conn = await pool.getConnection();
272
- const [result] = await conn.query(`
273
- SELECT
274
- DATA_TYPE type,
275
- COLUMN_NAME \`name\`,
276
- IFNULL(IFNULL(CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION),DATETIME_PRECISION) \`length\`,
277
- NUMERIC_SCALE scale,
278
- COLUMN_DEFAULT def,
279
- IF(COLUMN_KEY = 'PRI', 1, 0) id,
280
- IF(IS_NULLABLE = 'NO', 1, 0) notNull,
281
- COLUMN_COMMENT \`comment\`
282
- FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
272
+ const [result] = await conn.query(`
273
+ SELECT
274
+ DATA_TYPE type,
275
+ COLUMN_NAME \`name\`,
276
+ IFNULL(IFNULL(CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION),DATETIME_PRECISION) \`length\`,
277
+ NUMERIC_SCALE scale,
278
+ COLUMN_DEFAULT def,
279
+ IF(COLUMN_KEY = 'PRI', 1, 0) id,
280
+ IF(IS_NULLABLE = 'NO', 1, 0) notNull,
281
+ COLUMN_COMMENT \`comment\`
282
+ FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
283
283
  `, [configData.database, tableName]);
284
284
  let logicDelete = '';
285
285
  const columns = result.map(r => {
package/package.json CHANGED
@@ -1,80 +1,80 @@
1
- {
2
- "name": "baja-lite",
3
- "version": "1.6.3",
4
- "description": "some util for self",
5
- "homepage": "https://github.com/void-soul/baja-lite",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/void-soul/baja-lite.git"
9
- },
10
- "license": "MIT",
11
- "author": "void-soul",
12
- "type": "module",
13
- "exports": {
14
- ".": {
15
- "types": "./index.d.ts",
16
- "import": "./index.js"
17
- },
18
- "./boot.js": "./boot.js",
19
- "./boot-remote.js": "./boot-remote.js",
20
- "./wx.js": "./wx.js"
21
- },
22
- "types": "./index.d.ts",
23
- "bin": {
24
- "baja": "./code.js"
25
- },
26
- "scripts": {
27
- "dist": "node ./ci.js",
28
- "mysql": "bun --inspect ./src/test-mysql.ts",
29
- "mysql2": "node inspect ./dist/cjs/test-mysql.js",
30
- "postgres": "bun --inspect ./src/test-postgresql.ts",
31
- "postgres2": "node inspect ./dist/cjs/test-postgresql.js",
32
- "sqlite": "node inspect ./dist/cjs/test-sqlite.js",
33
- "test": "bun --inspect ./src/test.ts",
34
- "test2": "node inspect ./dist/cjs/tes.js",
35
- "xml": "bun --inspect ./src/test-xml.ts"
36
- },
37
- "dependencies": {
38
- "@msgpack/msgpack": "3.1.2",
39
- "@types/request-promise": "4.1.51",
40
- "axios": "1.11.0",
41
- "baja-lite-field": "1.4.20",
42
- "decimal.js": "10.6.0",
43
- "html-parse-stringify": "3.0.1",
44
- "iterare": "1.2.1",
45
- "mustache": "4.2.0",
46
- "pino": "9.9.0",
47
- "pino-pretty": "13.1.1",
48
- "reflect-metadata": "0.2.2",
49
- "request": "2.88.2",
50
- "request-promise": "4.2.6",
51
- "sql-formatter": "15.6.6",
52
- "sqlstring": "2.3.3",
53
- "tslib": "2.8.1"
54
- },
55
- "devDependencies": {
56
- "@types/better-sqlite3": "7.6.13",
57
- "@types/mustache": "4.2.6",
58
- "@types/node": "24.3.0",
59
- "@types/shelljs": "0.8.17",
60
- "@types/sqlstring": "2.3.2",
61
- "@typescript-eslint/eslint-plugin": "8.40.0",
62
- "@typescript-eslint/parser": "8.40.0",
63
- "better-sqlite3": "12.2.0",
64
- "ioredis": "5.7.0",
65
- "mongodb": "6.18.0",
66
- "mysql2": "3.14.3",
67
- "pg": "8.16.3",
68
- "pg-pool": "3.10.1",
69
- "redlock": "5.0.0-beta.2",
70
- "shelljs": "0.10.0",
71
- "typescript": "5.9.2"
72
- },
73
- "engines": {
74
- "node": ">=20"
75
- },
76
- "publishConfig": {
77
- "access": "public"
78
- },
79
- "models": "./index.js"
80
- }
1
+ {
2
+ "name": "baja-lite",
3
+ "version": "1.6.5",
4
+ "description": "some util for self",
5
+ "homepage": "https://github.com/void-soul/baja-lite",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/void-soul/baja-lite.git"
9
+ },
10
+ "license": "MIT",
11
+ "author": "void-soul",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./index.d.ts",
16
+ "import": "./index.js"
17
+ },
18
+ "./boot.js": "./boot.js",
19
+ "./boot-remote.js": "./boot-remote.js",
20
+ "./wx.js": "./wx.js"
21
+ },
22
+ "types": "./index.d.ts",
23
+ "bin": {
24
+ "baja": "./code.js"
25
+ },
26
+ "scripts": {
27
+ "dist": "node ./ci.js",
28
+ "mysql": "bun --inspect ./src/test-mysql.ts",
29
+ "mysql2": "node inspect ./dist/cjs/test-mysql.js",
30
+ "postgres": "bun --inspect ./src/test-postgresql.ts",
31
+ "postgres2": "node inspect ./dist/cjs/test-postgresql.js",
32
+ "sqlite": "node inspect ./dist/cjs/test-sqlite.js",
33
+ "test": "bun --inspect ./src/test.ts",
34
+ "test2": "node inspect ./dist/cjs/tes.js",
35
+ "xml": "bun --inspect ./src/test-xml.ts"
36
+ },
37
+ "dependencies": {
38
+ "@msgpack/msgpack": "3.1.2",
39
+ "@types/request-promise": "4.1.51",
40
+ "axios": "1.11.0",
41
+ "baja-lite-field": "1.4.20",
42
+ "decimal.js": "10.6.0",
43
+ "html-parse-stringify": "3.0.1",
44
+ "iterare": "1.2.1",
45
+ "mustache": "4.2.0",
46
+ "pino": "9.9.0",
47
+ "pino-pretty": "13.1.1",
48
+ "reflect-metadata": "0.2.2",
49
+ "request": "2.88.2",
50
+ "request-promise": "4.2.6",
51
+ "sql-formatter": "15.6.6",
52
+ "sqlstring": "2.3.3",
53
+ "tslib": "2.8.1"
54
+ },
55
+ "devDependencies": {
56
+ "@types/better-sqlite3": "7.6.13",
57
+ "@types/mustache": "4.2.6",
58
+ "@types/node": "24.3.0",
59
+ "@types/shelljs": "0.8.17",
60
+ "@types/sqlstring": "2.3.2",
61
+ "@typescript-eslint/eslint-plugin": "8.40.0",
62
+ "@typescript-eslint/parser": "8.40.0",
63
+ "better-sqlite3": "12.2.0",
64
+ "ioredis": "5.7.0",
65
+ "mongodb": "6.18.0",
66
+ "mysql2": "3.14.3",
67
+ "pg": "8.16.3",
68
+ "pg-pool": "3.10.1",
69
+ "redlock": "5.0.0-beta.2",
70
+ "shelljs": "0.10.0",
71
+ "typescript": "5.9.2"
72
+ },
73
+ "engines": {
74
+ "node": ">=20"
75
+ },
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "models": "./index.js"
80
+ }
package/sql.js CHANGED
@@ -242,10 +242,10 @@ class MysqlConnection {
242
242
  resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
243
243
  }
244
244
  catch (error) {
245
- logger.error(`
246
- error: ${error},
247
- sql: ${sql},
248
- params: ${params}
245
+ logger.error(`
246
+ error: ${error},
247
+ sql: ${sql},
248
+ params: ${params}
249
249
  `);
250
250
  reject(error);
251
251
  }
@@ -278,10 +278,10 @@ class MysqlConnection {
278
278
  resolve(null);
279
279
  }
280
280
  catch (error) {
281
- logger.error(`
282
- error: ${error},
283
- sql: ${sql},
284
- params: ${params}
281
+ logger.error(`
282
+ error: ${error},
283
+ sql: ${sql},
284
+ params: ${params}
285
285
  `);
286
286
  reject(error);
287
287
  }
@@ -312,10 +312,10 @@ class MysqlConnection {
312
312
  resolve(null);
313
313
  }
314
314
  catch (error) {
315
- logger.error(`
316
- error: ${error},
317
- sql: ${sql},
318
- params: ${params}
315
+ logger.error(`
316
+ error: ${error},
317
+ sql: ${sql},
318
+ params: ${params}
319
319
  `);
320
320
  reject(error);
321
321
  }
@@ -346,10 +346,10 @@ class MysqlConnection {
346
346
  resolve([]);
347
347
  }
348
348
  catch (error) {
349
- logger.error(`
350
- error: ${error},
351
- sql: ${sql},
352
- params: ${params}
349
+ logger.error(`
350
+ error: ${error},
351
+ sql: ${sql},
352
+ params: ${params}
353
353
  `);
354
354
  reject(error);
355
355
  }
@@ -378,10 +378,10 @@ class MysqlConnection {
378
378
  resolve(result);
379
379
  }
380
380
  catch (error) {
381
- logger.error(`
382
- error: ${error},
383
- sql: ${sql},
384
- params: ${params}
381
+ logger.error(`
382
+ error: ${error},
383
+ sql: ${sql},
384
+ params: ${params}
385
385
  `);
386
386
  reject(error);
387
387
  }
@@ -525,10 +525,10 @@ class PostgresqlConnection {
525
525
  resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
526
526
  }
527
527
  catch (error) {
528
- logger.error(`
529
- error: ${error},
530
- sql: ${sql},
531
- params: ${params}
528
+ logger.error(`
529
+ error: ${error},
530
+ sql: ${sql},
531
+ params: ${params}
532
532
  `);
533
533
  reject(error);
534
534
  }
@@ -565,10 +565,10 @@ class PostgresqlConnection {
565
565
  resolve(null);
566
566
  }
567
567
  catch (error) {
568
- logger.error(`
569
- error: ${error},
570
- sql: ${sql},
571
- params: ${params}
568
+ logger.error(`
569
+ error: ${error},
570
+ sql: ${sql},
571
+ params: ${params}
572
572
  `);
573
573
  reject(error);
574
574
  }
@@ -603,10 +603,10 @@ class PostgresqlConnection {
603
603
  resolve(null);
604
604
  }
605
605
  catch (error) {
606
- logger.error(`
607
- error: ${error},
608
- sql: ${sql},
609
- params: ${params}
606
+ logger.error(`
607
+ error: ${error},
608
+ sql: ${sql},
609
+ params: ${params}
610
610
  `);
611
611
  reject(error);
612
612
  }
@@ -641,10 +641,10 @@ class PostgresqlConnection {
641
641
  resolve([]);
642
642
  }
643
643
  catch (error) {
644
- logger.error(`
645
- error: ${error},
646
- sql: ${sql},
647
- params: ${params}
644
+ logger.error(`
645
+ error: ${error},
646
+ sql: ${sql},
647
+ params: ${params}
648
648
  `);
649
649
  reject(error);
650
650
  }
@@ -677,10 +677,10 @@ class PostgresqlConnection {
677
677
  resolve(rows);
678
678
  }
679
679
  catch (error) {
680
- logger.error(`
681
- error: ${error},
682
- sql: ${sql},
683
- params: ${params}
680
+ logger.error(`
681
+ error: ${error},
682
+ sql: ${sql},
683
+ params: ${params}
684
684
  `);
685
685
  reject(error);
686
686
  }
@@ -819,10 +819,10 @@ class SqliteConnection {
819
819
  return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
820
820
  }
821
821
  catch (error) {
822
- logger.error(`
823
- error: ${error},
824
- sql: ${sql},
825
- params: ${params}
822
+ logger.error(`
823
+ error: ${error},
824
+ sql: ${sql},
825
+ params: ${params}
826
826
  `);
827
827
  throw error;
828
828
  }
@@ -845,10 +845,10 @@ class SqliteConnection {
845
845
  return this[_daoConnection].prepare(sql).pluck().get(params ?? {});
846
846
  }
847
847
  catch (error) {
848
- logger.error(`
849
- error: ${error},
850
- sql: ${sql},
851
- params: ${params}
848
+ logger.error(`
849
+ error: ${error},
850
+ sql: ${sql},
851
+ params: ${params}
852
852
  `);
853
853
  throw error;
854
854
  }
@@ -870,10 +870,10 @@ class SqliteConnection {
870
870
  return this[_daoConnection].prepare(sql).get(params ?? {});
871
871
  }
872
872
  catch (error) {
873
- logger.error(`
874
- error: ${error},
875
- sql: ${sql},
876
- params: ${params}
873
+ logger.error(`
874
+ error: ${error},
875
+ sql: ${sql},
876
+ params: ${params}
877
877
  `);
878
878
  throw error;
879
879
  }
@@ -896,10 +896,10 @@ class SqliteConnection {
896
896
  return this[_daoConnection].prepare(sql).raw().all(params ?? {});
897
897
  }
898
898
  catch (error) {
899
- logger.error(`
900
- error: ${error},
901
- sql: ${sql},
902
- params: ${params}
899
+ logger.error(`
900
+ error: ${error},
901
+ sql: ${sql},
902
+ params: ${params}
903
903
  `);
904
904
  throw error;
905
905
  }
@@ -922,10 +922,10 @@ class SqliteConnection {
922
922
  return this[_daoConnection].prepare(sql).all(params ?? {});
923
923
  }
924
924
  catch (error) {
925
- logger.error(`
926
- error: ${error},
927
- sql: ${sql},
928
- params: ${params}
925
+ logger.error(`
926
+ error: ${error},
927
+ sql: ${sql},
928
+ params: ${params}
929
929
  `);
930
930
  throw error;
931
931
  }
@@ -938,15 +938,15 @@ export class Sqlite {
938
938
  constructor(db) {
939
939
  this[_daoDB] = db;
940
940
  this[_daoDB].pragma('journal_mode = WAL');
941
- this[_daoDB].exec(`
942
- CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
943
- DELETE FROM DUAL;
944
- INSERT INTO DUAL (______id ) VALUES ( 1 );
945
- CREATE TABLE IF NOT EXISTS TABLE_VERSION (
946
- ______tableName text NOT NULL,
947
- ______version text NOT NULL,
948
- PRIMARY KEY ( ______tableName )
949
- );
941
+ this[_daoDB].exec(`
942
+ CREATE TABLE IF NOT EXISTS DUAL ( ______id INTEGER NOT NULL, PRIMARY KEY ( ______id ));
943
+ DELETE FROM DUAL;
944
+ INSERT INTO DUAL (______id ) VALUES ( 1 );
945
+ CREATE TABLE IF NOT EXISTS TABLE_VERSION (
946
+ ______tableName text NOT NULL,
947
+ ______version text NOT NULL,
948
+ PRIMARY KEY ( ______tableName )
949
+ );
950
950
  `);
951
951
  this[_daoDB].function('UUID_SHORT', { deterministic: false }, () => snowflake.generate());
952
952
  this[_daoDB].function('UUID', { deterministic: false }, () => snowflake.generate());
@@ -1045,10 +1045,10 @@ export class SqliteRemoteConnection {
1045
1045
  resolve({ affectedRows, insertId: insertId ? BigInt(insertId) : 0n });
1046
1046
  }
1047
1047
  catch (error) {
1048
- logger.error(`
1049
- error: ${error},
1050
- sql: ${sql},
1051
- params: ${params}
1048
+ logger.error(`
1049
+ error: ${error},
1050
+ sql: ${sql},
1051
+ params: ${params}
1052
1052
  `);
1053
1053
  reject(error);
1054
1054
  }
@@ -1075,10 +1075,10 @@ export class SqliteRemoteConnection {
1075
1075
  resolve(r);
1076
1076
  }
1077
1077
  catch (error) {
1078
- logger.error(`
1079
- error: ${error},
1080
- sql: ${sql},
1081
- params: ${params}
1078
+ logger.error(`
1079
+ error: ${error},
1080
+ sql: ${sql},
1081
+ params: ${params}
1082
1082
  `);
1083
1083
  reject(error);
1084
1084
  }
@@ -1105,10 +1105,10 @@ export class SqliteRemoteConnection {
1105
1105
  resolve(r);
1106
1106
  }
1107
1107
  catch (error) {
1108
- logger.error(`
1109
- error: ${error},
1110
- sql: ${sql},
1111
- params: ${params}
1108
+ logger.error(`
1109
+ error: ${error},
1110
+ sql: ${sql},
1111
+ params: ${params}
1112
1112
  `);
1113
1113
  reject(error);
1114
1114
  }
@@ -1135,10 +1135,10 @@ export class SqliteRemoteConnection {
1135
1135
  resolve(r);
1136
1136
  }
1137
1137
  catch (error) {
1138
- logger.error(`
1139
- error: ${error},
1140
- sql: ${sql},
1141
- params: ${params}
1138
+ logger.error(`
1139
+ error: ${error},
1140
+ sql: ${sql},
1141
+ params: ${params}
1142
1142
  `);
1143
1143
  reject(error);
1144
1144
  }
@@ -1165,10 +1165,10 @@ export class SqliteRemoteConnection {
1165
1165
  resolve(r);
1166
1166
  }
1167
1167
  catch (error) {
1168
- logger.error(`
1169
- error: ${error},
1170
- sql: ${sql},
1171
- params: ${params}
1168
+ logger.error(`
1169
+ error: ${error},
1170
+ sql: ${sql},
1171
+ params: ${params}
1172
1172
  `);
1173
1173
  reject(error);
1174
1174
  }
@@ -1504,8 +1504,8 @@ class Build {
1504
1504
  if (MapName && Column) {
1505
1505
  const map = globalThis[_enum].EnumMap(MapName.trim());
1506
1506
  if (map) {
1507
- return ` CASE
1508
- ${Object.entries(map).map(([k, v]) => `WHEN ${Column} = '${k}' THEN '${v}'`).join(' ')}
1507
+ return ` CASE
1508
+ ${Object.entries(map).map(([k, v]) => `WHEN ${Column} = '${k}' THEN '${v}'`).join(' ')}
1509
1509
  END `;
1510
1510
  }
1511
1511
  }
@@ -2173,9 +2173,9 @@ export class SqlService {
2173
2173
  return `SELECT ${questMark.join(',')} FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM ${tableName} WHERE ${where})`;
2174
2174
  });
2175
2175
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2176
- const sql = formatDialect(`INSERT INTO
2177
- ${tableName}
2178
- (${columnNames})
2176
+ const sql = formatDialect(`INSERT INTO
2177
+ ${tableName}
2178
+ (${columnNames})
2179
2179
  ${questMarks.join(' UNION ALL ')};`, { dialect: formatDialects[option.dbType] });
2180
2180
  sqls.push({ sql, params });
2181
2181
  break;
@@ -2232,11 +2232,11 @@ export class SqlService {
2232
2232
  return `(${questMark.join(',')})`;
2233
2233
  });
2234
2234
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2235
- const sql = formatDialect(`
2236
- ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2237
- ${tableName}
2238
- (${columnNames})
2239
- VALUES ${questMarks};
2235
+ const sql = formatDialect(`
2236
+ ${option.dbType === DBType.Mysql ? '' : 'INSERT OR'} REPLACE INTO
2237
+ ${tableName}
2238
+ (${columnNames})
2239
+ VALUES ${questMarks};
2240
2240
  `, { dialect: formatDialects[option.dbType] });
2241
2241
  sqls.push({ sql, params });
2242
2242
  break;
@@ -2293,11 +2293,11 @@ export class SqlService {
2293
2293
  return `(${questMark.join(',')})`;
2294
2294
  });
2295
2295
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2296
- const sql = formatDialect(`
2297
- INSERT INTO
2298
- ${tableName}
2299
- (${columnNames})
2300
- VALUES ${questMarks};
2296
+ const sql = formatDialect(`
2297
+ INSERT INTO
2298
+ ${tableName}
2299
+ (${columnNames})
2300
+ VALUES ${questMarks};
2301
2301
  `, { dialect: formatDialects[option.dbType] });
2302
2302
  sqls.push({ sql, params });
2303
2303
  break;
@@ -2360,15 +2360,15 @@ export class SqlService {
2360
2360
  sqls.push(..._sqls);
2361
2361
  const columnNames = iterate(finalColumns).map(i => this[_fields][i]?.C2()).join(',');
2362
2362
  sqls.push({
2363
- sql: formatDialect(`
2364
- INSERT INTO
2365
- ${tableTemp}
2366
- (${columnNames})
2367
- VALUES ${questMarks};
2363
+ sql: formatDialect(`
2364
+ INSERT INTO
2365
+ ${tableTemp}
2366
+ (${columnNames})
2367
+ VALUES ${questMarks};
2368
2368
  `, { dialect: formatDialects[option.dbType] }), params
2369
2369
  });
2370
2370
  sqls.push({
2371
- sql: formatDialect(`INSERT INTO ${option.tableName} (${columnNames})
2371
+ sql: formatDialect(`INSERT INTO ${option.tableName} (${columnNames})
2372
2372
  SELECT ${columnNames} FROM ${tableTemp};`, { dialect: formatDialects[option.dbType] })
2373
2373
  });
2374
2374
  sqls.push({ sql: `DROP TABLE IF EXISTS ${tableTempESC};` });
@@ -2570,20 +2570,20 @@ export class SqlService {
2570
2570
  else {
2571
2571
  params = new Array();
2572
2572
  whereSql = iterate(wheres).map(where => {
2573
- return `(
2573
+ return `(
2574
2574
  ${Object.entries(where).map(([K, V]) => {
2575
2575
  params.push(V);
2576
2576
  return `${this[_fields][K]?.C2()} = ?`;
2577
- }).join(' AND ')}
2577
+ }).join(' AND ')}
2578
2578
  )`;
2579
2579
  }).join(' OR ');
2580
2580
  }
2581
2581
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2582
2582
  params.unshift(this[_deleteState]);
2583
2583
  sqls.push({
2584
- sql: formatDialect(`
2585
- UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2586
- WHERE ${whereSql};
2584
+ sql: formatDialect(`
2585
+ UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2586
+ WHERE ${whereSql};
2587
2587
  `, { dialect: formatDialects[option.dbType] }), params
2588
2588
  });
2589
2589
  }
@@ -2600,7 +2600,7 @@ export class SqlService {
2600
2600
  case DBType.Mysql: {
2601
2601
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2602
2602
  sqls.push({
2603
- 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 ')}
2603
+ 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 ')}
2604
2604
  SET a.${this[_fields][this[_stateFileName]]?.C2()} = ?;`, { dialect: formatDialects[option.dbType] }),
2605
2605
  params: [this[_deleteState]]
2606
2606
  });
@@ -2617,7 +2617,7 @@ export class SqlService {
2617
2617
  const columnNames = iterate(delWhere).map(K => this[_fields][K]?.C2()).join(',');
2618
2618
  if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
2619
2619
  sqls.push({
2620
- sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2620
+ sql: formatDialect(`UPDATE ${tableNameESC} SET ${this[_fields][this[_stateFileName]]?.C2()} = ?
2621
2621
  WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`, { dialect: formatDialects[option.dbType] }),
2622
2622
  params: [this[_deleteState]]
2623
2623
  });
@@ -2704,7 +2704,7 @@ export class SqlService {
2704
2704
  if (option.mode === SelectMode.Common) {
2705
2705
  const params = new Array();
2706
2706
  const whereSql = formatDialect(iterate(wheres).map(where => this[_transformer](where, option)).map(where => {
2707
- return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2707
+ return `SELECT ${columns} FROM ${tableNameESC} a WHERE
2708
2708
  ${Object.entries(where).map(([K, V]) => {
2709
2709
  params.push(V);
2710
2710
  return `${this[_fields][K]?.C2()} = ?`;
@@ -3100,7 +3100,7 @@ export class SqlService {
3100
3100
  if (option?.force) {
3101
3101
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${tableES};`);
3102
3102
  }
3103
- const lastVersion = this[_sqlite_version] ?? '0.0.1';
3103
+ const lastVersion = this[_sqlite_version] ?? '1';
3104
3104
  // 检查表
3105
3105
  const tableCheckResult = option.conn.pluck(SyncMode.Sync, `SELECT COUNT(1) t FROM sqlite_master WHERE TYPE = 'table' AND name = ?`, [option.tableName]);
3106
3106
  if (tableCheckResult) {
@@ -3115,11 +3115,11 @@ export class SqlService {
3115
3115
  const rtable = `${option.tableName}_${tableVersion.replace(/\./, '_')}`;
3116
3116
  option.conn.execute(SyncMode.Sync, `DROP TABLE IF EXISTS ${rtable};`);
3117
3117
  option.conn.execute(SyncMode.Sync, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3118
- option.conn.execute(SyncMode.Sync, `
3119
- CREATE TABLE IF NOT EXISTS ${tableES}(
3120
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3121
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3122
- );
3118
+ option.conn.execute(SyncMode.Sync, `
3119
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3120
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3121
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3122
+ );
3123
3123
  `);
3124
3124
  if (this[_index] && this[_index].length) {
3125
3125
  for (const index of this[_index]) {
@@ -3137,12 +3137,12 @@ export class SqlService {
3137
3137
  }
3138
3138
  else { // 表不存在
3139
3139
  // 创建表
3140
- option.conn.execute(SyncMode.Sync, `
3141
- CREATE TABLE IF NOT EXISTS ${tableES} (
3142
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3143
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3144
-
3145
- );
3140
+ option.conn.execute(SyncMode.Sync, `
3141
+ CREATE TABLE IF NOT EXISTS ${tableES} (
3142
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3143
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3144
+
3145
+ );
3146
3146
  `);
3147
3147
  if (this[_index] && this[_index].length) {
3148
3148
  for (const index of this[_index]) {
@@ -3158,7 +3158,7 @@ export class SqlService {
3158
3158
  if (option?.force) {
3159
3159
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${tableES};`);
3160
3160
  }
3161
- const lastVersion = this[_sqlite_version] ?? '0.0.1';
3161
+ const lastVersion = this[_sqlite_version] ?? '1';
3162
3162
  // 检查表
3163
3163
  const tableCheckResult = await option.conn.pluck(SyncMode.Async, `SELECT COUNT(1) t FROM sqlite_master WHERE TYPE = 'table' AND name = ?`, [option.tableName]);
3164
3164
  if (tableCheckResult) {
@@ -3173,11 +3173,11 @@ export class SqlService {
3173
3173
  const rtable = `${option.tableName}_${tableVersion.replace(/\./, '_')}`;
3174
3174
  await option.conn.execute(SyncMode.Async, `DROP TABLE IF EXISTS ${rtable};`);
3175
3175
  await option.conn.execute(SyncMode.Async, `ALTER TABLE ${tableES} RENAME TO ${rtable};`);
3176
- await option.conn.execute(SyncMode.Async, `
3177
- CREATE TABLE IF NOT EXISTS ${tableES}(
3178
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3179
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3180
- );
3176
+ await option.conn.execute(SyncMode.Async, `
3177
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3178
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3179
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3180
+ );
3181
3181
  `);
3182
3182
  if (this[_index] && this[_index].length) {
3183
3183
  for (const index of this[_index]) {
@@ -3195,11 +3195,11 @@ export class SqlService {
3195
3195
  }
3196
3196
  else { // 表不存在
3197
3197
  // 创建表
3198
- await option.conn.execute(SyncMode.Async, `
3199
- CREATE TABLE IF NOT EXISTS ${tableES}(
3200
- ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3201
- ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3202
- );
3198
+ await option.conn.execute(SyncMode.Async, `
3199
+ CREATE TABLE IF NOT EXISTS ${tableES}(
3200
+ ${Object.values(this[_fields]).map(K => K[DBType.Sqlite]()).join(',')}
3201
+ ${this[_ids] && this[_ids].length ? `, PRIMARY KEY (${this[_ids].map(i => this[_fields][i]?.C2()).join(',')})` : ''}
3202
+ );
3203
3203
  `);
3204
3204
  if (this[_index] && this[_index].length) {
3205
3205
  for (const index of this[_index]) {
@@ -3269,16 +3269,16 @@ export class SqlService {
3269
3269
  tableName = tableName ?? this[_tableName];
3270
3270
  switch (dbType) {
3271
3271
  case DBType.Mysql: {
3272
- let sql = formatDialect(`CREATE ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3273
- ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3274
- ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3275
- ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3272
+ let sql = formatDialect(`CREATE ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3273
+ ${columns.map(K => this[_fields][K][DBType.Mysql]()).join(',')}
3274
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) USING BTREE ` : ''}
3275
+ ${indexs && indexs.length ? `,${indexs.map(i => `KEY ${this[_fields][i]?.C2()} (${this[_fields][i]?.C2()})`).join(',')} ` : ''}
3276
3276
  ) ENGINE=MEMORY;`, { dialect: mysql });
3277
3277
  sqls.push({ sql });
3278
3278
  if (data && data.length > 0) {
3279
3279
  const params = [];
3280
3280
  let first = true;
3281
- sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3281
+ sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3282
3282
  ${(data).map(d => {
3283
3283
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3284
3284
  params.push(V);
@@ -3293,9 +3293,9 @@ export class SqlService {
3293
3293
  }
3294
3294
  case DBType.Sqlite:
3295
3295
  case DBType.SqliteRemote: {
3296
- let sql = formatDialect(`CREATE ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3297
- ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3298
- ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3296
+ let sql = formatDialect(`CREATE ${temp ? 'TEMPORARY' : ''} TABLE IF NOT EXISTS ${tableName}(
3297
+ ${columns.map(K => this[_fields][K][DBType.Sqlite]()).join(',')}
3298
+ ${ids && ids.length ? `,PRIMARY KEY (${ids.map(i => this[_fields][i]?.C2()).join(',')}) ` : ''}
3299
3299
  );`, { dialect: sqlite });
3300
3300
  sqls.push({ sql });
3301
3301
  if (indexs) {
@@ -3307,7 +3307,7 @@ export class SqlService {
3307
3307
  if (data && data.length > 0) {
3308
3308
  const params = [];
3309
3309
  let first = true;
3310
- sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3310
+ sql = formatDialect(`INSERT INTO ${tableName} (${columns.map(c => this[_fields][c]?.C2()).join(',')})
3311
3311
  ${(data).map(d => {
3312
3312
  const r = `SELECT ${Object.entries(d).map(([K, V]) => {
3313
3313
  params.push(V);
@@ -3825,11 +3825,11 @@ class StreamQuery {
3825
3825
  min(key, legName, distinct) { this._columns.push(`MIN(${distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}) ${legName || this[_fields][String(key)]?.C2()}`); return this; }
3826
3826
  /** GROUP_CONCAT([DISTINCT] key [ORDER BY :asc ASC] [ORDER BY :asc DESC] [SEPARATOR :separator]) */
3827
3827
  groupConcat(key, param) {
3828
- this._columns.push(`GROUP_CONCAT(
3829
- ${param && param.distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}
3830
- ${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `t.${this[_fields][String(i)]?.C2()} ASC`)} ` : ''}
3831
- ${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `t.${this[_fields][String(i)]?.C2()} DESC`)} ` : ''}
3832
- SEPARATOR '${param && param.separator || ','}'
3828
+ this._columns.push(`GROUP_CONCAT(
3829
+ ${param && param.distinct ? 'DISTINCT' : ''} t.${this[_fields][String(key)]?.C2()}
3830
+ ${param && param.asc && param.asc.length > 0 ? `ORDER BY ${param.asc.map(i => `t.${this[_fields][String(i)]?.C2()} ASC`)} ` : ''}
3831
+ ${param && param.desc && param.desc.length > 0 ? `${param && param.asc && param.asc.length > 0 ? '' : 'ORDER BY'} ${param.desc.map(i => `t.${this[_fields][String(i)]?.C2()} DESC`)} ` : ''}
3832
+ SEPARATOR '${param && param.separator || ','}'
3833
3833
  ) ${param && param.groupName || this[_fields][String(key)]?.C2()}`);
3834
3834
  return this;
3835
3835
  }
@@ -3865,14 +3865,14 @@ class StreamQuery {
3865
3865
  option.sync ?? (option.sync = SyncMode.Async);
3866
3866
  option.selectResult ?? (option.selectResult = SelectResult.RS_CS);
3867
3867
  const { where, params } = this._where();
3868
- let sql = `
3869
- SELECT
3870
- ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => `t.${this[_fields][String(key)]?.C3()}`).join(',')}
3871
- FROM ${option.tableName ?? this._service[_tableName]} t
3872
- ${where ? ' WHERE ' : ''}
3873
- ${where}
3874
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3875
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3868
+ let sql = `
3869
+ SELECT
3870
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => `t.${this[_fields][String(key)]?.C3()}`).join(',')}
3871
+ FROM ${option.tableName ?? this._service[_tableName]} t
3872
+ ${where ? ' WHERE ' : ''}
3873
+ ${where}
3874
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3875
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3876
3876
  `;
3877
3877
  if (this._startRow && this._pageSize) {
3878
3878
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3910,14 +3910,14 @@ class StreamQuery {
3910
3910
  size: 0,
3911
3911
  total: 0
3912
3912
  };
3913
- let sql = `
3914
- SELECT
3915
- ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => `t.${this[_fields][String(key)]?.C3()}`).join(',')}
3916
- FROM ${option.tableName ?? this._service[_tableName]} t
3917
- ${where ? ' WHERE ' : ''}
3918
- ${where}
3919
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3920
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3913
+ let sql = `
3914
+ SELECT
3915
+ ${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => `t.${this[_fields][String(key)]?.C3()}`).join(',')}
3916
+ FROM ${option.tableName ?? this._service[_tableName]} t
3917
+ ${where ? ' WHERE ' : ''}
3918
+ ${where}
3919
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3920
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3921
3921
  `;
3922
3922
  if (this._startRow && this._pageSize) {
3923
3923
  sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
@@ -3925,13 +3925,13 @@ class StreamQuery {
3925
3925
  else if (this._startRow) {
3926
3926
  sql += `LIMIT ${this._startRow}`;
3927
3927
  }
3928
- const sqlCount = `
3929
- SELECT COUNT(1)
3930
- FROM ${option.tableName ?? this._service[_tableName]} t
3931
- ${where ? ' WHERE ' : ''}
3932
- ${where}
3933
- ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3934
- ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3928
+ const sqlCount = `
3929
+ SELECT COUNT(1)
3930
+ FROM ${option.tableName ?? this._service[_tableName]} t
3931
+ ${where ? ' WHERE ' : ''}
3932
+ ${where}
3933
+ ${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
3934
+ ${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
3935
3935
  `;
3936
3936
  if (option.sync === SyncMode.Sync) {
3937
3937
  result.total = this._service.select({
@@ -3998,9 +3998,9 @@ class StreamQuery {
3998
3998
  }
3999
3999
  }
4000
4000
  if (sets.length > 0) {
4001
- const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
4002
- ${where ? ' WHERE ' : ''}
4003
- ${where}
4001
+ const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
4002
+ ${where ? ' WHERE ' : ''}
4003
+ ${where}
4004
4004
  `.replace(/t\./g, '');
4005
4005
  if (option.sync === SyncMode.Async) {
4006
4006
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
@@ -4017,9 +4017,9 @@ class StreamQuery {
4017
4017
  option ?? (option = {});
4018
4018
  option.sync ?? (option.sync = SyncMode.Async);
4019
4019
  const { where, params } = this._where();
4020
- const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
4021
- ${where ? ' WHERE ' : ''}
4022
- ${where}
4020
+ const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
4021
+ ${where ? ' WHERE ' : ''}
4022
+ ${where}
4023
4023
  `.replace(/t\./g, '');
4024
4024
  // if (option.sync === SyncMode.Async) {
4025
4025
  // return this._service.delete({ ...option, sync: SyncMode.Async, whereSql: where, whereParams: params });
package/sqlite.js CHANGED
@@ -151,7 +151,9 @@ export class SqliteRemoteClass {
151
151
  .replace('%s', date.getSeconds().toString().padStart(2, '0'));
152
152
  });
153
153
  this.dbList[dbName].function('RAND', { deterministic: false }, () => Math.random());
154
- this.dbList[dbName].function('UNIX_TIMESTAMP', { deterministic: false }, (dateStr) => dateStr ? Math.floor(new Date(dateStr).getTime() / 1000) : Math.floor(Date.now() / 1000));
154
+ this.dbList[dbName].function('UNIX_TIMESTAMP', { deterministic: false }, (dateStr) => dateStr
155
+ ? Math.floor(new Date(dateStr).getTime() / 1000)
156
+ : Math.floor(Date.now() / 1000));
155
157
  }
156
158
  }
157
159
  async export(dbName, exportPath) {
package/test-mysql.js CHANGED
@@ -93,9 +93,9 @@ export async function go2() {
93
93
  columnMode: ColumnMode.HUMP,
94
94
  sqlDir: 'E:/pro/my-sdk/baja-lite/xml',
95
95
  sqlMap: {
96
- ['test.test']: `
97
- SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
98
- SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
96
+ ['test.test']: `
97
+ SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
98
+ SELECT * FROM base_user {{#realname}} WHERE realname LIKE CONCAT(:realname, '%') {{/realname}};
99
99
  `
100
100
  }
101
101
  });
package/test-xml.js CHANGED
@@ -1,70 +1,70 @@
1
1
  import HTML from 'html-parse-stringify';
2
- console.log((HTML.parse(`
3
- <sql id="reportField">
4
- a.left_e_foul leftEFoul,
5
- a.right_e_foul rightEFoul,
6
- a.left_em_foul leftEmFoul,
7
- a.right_em_foul rightEmFoul,
8
- a.left_s_foul leftSFoul,
9
- a.right_s_foul rightSFoul,
10
- a.left_sb_foul leftSbFoul,
11
- a.right_sb_foul rightSbFoul,
12
- a.left_p_foul leftPFoul,
13
- a.right_p_foul rightPFoul,
14
- a.left_attack_goal leftAttackGoal,
15
- a.right_attack_goal rightAttackGoal,
16
- a.left_point_goal leftPointGoal,
17
- a.right_point_goal rightPointGoal,
18
- a.left_over_time_goal leftOverTimeGoal,
19
- a.right_over_time_goal rightOverTimeGoal,
20
- a.left_normal_goal leftNormalGoal,
21
- a.right_normal_goal rightNormalGoal,
22
- a.left_own_goal leftOwnGoal,
23
- a.right_own_goal rightOwnGoal,
24
- a.left_time_out leftTimeOut,
25
- a.right_time_out rightTimeOut,
26
- a.left_coach_y_card leftCoachYCard,
27
- a.right_coach_y_card rightCoachYCard,
28
- a.left_player_r_card leftPlayerRCard,
29
- a.right_player_r_card rightPlayerRCard,
30
- a.left_jump_ball leftJumpBall,
31
- a.right_jump_ball rightJumpBall
32
- </sql>
33
- <select id="matchReport" resultType="org.jeecg.modules.event.entity.EventMatchReport">
34
- select
35
- b.event_name eventName,
36
- a.match_id matchId,
37
- a.event_times eventTimes,
38
- a.team_left_id teamLeftId,
39
- a.team_RIGHt_id teamRightId,
40
- a.team_left_name teamLeftName,
41
- a.team_right_name teamRightName,
42
- a.team_left_image teamLeftImage,
43
- a.team_right_image teamRightImage,
44
- <include refid="reportField" />
45
- <if test="matchInfo.reportType!=null and matchInfo.reportType!=''">
46
- from view_match_report a
47
- </if>
48
- <if test="matchInfo.reportType==null or matchInfo.reportType==''">
49
- from event_match_report a
50
- </if>
51
- left join event_main_info b on a.event_id = b.id
52
- <where>
53
- <if test="matchInfo.id!=null and matchInfo.id!=''">
54
- and a.match_id = #{matchInfo.id}
55
- </if>
56
- <if test="matchInfo.eventId!=null and matchInfo.eventId!=''">
57
- and a.event_id = #{matchInfo.eventId}
58
- </if>
59
- <if test="matchInfo.teamLeftId!=null and matchInfo.teamLeftId!=''">
60
- and (a.team_left_id = #{matchInfo.teamLeftId} OR a.team_right_id = #{matchInfo.teamLeftId})
61
- </if>
62
- <if test="dataIdList!=null">
63
- and a.event_id in
64
- <foreach collection="dataIdList" item="item" open="(" close=")" separator=",">
65
- #{item}
66
- </foreach>
67
- </if>
68
- </where>
69
- </select>
2
+ console.log((HTML.parse(`
3
+ <sql id="reportField">
4
+ a.left_e_foul leftEFoul,
5
+ a.right_e_foul rightEFoul,
6
+ a.left_em_foul leftEmFoul,
7
+ a.right_em_foul rightEmFoul,
8
+ a.left_s_foul leftSFoul,
9
+ a.right_s_foul rightSFoul,
10
+ a.left_sb_foul leftSbFoul,
11
+ a.right_sb_foul rightSbFoul,
12
+ a.left_p_foul leftPFoul,
13
+ a.right_p_foul rightPFoul,
14
+ a.left_attack_goal leftAttackGoal,
15
+ a.right_attack_goal rightAttackGoal,
16
+ a.left_point_goal leftPointGoal,
17
+ a.right_point_goal rightPointGoal,
18
+ a.left_over_time_goal leftOverTimeGoal,
19
+ a.right_over_time_goal rightOverTimeGoal,
20
+ a.left_normal_goal leftNormalGoal,
21
+ a.right_normal_goal rightNormalGoal,
22
+ a.left_own_goal leftOwnGoal,
23
+ a.right_own_goal rightOwnGoal,
24
+ a.left_time_out leftTimeOut,
25
+ a.right_time_out rightTimeOut,
26
+ a.left_coach_y_card leftCoachYCard,
27
+ a.right_coach_y_card rightCoachYCard,
28
+ a.left_player_r_card leftPlayerRCard,
29
+ a.right_player_r_card rightPlayerRCard,
30
+ a.left_jump_ball leftJumpBall,
31
+ a.right_jump_ball rightJumpBall
32
+ </sql>
33
+ <select id="matchReport" resultType="org.jeecg.modules.event.entity.EventMatchReport">
34
+ select
35
+ b.event_name eventName,
36
+ a.match_id matchId,
37
+ a.event_times eventTimes,
38
+ a.team_left_id teamLeftId,
39
+ a.team_RIGHt_id teamRightId,
40
+ a.team_left_name teamLeftName,
41
+ a.team_right_name teamRightName,
42
+ a.team_left_image teamLeftImage,
43
+ a.team_right_image teamRightImage,
44
+ <include refid="reportField" />
45
+ <if test="matchInfo.reportType!=null and matchInfo.reportType!=''">
46
+ from view_match_report a
47
+ </if>
48
+ <if test="matchInfo.reportType==null or matchInfo.reportType==''">
49
+ from event_match_report a
50
+ </if>
51
+ left join event_main_info b on a.event_id = b.id
52
+ <where>
53
+ <if test="matchInfo.id!=null and matchInfo.id!=''">
54
+ and a.match_id = #{matchInfo.id}
55
+ </if>
56
+ <if test="matchInfo.eventId!=null and matchInfo.eventId!=''">
57
+ and a.event_id = #{matchInfo.eventId}
58
+ </if>
59
+ <if test="matchInfo.teamLeftId!=null and matchInfo.teamLeftId!=''">
60
+ and (a.team_left_id = #{matchInfo.teamLeftId} OR a.team_right_id = #{matchInfo.teamLeftId})
61
+ </if>
62
+ <if test="dataIdList!=null">
63
+ and a.event_id in
64
+ <foreach collection="dataIdList" item="item" open="(" close=")" separator=",">
65
+ #{item}
66
+ </foreach>
67
+ </if>
68
+ </where>
69
+ </select>
70
70
  >`)));