baja-lite 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boot-remote.js +1 -1
- package/boot.js +12 -9
- package/object.d.ts +2 -2
- package/object.js +25 -3
- package/package.json +1 -1
- package/sql.d.ts +415 -338
- package/sql.js +825 -395
package/sql.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ declare const _inTransaction: unique symbol;
|
|
|
20
20
|
declare const _daoDB: unique symbol;
|
|
21
21
|
declare const _sqliteRemoteName: unique symbol;
|
|
22
22
|
declare const _SqlOption: unique symbol;
|
|
23
|
+
export declare const _dataConvert: unique symbol;
|
|
23
24
|
export declare const _enum: unique symbol;
|
|
24
25
|
export declare const _GlobalSqlOption: unique symbol;
|
|
25
26
|
export declare const _EventBus: unique symbol;
|
|
@@ -40,27 +41,27 @@ export declare enum SyncMode {
|
|
|
40
41
|
}
|
|
41
42
|
export declare enum InsertMode {
|
|
42
43
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
# 默认使用
|
|
45
|
+
** 支持单个、批量,语法 `INSERT INTO XX VALUES (第一条数据), (第二条数据);`
|
|
46
|
+
** 批量执行有性能优势,但无法利用数据库的sql预编译功能
|
|
47
|
+
*/
|
|
47
48
|
Insert = 0,
|
|
48
49
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
# 利用临时表
|
|
51
|
+
## 执行步骤
|
|
52
|
+
1. 建立临时表(从正式表复制)
|
|
53
|
+
2. 数据全部进入临时表
|
|
54
|
+
3. 临时表数据转移到正式表: `INSERT INTO 正式表 SELECT * FROM 临时表`
|
|
55
|
+
4. 删除临时表
|
|
56
|
+
## 注意
|
|
57
|
+
1. 适用于:主键不会冲突、非自增
|
|
58
|
+
2. 临时表的结构复制正式表
|
|
58
59
|
*/
|
|
59
60
|
InsertWithTempTable = 1,
|
|
60
61
|
InsertIfNotExists = 2,
|
|
61
62
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
# 插入或者更新
|
|
64
|
+
1. 判断依据是主键
|
|
64
65
|
*/
|
|
65
66
|
Replace = 3
|
|
66
67
|
}
|
|
@@ -71,7 +72,7 @@ export declare enum DeleteMode {
|
|
|
71
72
|
`DELETE FROM WHERE (id = 1) OR (id = 2)`
|
|
72
73
|
### 例二
|
|
73
74
|
`DELETE FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
|
|
74
|
-
|
|
75
|
+
*/
|
|
75
76
|
Common = 0,
|
|
76
77
|
TempTable = 1
|
|
77
78
|
}
|
|
@@ -82,7 +83,7 @@ export declare enum SelectMode {
|
|
|
82
83
|
`SELECT * FROM WHERE (id = 1) OR (id = 2)`
|
|
83
84
|
### 例二
|
|
84
85
|
`SELECT * FROM WHERE (id = 1 AND idx = 11) OR (id = 2 AND idx = 22)`
|
|
85
|
-
|
|
86
|
+
*/
|
|
86
87
|
Common = 0,
|
|
87
88
|
TempTable = 1
|
|
88
89
|
}
|
|
@@ -173,12 +174,12 @@ interface ServiceOption {
|
|
|
173
174
|
# 全局行为配置文件
|
|
174
175
|
### `sqlDir?: string;` 数据库查询语句存放目录.存放格式为 export.default 的js、ts, 存放内容满足格式:
|
|
175
176
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
```
|
|
178
|
+
interface SqlModel {
|
|
179
|
+
[key: string]: string | ((params: { [k: string]: any }, context: any, isCount?: boolean) => string)
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
可以继承该接口来约束格式
|
|
182
183
|
*/
|
|
183
184
|
export interface GlobalSqlOptionForWeb {
|
|
184
185
|
/** 增改忽略Undefined */
|
|
@@ -192,18 +193,18 @@ export interface GlobalSqlOptionForWeb {
|
|
|
192
193
|
SqliteRemote?: {
|
|
193
194
|
/**
|
|
194
195
|
## 单一数据源
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
196
|
+
```
|
|
197
|
+
db: 'd:/1.db'
|
|
198
|
+
```
|
|
199
|
+
## 多数据源:传入多个连接配置
|
|
200
|
+
```
|
|
201
|
+
db: {
|
|
202
|
+
db1: 'd:/1.db',
|
|
203
|
+
db2: 'd:/2.db'
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
不支持 `SqliteMemory`
|
|
207
|
+
*/
|
|
207
208
|
db?: Record<string, string> | string;
|
|
208
209
|
/** 远程SQLITE接口实现,适用于Electron, 采用Ipc 的handel机制实现 */
|
|
209
210
|
service: SqliteRemoteInterface;
|
|
@@ -221,11 +222,11 @@ export interface GlobalSqlOptionForWeb {
|
|
|
221
222
|
*/
|
|
222
223
|
sqlFNMap?: Record<string, string>;
|
|
223
224
|
/**
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
// 第一个元素=列名,第二个元素是属性路径,
|
|
226
|
+
[
|
|
227
|
+
['dit_id', ['id']], // 列名ditid,对应属性id
|
|
228
|
+
['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
|
|
229
|
+
]
|
|
229
230
|
*/
|
|
230
231
|
sqlMapperMap?: SqlMappers;
|
|
231
232
|
/** 提供的枚举MAP */
|
|
@@ -235,115 +236,126 @@ export interface GlobalSqlOptionForWeb {
|
|
|
235
236
|
* 当设置为columnMode.HUMP时,切记将代码生成器中属性名称改对
|
|
236
237
|
* # 自定义sql查询时,无法自动转换哦,可使用标签转换:
|
|
237
238
|
*```
|
|
238
|
-
|
|
239
|
+
SELECT
|
|
239
240
|
* {{#hump}} seller_sku2, seller_sku {{/hump}}
|
|
240
241
|
* ```
|
|
241
242
|
* 转换为
|
|
242
243
|
*```
|
|
243
|
-
|
|
244
|
+
SELECT
|
|
244
245
|
* {{#hump}} seller_sku2 sellerSku2, seller_sku sellerSku {{/hump}}
|
|
245
246
|
* ```
|
|
246
247
|
*/
|
|
247
248
|
columnMode?: ColumnMode;
|
|
248
249
|
/** 对于WEB模式,默认为SqliteRemote */
|
|
249
250
|
dbType?: DBType;
|
|
251
|
+
/**
|
|
252
|
+
* * 数据转换器,用于service的select、page方法,以及stream查询
|
|
253
|
+
* * 例如
|
|
254
|
+
* ```
|
|
255
|
+
* dataConvert: {
|
|
256
|
+
* // 使用时,传入qiniu和列名,将根据列名对应的值生成URL
|
|
257
|
+
* qiniu: data => qiniuConvertUrl(data)
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
dataConvert?: Record<string, (data: any) => any>;
|
|
250
262
|
}
|
|
251
263
|
/**
|
|
252
264
|
# 全局行为配置文件
|
|
253
|
-
|
|
265
|
+
MYSQL编码: 'utf8mb4', utf8mb4_general_ci'
|
|
254
266
|
### `sqlDir?: string;` 数据库查询语句存放目录.存放格式为 export.default 的js、ts, 存放内容满足格式:
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
interface SqlModel {
|
|
270
|
+
[key: string]: string | ((params: { [k: string]: any }, context: any, isCount?: boolean) => string)
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
可以继承该接口来约束格式
|
|
262
274
|
*/
|
|
263
275
|
export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
|
|
264
276
|
/**
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
277
|
+
初始化MYSQL链接 支持多数据源
|
|
278
|
+
## 单一数据源: 直接传入Mysql2的连接配置
|
|
279
|
+
[MYSQL初始化文档](https://github.com/mysqljs/mysql#connection-options)
|
|
280
|
+
```
|
|
281
|
+
Mysql: {
|
|
282
|
+
host: '127.0.0.1',
|
|
283
|
+
...
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
## 多数据源:传入多个Mysql2的连接配置
|
|
287
|
+
```
|
|
288
|
+
Mysql: {
|
|
289
|
+
db1: {
|
|
290
|
+
host: '127.0.0.1',
|
|
291
|
+
...
|
|
292
|
+
},
|
|
293
|
+
db2: {
|
|
294
|
+
host: '127.0.0.1',
|
|
295
|
+
...
|
|
296
|
+
},
|
|
297
|
+
...
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
*/
|
|
289
301
|
Mysql?: Record<string, Record<string, any>> | Record<string, any>;
|
|
290
302
|
/**
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
303
|
+
初始化postgresql链接 支持多数据源
|
|
304
|
+
## 单一数据源: 直接传入postgresql的连接配置
|
|
305
|
+
[Postgresql初始化文档](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool)
|
|
306
|
+
```
|
|
307
|
+
Postgresql: {
|
|
308
|
+
database: 'postgres',
|
|
309
|
+
user: 'brianc',
|
|
310
|
+
password: 'secret!',
|
|
311
|
+
port: 5432,
|
|
312
|
+
ssl: true,
|
|
313
|
+
max: 20, // set pool max size to 20
|
|
314
|
+
idleTimeoutMillis: 1000, // close idle clients after 1 second
|
|
315
|
+
connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established
|
|
316
|
+
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
317
|
+
host?: string | undefined;
|
|
318
|
+
connectionString?: string | undefined;
|
|
319
|
+
keepAlive?: boolean | undefined;
|
|
320
|
+
stream?: () => stream.Duplex | stream.Duplex | undefined;
|
|
321
|
+
statement_timeout?: false | number | undefined;
|
|
322
|
+
query_timeout?: number | undefined;
|
|
323
|
+
keepAliveInitialDelayMillis?: number | undefined;
|
|
324
|
+
idle_in_transaction_session_timeout?: number | undefined;
|
|
325
|
+
application_name?: string | undefined;
|
|
326
|
+
types?: CustomTypesConfig | undefined;
|
|
327
|
+
options?: string | undefined;
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
## 多数据源:传入多个Postgresql的连接配置
|
|
331
|
+
```
|
|
332
|
+
Postgresql: {
|
|
333
|
+
db1: {
|
|
334
|
+
database: 'postgres',
|
|
335
|
+
user: 'brianc',
|
|
336
|
+
password: 'secret!',
|
|
337
|
+
port: 5432,
|
|
338
|
+
ssl: true,
|
|
339
|
+
max: 20, // set pool max size to 20
|
|
340
|
+
idleTimeoutMillis: 1000, // close idle clients after 1 second
|
|
341
|
+
connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established
|
|
342
|
+
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
343
|
+
},
|
|
344
|
+
db2: {
|
|
345
|
+
database: 'postgres',
|
|
346
|
+
user: 'brianc',
|
|
347
|
+
password: 'secret!',
|
|
348
|
+
port: 5432,
|
|
349
|
+
ssl: true,
|
|
350
|
+
max: 20, // set pool max size to 20
|
|
351
|
+
idleTimeoutMillis: 1000, // close idle clients after 1 second
|
|
352
|
+
connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established
|
|
353
|
+
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
354
|
+
},
|
|
355
|
+
...
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
*/
|
|
347
359
|
Postgresql?: Record<string, Record<string, any>> | Record<string, any>;
|
|
348
360
|
/**
|
|
349
361
|
## 单一数据源
|
|
@@ -352,34 +364,34 @@ export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
|
|
|
352
364
|
```
|
|
353
365
|
## 多数据源:传入多个连接配置
|
|
354
366
|
```
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
367
|
+
Sqlite: {
|
|
368
|
+
db1: 'd:/1.db',
|
|
369
|
+
db2: 'd:/2.db'
|
|
370
|
+
}
|
|
359
371
|
```
|
|
360
|
-
|
|
372
|
+
路径 = `SqliteMemory` 将创建内存库
|
|
361
373
|
*/
|
|
362
374
|
Sqlite?: Record<string, string> | string;
|
|
363
375
|
/**
|
|
364
376
|
## 日志文件存放路径,该目录下文件名是模块名,例如有一个文件名为 `user.js`,内容为:
|
|
365
377
|
```
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
378
|
+
export default {
|
|
379
|
+
'sql_1': 'SELECT * FROM user WHERE username = :username',
|
|
380
|
+
'sql_2': (options: {
|
|
381
|
+
ctx?: any;
|
|
382
|
+
isCount?: boolean;
|
|
383
|
+
isSum?: boolean;
|
|
384
|
+
limitStart?: number;
|
|
385
|
+
limitEnd?: number;
|
|
386
|
+
sortName?: string; sortType?: string;
|
|
387
|
+
params?: Record<string, any>;
|
|
388
|
+
}) => {
|
|
389
|
+
return `
|
|
390
|
+
SELECT * FROM user u LEFT JOIN organ o ON u.orgid = o.orgid
|
|
391
|
+
WHERE o.orgid = :orgid;
|
|
392
|
+
`;
|
|
393
|
+
}
|
|
394
|
+
} as SqlModel;
|
|
383
395
|
```
|
|
384
396
|
** 可以看到,sql语句支持直接映射一个sql语句,也可以通过函数返回,返回字符串支持[mustache](https://github.com/janl/mustache.js)
|
|
385
397
|
** 上面的文件中,将注册两个SQL:`user.sql_1` 和 `user.sql_2`.
|
|
@@ -390,51 +402,64 @@ export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
|
|
|
390
402
|
### 注意
|
|
391
403
|
1. 不要直接拼接参数:不安全且效率低
|
|
392
404
|
2. sqlite不支持多语句拼接
|
|
393
|
-
|
|
394
|
-
|
|
405
|
+
## 也支持.mu文件,格式略
|
|
406
|
+
*/
|
|
395
407
|
sqlDir?: string;
|
|
396
408
|
/**
|
|
397
|
-
|
|
398
|
-
|
|
409
|
+
## [mustache](https://mustache.github.io/) 编译时的[模板](https://github.com/janl/mustache.js#:~:text=requires%20only%20this%3A-,%7B%7B%3E%20next_more%7D%7D,-Why%3F%20Because%20the)
|
|
410
|
+
## 文件名就是模板名
|
|
399
411
|
*/
|
|
400
412
|
sqlFNDir?: string;
|
|
401
413
|
/**
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
+
* #TODO 未完成读取 sqlMapDir
|
|
415
|
+
* # sqlMapDir 目录定义如下,
|
|
416
|
+
* `test.ts`
|
|
417
|
+
* ```
|
|
418
|
+
* export const dict:SqlMappers = [
|
|
419
|
+
* {columnName: 'dit_id', mapNames: ['DTID'], def: 0, convert: 转换函数}, // 列名ditid,对应属性DTID,如果没有值,将返回默认值0,其中默认值0是可选的
|
|
420
|
+
* {columnName: 'event_id', mapNames: ['eventMainInfo', 'id'], def: 0, convert: 转换函数},// 列名event_id对应属性eventMainInfo.id,这种方式将返回嵌套的json对象,其中默认值null是可选的
|
|
421
|
+
* ]
|
|
422
|
+
* ```
|
|
423
|
+
* 将得到 test.dict 这个map
|
|
424
|
+
*/
|
|
425
|
+
sqlMapDir?: string;
|
|
426
|
+
/**
|
|
427
|
+
## 映射数据为对象,文件名就是模板名
|
|
428
|
+
```
|
|
429
|
+
// 第一个元素=列名,第二个元素是属性路径,
|
|
430
|
+
// 该目录下可存放json文件,内容如下
|
|
431
|
+
//
|
|
432
|
+
// 可以在查询时使用,优先级高于hump
|
|
433
|
+
// 例如:
|
|
434
|
+
[
|
|
435
|
+
['dit_id', ['id'], 可选的默认值], // 列名ditid,对应属性id,当未查询返回时,使用默认值
|
|
436
|
+
['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id,当未查询返回时,该属性不存在
|
|
437
|
+
]
|
|
438
|
+
```
|
|
414
439
|
*/
|
|
415
440
|
sqlMapperDir?: string;
|
|
416
441
|
/**
|
|
417
442
|
[REDIS初始化文档](https://github.com/redis/ioredis?tab=readme-ov-file#:~:text=connect%20to%20by%3A-,new%20Redis()%3B,-//%20Connect%20to%20127.0.0.1)
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
443
|
+
```
|
|
444
|
+
Redis: {
|
|
445
|
+
host: '127.0.0.1',
|
|
446
|
+
...
|
|
447
|
+
}
|
|
448
|
+
```
|
|
449
|
+
## 多数据源:传入多个Redis的连接配置
|
|
450
|
+
```
|
|
451
|
+
Redis: {
|
|
452
|
+
db1: {
|
|
453
|
+
host: '127.0.0.1',
|
|
454
|
+
...
|
|
455
|
+
},
|
|
456
|
+
db2: {
|
|
457
|
+
host: '127.0.0.1',
|
|
458
|
+
...
|
|
459
|
+
},
|
|
460
|
+
...
|
|
461
|
+
}
|
|
462
|
+
```
|
|
438
463
|
*/
|
|
439
464
|
Redis?: Record<string, Record<string, any>> | Record<string, any>;
|
|
440
465
|
/** sqlite数据库驱动初始化函数 */
|
|
@@ -596,7 +621,12 @@ export declare class SqliteRemote implements Dao {
|
|
|
596
621
|
restore(sync: SyncMode.Sync, importPath: string): void;
|
|
597
622
|
restore(sync: SyncMode.Async, importPath: string): Promise<void>;
|
|
598
623
|
}
|
|
599
|
-
export type SqlMapper =
|
|
624
|
+
export type SqlMapper = {
|
|
625
|
+
columnName: string;
|
|
626
|
+
mapNames: string[];
|
|
627
|
+
def?: any;
|
|
628
|
+
convert?: (data: any) => any;
|
|
629
|
+
}[];
|
|
600
630
|
export type SqlMappers = Record<string, SqlMapper>;
|
|
601
631
|
export type SqlModel = Record<string, string | ((options: {
|
|
602
632
|
ctx?: any;
|
|
@@ -633,14 +663,15 @@ export declare class SqlCache {
|
|
|
633
663
|
/**
|
|
634
664
|
*
|
|
635
665
|
* ```
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
666
|
+
// 第一个元素=列名,第二个元素是属性路径,
|
|
667
|
+
[
|
|
668
|
+
['dit_id', ['id']], // 列名ditid,对应属性id
|
|
669
|
+
['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
|
|
670
|
+
]
|
|
641
671
|
* ```
|
|
642
|
-
* @param
|
|
672
|
+
* @param ams
|
|
643
673
|
* @param keys
|
|
674
|
+
* @param key
|
|
644
675
|
*/
|
|
645
676
|
private readResultMap;
|
|
646
677
|
init(options: {
|
|
@@ -703,40 +734,40 @@ export declare const DB: (config: ServiceOption) => <C extends {
|
|
|
703
734
|
};
|
|
704
735
|
} & C;
|
|
705
736
|
/**
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
737
|
+
js项目中实体类注解替代品,只要确保函数被执行即可,举例:
|
|
738
|
+
```
|
|
739
|
+
// 声明一个class
|
|
740
|
+
export class AmaFuck {}
|
|
741
|
+
DeclareClass(AmaFuck, [
|
|
742
|
+
{ type: "String", name: "SellerSKU" },
|
|
743
|
+
{ type: "String", name: "SellerSKU2" },
|
|
744
|
+
{ type: "String", name: "site" }
|
|
745
|
+
]);
|
|
746
|
+
```
|
|
716
747
|
*/
|
|
717
748
|
export declare function DeclareClass(clz: any, FieldOptions: FieldOption[]): void;
|
|
718
749
|
/**
|
|
719
750
|
JS项目中,service注解代替,举例:
|
|
720
751
|
```
|
|
721
752
|
// 声明一个service,注意这里的let
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
753
|
+
export let AmaService = class AmaService extends SqlService {};
|
|
754
|
+
AmaService = DeclareService(AmaService, {
|
|
755
|
+
tableName: "ama_fuck2",
|
|
756
|
+
clz: AmaFuck,
|
|
757
|
+
dbType: DBType.Sqlite,
|
|
758
|
+
sqliteVersion: "0.0.3"
|
|
759
|
+
});
|
|
729
760
|
```
|
|
730
761
|
*/
|
|
731
762
|
export declare function DeclareService(clz: any, config: ServiceOption): any;
|
|
732
763
|
/**
|
|
733
764
|
## 数据库服务
|
|
734
765
|
### 注解DB
|
|
735
|
-
|
|
766
|
+
|
|
736
767
|
### 泛型 T,同DB注解中的clz
|
|
737
768
|
** 服务中所有方法默认以该类型为准
|
|
738
769
|
**
|
|
739
|
-
|
|
770
|
+
|
|
740
771
|
*/
|
|
741
772
|
export declare class SqlService<T extends object> {
|
|
742
773
|
[_tableName]?: string;
|
|
@@ -767,32 +798,30 @@ export declare class SqlService<T extends object> {
|
|
|
767
798
|
}) => Partial<T>;
|
|
768
799
|
private _insert;
|
|
769
800
|
/**
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
* @
|
|
794
|
-
* @param {MethodOption} [option]
|
|
795
|
-
* @memberof SqlServer
|
|
801
|
+
0. `sync`: 同步(sqlite)或者异步(mysql、remote),影响返回值类型,默认 `异步`
|
|
802
|
+
1. `data`:可是数组或者单对象
|
|
803
|
+
2. `skipUndefined`: boolean; 是否不处理值为undefined的字段,默认 true
|
|
804
|
+
3. `skipNull`: boolean; 是否不处理值为null的字段,默认 true
|
|
805
|
+
4. `skipEmptyString`: boolean; 是否不处理值为空字符串(`注意:多个空格也算空字符串`)的字段,默认 true
|
|
806
|
+
5. `maxDeal`: number; 批量处理时,每次处理多少个?默认500
|
|
807
|
+
6. `tableName`: 默认使用service注解的`tableName`,可以在某个方法中覆盖
|
|
808
|
+
7. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
809
|
+
8. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
810
|
+
```
|
|
811
|
+
service.transaction(async conn => {
|
|
812
|
+
service.insert({conn});
|
|
813
|
+
});
|
|
814
|
+
```
|
|
815
|
+
9. `dao`: 永远不需要传入该值
|
|
816
|
+
10. `mode` :默认`insert`,可选如下
|
|
817
|
+
1. `insert`: 默认
|
|
818
|
+
2. `insertIfNotExists`: 通过主键或者existConditionOtherThanIds字段判断数据是否存在,不存在才插入,存在则不执行
|
|
819
|
+
3. `replace`: 只支持用主键判断, 存在更新, 不存在插入
|
|
820
|
+
11. `existConditionOtherThanIds`: insertIfNotExists时判断同一记录的字段名称,默认情况下按照ID判断,设置existConditionOtherThanIds后,不用id
|
|
821
|
+
12. `replaceWithDef` replace时,是否带入默认值? 默认true
|
|
822
|
+
### 返回值是最后一次插入的主键ID,对于自增ID表适用
|
|
823
|
+
1. 如果主键是自增批量操作,且期望返回所有记录的ID,那么需要设置 `option 中的 every = true`,此时效率降低
|
|
824
|
+
* @memberof SqlService
|
|
796
825
|
*/
|
|
797
826
|
insert(option: MethodOption & {
|
|
798
827
|
data: Partial<T>;
|
|
@@ -848,22 +877,22 @@ export declare class SqlService<T extends object> {
|
|
|
848
877
|
}): bigint[];
|
|
849
878
|
private _update;
|
|
850
879
|
/**
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
880
|
+
## 根据主键修改
|
|
881
|
+
0. `sync`: 同步(sqlite)或者异步(mysql、remote),影响返回值类型,默认`异步模式`
|
|
882
|
+
1. `data`:可是数组或者单对象
|
|
883
|
+
2. `skipUndefined`: boolean; 是否不处理值为undefined的字段,默认 true
|
|
884
|
+
3. `skipNull`: boolean; 是否不处理值为null的字段,默认 true
|
|
885
|
+
4. `skipEmptyString`: boolean; 是否不处理值为空字符串(`注意:多个空格也算空字符串`)的字段,默认 true
|
|
886
|
+
5. `maxDeal`: number; 批量处理时,每次处理多少个?默认500
|
|
887
|
+
6. `tableName`: 默认使用service注解的`tableName`,可以在某个方法中覆盖
|
|
888
|
+
7. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
889
|
+
8. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
890
|
+
```
|
|
891
|
+
service.transaction(async conn => {
|
|
892
|
+
service.insert({conn});
|
|
893
|
+
});
|
|
894
|
+
```
|
|
895
|
+
9. `dao`: 永远不需要传入该值
|
|
867
896
|
*/
|
|
868
897
|
update(option: MethodOption & {
|
|
869
898
|
data: Partial<T> | Array<Partial<T>>;
|
|
@@ -882,23 +911,23 @@ export declare class SqlService<T extends object> {
|
|
|
882
911
|
maxDeal?: number;
|
|
883
912
|
}): number;
|
|
884
913
|
/**
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
914
|
+
## 删除
|
|
915
|
+
0. `sync`: 同步(sqlite)或者异步(mysql、remote),影响返回值类型,默认`异步模式`
|
|
916
|
+
1. 支持按ID删除:可以单个ID或者ID数组 `需要实体类只有一个ID`
|
|
917
|
+
2. 支持实体类删除: 用于多个ID或者按实体类某些字段删除
|
|
918
|
+
3. 两种模式:`mode`=`Common` 或者 `TempTable`
|
|
919
|
+
3. 如果数据多,使用 `TempTable`模式
|
|
920
|
+
4. 当设置实体类的字段有 `logicDelete` ,将进行逻辑删除,除非设置 forceDelete = true
|
|
921
|
+
6. `tableName`: 默认使用service注解的`tableName`,可以在某个方法中覆盖
|
|
922
|
+
7. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
923
|
+
8. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
924
|
+
```
|
|
925
|
+
service.transaction(async conn => {
|
|
926
|
+
service.insert({conn});
|
|
927
|
+
});
|
|
928
|
+
```
|
|
929
|
+
9. `dao`: 永远不需要传入该值
|
|
930
|
+
*/
|
|
902
931
|
delete(option: MethodOption & {
|
|
903
932
|
sync?: SyncMode.Async;
|
|
904
933
|
id?: string | number | Array<string | number>;
|
|
@@ -915,26 +944,26 @@ export declare class SqlService<T extends object> {
|
|
|
915
944
|
}): number;
|
|
916
945
|
private _template;
|
|
917
946
|
/**
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
947
|
+
#根据条件查询对象
|
|
948
|
+
## 特点:快速、简单,可快速根据某些字段是否等于来查询返回,可以查询记录和记录数
|
|
949
|
+
0. `sync`: 同步(sqlite)或者异步(mysql、remote),影响返回值类型,默认`异步模式`
|
|
950
|
+
1. `templateResult`: 返回值类型断言,4种
|
|
951
|
+
1. `AssertOne` 确定返回一个,如果不是一个,将报错,返回类型是T `默认`
|
|
952
|
+
2. `NotSureOne` 可能返回一个,返回类型是T|null
|
|
953
|
+
3. `Many` 返回多个
|
|
954
|
+
4. `Count` 返回记录数
|
|
955
|
+
2. 支持按ID查询:可以单个ID或者ID数组 `需要实体类只有一个ID`
|
|
956
|
+
3. 支持实体类查询: 用于多个ID或者按实体类某些字段查询
|
|
957
|
+
4. 两种查询方式:`mode`=`Common`(默认) 或者 `TempTable`
|
|
958
|
+
5. `tableName`: 默认使用service注解的`tableName`,可以在某个方法中覆盖
|
|
959
|
+
6. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
960
|
+
7. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
961
|
+
```
|
|
962
|
+
service.transaction(async conn => {
|
|
963
|
+
service.insert({conn});
|
|
964
|
+
});
|
|
965
|
+
```
|
|
966
|
+
8. `dao`: 永远不需要传入该值
|
|
938
967
|
|
|
939
968
|
*/
|
|
940
969
|
template<L = T>(option: MethodOption & {
|
|
@@ -1059,32 +1088,58 @@ export declare class SqlService<T extends object> {
|
|
|
1059
1088
|
}): Promise<ArrayList<L>>;
|
|
1060
1089
|
private _select;
|
|
1061
1090
|
/**
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1091
|
+
# 自由查询
|
|
1092
|
+
0. `sync`: 同步(sqlite)或者异步(mysql、remote),影响返回值类型,默认`异步模式`
|
|
1093
|
+
1. `templateResult`: 返回值类型断言,6种, R表示行,C表示列,带S表示复数
|
|
1094
|
+
1. R_C_Assert,
|
|
1095
|
+
2. R_C_NotSure,
|
|
1096
|
+
3. R_CS_Assert,
|
|
1097
|
+
4. R_CS_NotSure,
|
|
1098
|
+
5. RS_C,
|
|
1099
|
+
6. RS_C_List
|
|
1100
|
+
7. RS_CS[默认]
|
|
1101
|
+
8. RS_CS_List
|
|
1102
|
+
2. `sql` 或者 `sqlid`
|
|
1103
|
+
3. `params`
|
|
1104
|
+
4. `defValue`: One_Row_One_Column 时有效
|
|
1105
|
+
5. 禁止一次查询多个语句
|
|
1106
|
+
6. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
1107
|
+
7. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
1108
|
+
```
|
|
1109
|
+
service.transaction(async conn => {
|
|
1110
|
+
service.insert({conn});
|
|
1111
|
+
});
|
|
1112
|
+
```
|
|
1113
|
+
9. `dao`: 永远不需要传入该值
|
|
1114
|
+
10. `hump`: 是否将列名改为驼峰写法?默认情况下按照全局配置
|
|
1115
|
+
11. `mapper`: 列名-属性 映射工具,优先级高于hump
|
|
1116
|
+
```
|
|
1117
|
+
// 该属性支持传入mybatis.xml中定义的resultMap块ID,或者读取sqlMapDir目录下的JSON文件.
|
|
1118
|
+
// 注意:resultMap块ID与sql语句逻辑一致,同样是 目录.ID
|
|
1119
|
+
// 或者自定义Mapper,自定义Mapper格式如下:
|
|
1120
|
+
[
|
|
1121
|
+
{columnName: 'dit_id', mapNames: ['DTID'], def: 0, convert: 转换函数}, // 列名ditid,对应属性DTID,如果没有值,将返回默认值0,其中默认值0是可选的
|
|
1122
|
+
{columnName: 'event_id', mapNames: ['eventMainInfo', 'id'], def: 0, convert: 转换函数},// 列名event_id对应属性eventMainInfo.id,这种方式将返回嵌套的json对象,其中默认值null是可选的
|
|
1123
|
+
]
|
|
1124
|
+
```
|
|
1125
|
+
#TODO 未完成读取 sqlMapDir
|
|
1126
|
+
#### sqlMapDir 目录定义如下,
|
|
1127
|
+
`test.ts`
|
|
1128
|
+
```
|
|
1129
|
+
export const dict:SqlMappers = [
|
|
1130
|
+
{columnName: 'dit_id', mapNames: ['DTID'], def: 0, convert: 转换函数}, // 列名ditid,对应属性DTID,如果没有值,将返回默认值0,其中默认值0是可选的
|
|
1131
|
+
{columnName: 'event_id', mapNames: ['eventMainInfo', 'id'], def: 0, convert: 转换函数},// 列名event_id对应属性eventMainInfo.id,这种方式将返回嵌套的json对象,其中默认值null是可选的
|
|
1132
|
+
]
|
|
1133
|
+
```
|
|
1134
|
+
将得到 test.dict 这个map
|
|
1135
|
+
12. dataConvert 数据转换器
|
|
1136
|
+
```
|
|
1137
|
+
dataConvert: {
|
|
1138
|
+
fileName: 'qiniu'
|
|
1139
|
+
}
|
|
1140
|
+
// 表示列 fileName 按 qiniu的函数格式化
|
|
1141
|
+
// qiniu 在开始时定义
|
|
1142
|
+
```
|
|
1088
1143
|
*/
|
|
1089
1144
|
select<L = T>(option: MethodOption & {
|
|
1090
1145
|
sync?: SyncMode.Async;
|
|
@@ -1099,6 +1154,8 @@ export declare class SqlService<T extends object> {
|
|
|
1099
1154
|
hump?: boolean;
|
|
1100
1155
|
mapper?: string | SqlMapper;
|
|
1101
1156
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1157
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1158
|
+
dataConvert?: Record<string, string>;
|
|
1102
1159
|
}): Promise<L[]>;
|
|
1103
1160
|
select<L = T>(option: MethodOption & {
|
|
1104
1161
|
sync?: SyncMode.Async;
|
|
@@ -1113,6 +1170,8 @@ export declare class SqlService<T extends object> {
|
|
|
1113
1170
|
hump?: boolean;
|
|
1114
1171
|
mapper?: string | SqlMapper;
|
|
1115
1172
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1173
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1174
|
+
dataConvert?: Record<string, string>;
|
|
1116
1175
|
}): Promise<ArrayList<L>>;
|
|
1117
1176
|
select<L = T>(option: MethodOption & {
|
|
1118
1177
|
sync?: SyncMode.Async;
|
|
@@ -1127,6 +1186,8 @@ export declare class SqlService<T extends object> {
|
|
|
1127
1186
|
hump?: boolean;
|
|
1128
1187
|
mapper?: string | SqlMapper;
|
|
1129
1188
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1189
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1190
|
+
dataConvert?: Record<string, string>;
|
|
1130
1191
|
}): Promise<L>;
|
|
1131
1192
|
select<L = T>(option: MethodOption & {
|
|
1132
1193
|
sync?: SyncMode.Async;
|
|
@@ -1141,6 +1202,8 @@ export declare class SqlService<T extends object> {
|
|
|
1141
1202
|
hump?: boolean;
|
|
1142
1203
|
mapper?: string | SqlMapper;
|
|
1143
1204
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1205
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1206
|
+
dataConvert?: Record<string, string>;
|
|
1144
1207
|
}): Promise<L | null>;
|
|
1145
1208
|
select<L = T>(option: MethodOption & {
|
|
1146
1209
|
sync: SyncMode.Sync;
|
|
@@ -1155,6 +1218,8 @@ export declare class SqlService<T extends object> {
|
|
|
1155
1218
|
hump?: boolean;
|
|
1156
1219
|
mapper?: string | SqlMapper;
|
|
1157
1220
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1221
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1222
|
+
dataConvert?: Record<string, string>;
|
|
1158
1223
|
}): L[];
|
|
1159
1224
|
select<L = T>(option: MethodOption & {
|
|
1160
1225
|
sync: SyncMode.Sync;
|
|
@@ -1169,6 +1234,8 @@ export declare class SqlService<T extends object> {
|
|
|
1169
1234
|
hump?: boolean;
|
|
1170
1235
|
mapper?: string | SqlMapper;
|
|
1171
1236
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1237
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1238
|
+
dataConvert?: Record<string, string>;
|
|
1172
1239
|
}): ArrayList<L>;
|
|
1173
1240
|
select<L = T>(option: MethodOption & {
|
|
1174
1241
|
sync: SyncMode.Sync;
|
|
@@ -1183,6 +1250,8 @@ export declare class SqlService<T extends object> {
|
|
|
1183
1250
|
hump?: boolean;
|
|
1184
1251
|
mapper?: string | SqlMapper;
|
|
1185
1252
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1253
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1254
|
+
dataConvert?: Record<string, string>;
|
|
1186
1255
|
}): L;
|
|
1187
1256
|
select<L = T>(option: MethodOption & {
|
|
1188
1257
|
sync: SyncMode.Sync;
|
|
@@ -1197,6 +1266,8 @@ export declare class SqlService<T extends object> {
|
|
|
1197
1266
|
hump?: boolean;
|
|
1198
1267
|
mapper?: string | SqlMapper;
|
|
1199
1268
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1269
|
+
buildInConvert?: Record<keyof L, string>;
|
|
1270
|
+
dataConvert?: Record<string, string>;
|
|
1200
1271
|
}): L | null;
|
|
1201
1272
|
/**
|
|
1202
1273
|
# 自由执行sql
|
|
@@ -1205,14 +1276,14 @@ export declare class SqlService<T extends object> {
|
|
|
1205
1276
|
2. `params`
|
|
1206
1277
|
3. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
1207
1278
|
4. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1279
|
+
```
|
|
1280
|
+
service.transaction(async conn => {
|
|
1281
|
+
service.insert({conn});
|
|
1282
|
+
});
|
|
1283
|
+
```
|
|
1213
1284
|
5. `dao`: 永远不需要传入该值
|
|
1214
|
-
|
|
1215
|
-
|
|
1285
|
+
|
|
1286
|
+
*/
|
|
1216
1287
|
excute<L = T>(option: MethodOption & {
|
|
1217
1288
|
sync?: SyncMode.Async;
|
|
1218
1289
|
sqlId?: string;
|
|
@@ -1268,6 +1339,7 @@ export declare class SqlService<T extends object> {
|
|
|
1268
1339
|
hump?: boolean;
|
|
1269
1340
|
mapper?: string | SqlMapper;
|
|
1270
1341
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1342
|
+
dataConvert?: Record<string, string>;
|
|
1271
1343
|
}): Promise<PageQuery<L>>;
|
|
1272
1344
|
page<L = T>(option: MethodOption & {
|
|
1273
1345
|
sync: SyncMode.Sync;
|
|
@@ -1284,6 +1356,7 @@ export declare class SqlService<T extends object> {
|
|
|
1284
1356
|
hump?: boolean;
|
|
1285
1357
|
mapper?: string | SqlMapper;
|
|
1286
1358
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1359
|
+
dataConvert?: Record<string, string>;
|
|
1287
1360
|
}): PageQuery<L>;
|
|
1288
1361
|
/**
|
|
1289
1362
|
* 导出数据,可以为EJS-EXCEL直接使用
|
|
@@ -1326,16 +1399,16 @@ export declare class SqlService<T extends object> {
|
|
|
1326
1399
|
sync: SyncMode.Sync;
|
|
1327
1400
|
}): void;
|
|
1328
1401
|
/**
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1402
|
+
#创建表
|
|
1403
|
+
** `tableName` 表名称
|
|
1404
|
+
** `temp` 是否是临时表,默认true
|
|
1405
|
+
** `columns` 字符串数组,默认是当前实体类全部字段,通过`columns` 可以创建部分字段临时表
|
|
1406
|
+
** `id` 表的主键设置 4种:
|
|
1407
|
+
1. `auto`: `columns`中已经在当前实体类配置的ID作为主键 `默认`
|
|
1408
|
+
2. `all`: `columns`中所有字段全部当主键
|
|
1409
|
+
3. `none`: 没有主键
|
|
1410
|
+
4. 自定义字段名称:字符串数组
|
|
1411
|
+
** `index` 表的索引,设置方式同ID
|
|
1339
1412
|
*/
|
|
1340
1413
|
private _createTable;
|
|
1341
1414
|
private _matchSqlid;
|
|
@@ -1343,7 +1416,7 @@ export declare class SqlService<T extends object> {
|
|
|
1343
1416
|
private _generSql;
|
|
1344
1417
|
}
|
|
1345
1418
|
declare class StreamQuery<T extends object> {
|
|
1346
|
-
private _prefix;
|
|
1419
|
+
private readonly _prefix;
|
|
1347
1420
|
private _index;
|
|
1348
1421
|
private _wheres;
|
|
1349
1422
|
private _andQuerys;
|
|
@@ -1360,7 +1433,7 @@ declare class StreamQuery<T extends object> {
|
|
|
1360
1433
|
private _orders;
|
|
1361
1434
|
private _startRow;
|
|
1362
1435
|
private _pageSize;
|
|
1363
|
-
private _service;
|
|
1436
|
+
private readonly _service;
|
|
1364
1437
|
private [_fields];
|
|
1365
1438
|
private [_columns];
|
|
1366
1439
|
constructor(service: SqlService<T>, __fields: Record<string, AField>, __columns: string[]);
|
|
@@ -1371,6 +1444,8 @@ declare class StreamQuery<T extends object> {
|
|
|
1371
1444
|
/**
|
|
1372
1445
|
* AND(key1 = :value OR key2 = :value)
|
|
1373
1446
|
* @param keys [key1, key2, ...]
|
|
1447
|
+
* @param keys
|
|
1448
|
+
* @param value
|
|
1374
1449
|
*/
|
|
1375
1450
|
eqs(keys: (keyof T)[], value: string | number, { paramName, skipEmptyString, breakExcuteIfSkip }?: {
|
|
1376
1451
|
paramName?: string | undefined;
|
|
@@ -1689,6 +1764,7 @@ declare class StreamQuery<T extends object> {
|
|
|
1689
1764
|
update(key: keyof T, value: T[keyof T]): this;
|
|
1690
1765
|
update2(sql: string, param?: Record<string, any>): this;
|
|
1691
1766
|
updateT(t: Partial<T>): this;
|
|
1767
|
+
/** SET key = REPLACE(key, :valueToFind, :valueToReplace) */
|
|
1692
1768
|
replace(key: keyof T, valueToFind: T[keyof T], valueToReplace: T[keyof T]): this;
|
|
1693
1769
|
excuteSelect<L = T>(option?: MethodOption & {
|
|
1694
1770
|
sync?: SyncMode.Async;
|
|
@@ -1753,6 +1829,7 @@ declare class StreamQuery<T extends object> {
|
|
|
1753
1829
|
hump?: boolean;
|
|
1754
1830
|
mapper?: string | SqlMapper;
|
|
1755
1831
|
mapperIfUndefined?: MapperIfUndefined;
|
|
1832
|
+
dataConvert?: Record<string, string>;
|
|
1756
1833
|
}): PageQuery<L> | Promise<PageQuery<L>>;
|
|
1757
1834
|
excuteUpdate(option?: MethodOption & {
|
|
1758
1835
|
sync?: SyncMode.Async;
|