baja-lite 1.0.5 → 1.0.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/cjs/boot-remote.d.ts +2 -2
- package/cjs/code.js +19 -5
- package/cjs/convert-xml.js +5 -5
- package/cjs/fn.js +3 -3
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +1 -0
- package/cjs/list.d.ts +10 -0
- package/cjs/list.js +36 -0
- package/cjs/object.js +4 -4
- package/cjs/set-ex.d.ts +41 -15
- package/cjs/set-ex.js +68 -52
- package/cjs/sql.d.ts +391 -193
- package/cjs/sql.js +580 -287
- package/cjs/test-mysql.d.ts +1 -0
- package/cjs/test-mysql.js +15 -2
- package/es/boot-remote.d.ts +2 -2
- package/es/code.js +19 -5
- package/es/convert-xml.js +5 -5
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/list.d.ts +10 -0
- package/es/list.js +32 -0
- package/es/object.js +1 -1
- package/es/set-ex.d.ts +41 -15
- package/es/set-ex.js +68 -52
- package/es/sql.d.ts +391 -193
- package/es/sql.js +569 -277
- package/es/test-mysql.d.ts +1 -0
- package/es/test-mysql.js +15 -3
- package/package.json +8 -6
- package/src/boot-remote.ts +2 -2
- package/src/code.ts +24 -8
- package/src/convert-xml.ts +5 -6
- package/src/index.ts +2 -1
- package/src/list.ts +31 -0
- package/src/object.ts +4 -3
- package/src/set-ex.ts +91 -70
- package/src/sql.ts +647 -318
- package/src/test-mysql.ts +28 -9
package/src/sql.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { C2P, C2P2, P2C } from './object';
|
|
|
11
11
|
import { format } from 'sql-formatter';
|
|
12
12
|
import HTML from 'html-parse-stringify';
|
|
13
13
|
import { XML, convert } from './convert-xml';
|
|
14
|
+
import { ArrayList } from './list';
|
|
15
|
+
import LGet from 'lodash.get';
|
|
14
16
|
|
|
15
17
|
// #region 常量
|
|
16
18
|
const _daoDBName = Symbol('dbName');
|
|
@@ -37,6 +39,8 @@ const _inTransaction = Symbol('inTransaction');
|
|
|
37
39
|
const _daoDB = Symbol('daoDB');
|
|
38
40
|
const _sqliteRemoteName = Symbol('sqliteRemoteName');
|
|
39
41
|
const _SqlOption = Symbol('SqlOption');
|
|
42
|
+
const _resultMap = Symbol('resultMap');
|
|
43
|
+
const _resultMap_SQLID = Symbol('resultMap_SQLID');
|
|
40
44
|
export const _Hump = Symbol('Hump');
|
|
41
45
|
export const _GlobalSqlOption = Symbol('GlobalSqlOption');
|
|
42
46
|
export const _EventBus = Symbol('EventBus');
|
|
@@ -49,10 +53,12 @@ export const logger =
|
|
|
49
53
|
target: 'pino-pretty'
|
|
50
54
|
}
|
|
51
55
|
}) : pino({ name: 'sql' });
|
|
56
|
+
globalThis[_resultMap_SQLID] = {};
|
|
52
57
|
// #endregion
|
|
53
58
|
|
|
54
59
|
// #region 可选配置
|
|
55
|
-
export enum DBType { Mysql, Sqlite, Mongo, SqliteRemote, Redis, RedisLock }
|
|
60
|
+
export enum DBType { Mysql, Sqlite, Mongo, SqliteRemote, Redis, RedisLock };
|
|
61
|
+
export enum MapperIfUndefined { Null, Skip, Zero, EmptyString };
|
|
56
62
|
export enum SyncMode {
|
|
57
63
|
/** 同步执行 */
|
|
58
64
|
Sync,
|
|
@@ -124,16 +130,28 @@ export enum TemplateResult {
|
|
|
124
130
|
NotSureOne,
|
|
125
131
|
/** 返回多条记录 */
|
|
126
132
|
Many,
|
|
133
|
+
/** 返回多条记录并封装ArrayList */
|
|
134
|
+
ManyList,
|
|
127
135
|
/** 仅查询记录数量 */
|
|
128
136
|
Count
|
|
129
137
|
}
|
|
130
138
|
export enum SelectResult {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
/** 一行一列 确定非空 */
|
|
140
|
+
R_C_Assert,
|
|
141
|
+
/** 一行一列 可能空 */
|
|
142
|
+
R_C_NotSure,
|
|
143
|
+
/** 一行多列 确定非空 */
|
|
144
|
+
R_CS_Assert,
|
|
145
|
+
/** 一行多列 可能空 */
|
|
146
|
+
R_CS_NotSure,
|
|
147
|
+
/** 多行一列 */
|
|
148
|
+
RS_C,
|
|
149
|
+
/** 多行一列并封装ArrayList */
|
|
150
|
+
RS_C_List,
|
|
151
|
+
/** 多行多列 */
|
|
152
|
+
RS_CS,
|
|
153
|
+
/** 多行多列并封装ArrayList */
|
|
154
|
+
RS_CS_List
|
|
137
155
|
}
|
|
138
156
|
export enum SqlType {
|
|
139
157
|
tinyint,
|
|
@@ -243,7 +261,7 @@ interface ServiceOption {
|
|
|
243
261
|
```
|
|
244
262
|
可以继承该接口来约束格式
|
|
245
263
|
*/
|
|
246
|
-
export interface
|
|
264
|
+
export interface GlobalSqlOptionForWeb {
|
|
247
265
|
/** 增改忽略Undefined */
|
|
248
266
|
skipUndefined?: boolean;
|
|
249
267
|
/** 增改忽略NULL */
|
|
@@ -277,12 +295,20 @@ export interface GlobalSqlOption2 {
|
|
|
277
295
|
作用与sqlDir类似,不同在于sqlMap`不需要`目录,而是直接指定一个sqlModel对象,对象的格式和sqlDir的文件内容一样。
|
|
278
296
|
** 适用于简单使用
|
|
279
297
|
*/
|
|
280
|
-
sqlMap?:
|
|
298
|
+
sqlMap?: _SqlModel;
|
|
281
299
|
/**
|
|
282
300
|
作用与sqlFnDir类似,不同在于sqlFNMap`不需要`目录,而是直接指定一个 Record<string, string>,对象的格式和sqlFnDir的文件内容一样。
|
|
283
301
|
** 适用于简单使用
|
|
284
302
|
*/
|
|
285
303
|
sqlFNMap?: Record<string, string>;
|
|
304
|
+
/**
|
|
305
|
+
// 第一个元素=列名,第二个元素是属性路径,
|
|
306
|
+
[
|
|
307
|
+
['dit_id', ['id']], // 列名ditid,对应属性id
|
|
308
|
+
['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
|
|
309
|
+
]
|
|
310
|
+
*/
|
|
311
|
+
sqlMapperMap?: SqlMappers;
|
|
286
312
|
}
|
|
287
313
|
/**
|
|
288
314
|
# 全局行为配置文件
|
|
@@ -296,7 +322,7 @@ export interface GlobalSqlOption2 {
|
|
|
296
322
|
```
|
|
297
323
|
可以继承该接口来约束格式
|
|
298
324
|
*/
|
|
299
|
-
export interface GlobalSqlOption extends
|
|
325
|
+
export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
|
|
300
326
|
/**
|
|
301
327
|
初始化MYSQL链接 支持多数据源
|
|
302
328
|
## 单一数据源: 直接传入Mysql2的连接配置
|
|
@@ -372,9 +398,25 @@ export interface GlobalSqlOption extends GlobalSqlOption2 {
|
|
|
372
398
|
sqlDir?: string;
|
|
373
399
|
/**
|
|
374
400
|
## [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)
|
|
375
|
-
|
|
401
|
+
## 文件名就是模板名
|
|
376
402
|
*/
|
|
377
403
|
sqlFNDir?: string;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
## 映射数据为对象,文件名就是模板名
|
|
407
|
+
```
|
|
408
|
+
// 第一个元素=列名,第二个元素是属性路径,
|
|
409
|
+
// 该目录下可存放json文件,内容如下
|
|
410
|
+
//
|
|
411
|
+
// 可以在查询时使用,优先级高于hump
|
|
412
|
+
// 例如:
|
|
413
|
+
[
|
|
414
|
+
['dit_id', ['id'], 可选的默认值], // 列名ditid,对应属性id,当未查询返回时,使用默认值
|
|
415
|
+
['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id,当未查询返回时,该属性不存在
|
|
416
|
+
]
|
|
417
|
+
```
|
|
418
|
+
*/
|
|
419
|
+
sqlMapperDir?: string;
|
|
378
420
|
/**
|
|
379
421
|
[REDIS初始化文档](https://github.com/redis/ioredis?tab=readme-ov-file#:~:text=connect%20to%20by%3A-,new%20Redis()%3B,-//%20Connect%20to%20127.0.0.1)
|
|
380
422
|
```
|
|
@@ -415,6 +457,11 @@ export interface GlobalSqlOption extends GlobalSqlOption2 {
|
|
|
415
457
|
* ```
|
|
416
458
|
*/
|
|
417
459
|
columnMode?: ColumnMode;
|
|
460
|
+
/**
|
|
461
|
+
* 读取查询语句时,是否扫描JS文件?
|
|
462
|
+
* JS文件需要默认导出一个 SqlModel对象
|
|
463
|
+
*/
|
|
464
|
+
jsMode?: boolean;
|
|
418
465
|
}
|
|
419
466
|
|
|
420
467
|
interface FieldOption extends Object {
|
|
@@ -1231,6 +1278,8 @@ export class SqliteRemote implements Dao {
|
|
|
1231
1278
|
// #endregion
|
|
1232
1279
|
|
|
1233
1280
|
// #region 查询sql
|
|
1281
|
+
export type SqlMapper = ([string, string[], any?])[];
|
|
1282
|
+
export type SqlMappers = Record<string, SqlMapper>;
|
|
1234
1283
|
export type SqlModel = Record<string, string | (
|
|
1235
1284
|
(options: {
|
|
1236
1285
|
ctx: any;
|
|
@@ -1241,6 +1290,17 @@ export type SqlModel = Record<string, string | (
|
|
|
1241
1290
|
orderBy?: string;
|
|
1242
1291
|
[k: string]: any;
|
|
1243
1292
|
}) => string
|
|
1293
|
+
)>;
|
|
1294
|
+
type _SqlModel = Record<string, string | (
|
|
1295
|
+
(options: {
|
|
1296
|
+
ctx: any;
|
|
1297
|
+
isCount?: boolean;
|
|
1298
|
+
isSum?: boolean;
|
|
1299
|
+
limitStart?: number;
|
|
1300
|
+
limitEnd?: number;
|
|
1301
|
+
orderBy?: string;
|
|
1302
|
+
[k: string]: any;
|
|
1303
|
+
}) => string
|
|
1244
1304
|
) | XML[]>;
|
|
1245
1305
|
class Build {
|
|
1246
1306
|
private static page = 'COUNT(1) zccw1986 ';
|
|
@@ -1525,30 +1585,65 @@ function replaceCdata(rawText: string) {
|
|
|
1525
1585
|
}
|
|
1526
1586
|
return rawText;
|
|
1527
1587
|
}
|
|
1528
|
-
|
|
1529
|
-
|
|
1588
|
+
function _flatData(result: any, i: number, length: number, keys: string[], V: any) {
|
|
1589
|
+
const key = keys[i];
|
|
1590
|
+
if (i < length) {
|
|
1591
|
+
result[key!] ??= {};
|
|
1592
|
+
i++;
|
|
1593
|
+
_flatData(result[key!], i, length, keys, V);
|
|
1594
|
+
} else {
|
|
1595
|
+
result[key!] = V;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
/**
|
|
1599
|
+
* ifUndefined默认是MapperIfUndefined.Skip
|
|
1600
|
+
*/
|
|
1601
|
+
export function flatData<M>(options: { data: any; mapper: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): M {
|
|
1602
|
+
if (typeof options.mapper === 'string') {
|
|
1603
|
+
const name = options.mapper;
|
|
1604
|
+
options.mapper = globalThis[_resultMap][name];
|
|
1605
|
+
Throw.if(!options.mapper, `not found mapper!${name}`);
|
|
1606
|
+
}
|
|
1607
|
+
options.mapperIfUndefined ??= MapperIfUndefined.Skip;
|
|
1608
|
+
options.mapper = options.mapper as SqlMapper;
|
|
1609
|
+
const result: any = {};
|
|
1610
|
+
for (const [columnName, keys, def] of options.mapper) {
|
|
1611
|
+
let V = options.data[columnName];
|
|
1612
|
+
if (V === undefined) {
|
|
1613
|
+
if (options.mapperIfUndefined === MapperIfUndefined.Null) {
|
|
1614
|
+
V = null;
|
|
1615
|
+
} else if (options.mapperIfUndefined === MapperIfUndefined.Zero) {
|
|
1616
|
+
V = 0;
|
|
1617
|
+
} else if (options.mapperIfUndefined === MapperIfUndefined.EmptyString) {
|
|
1618
|
+
V = '';
|
|
1619
|
+
} else if (def !== undefined) {
|
|
1620
|
+
V = def;
|
|
1621
|
+
} else {
|
|
1622
|
+
continue;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
_flatData(result, 0, keys.length - 1, keys, V);
|
|
1626
|
+
}
|
|
1627
|
+
return result;
|
|
1628
|
+
}
|
|
1530
1629
|
|
|
1531
1630
|
export class SqlCache {
|
|
1532
|
-
private sqlMap:
|
|
1631
|
+
private sqlMap: _SqlModel = {};
|
|
1533
1632
|
private sqlFNMap: PartialsOrLookupFn = {};
|
|
1534
|
-
async
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
if (options.sqlDir) {
|
|
1543
|
-
const sqlFis = globalThis[_fs].readdirSync(options.sqlDir);
|
|
1544
|
-
for (const modeName of sqlFis) {
|
|
1545
|
-
logger.debug(`sql: ${modeName} start explain!`);
|
|
1633
|
+
private async _read(jsMode: boolean, sqlDir: string, queryTypes: string[], rootName: string) {
|
|
1634
|
+
const sqlFis = globalThis[_fs].readdirSync(sqlDir);
|
|
1635
|
+
for (const modeName of sqlFis) {
|
|
1636
|
+
const file = globalThis[_path].join(sqlDir, modeName);
|
|
1637
|
+
const stat = globalThis[_fs].statSync(file);
|
|
1638
|
+
if (stat.isDirectory()) {
|
|
1639
|
+
await this._read(jsMode, file, queryTypes, modeName);
|
|
1640
|
+
} else {
|
|
1546
1641
|
const extname = globalThis[_path].extname(modeName);
|
|
1547
1642
|
const name = globalThis[_path].basename(modeName, extname);
|
|
1548
|
-
const file = globalThis[_path].join(options.sqlDir, modeName);
|
|
1549
1643
|
let ct = 0;
|
|
1550
1644
|
if (extname === '.mu') {
|
|
1551
|
-
|
|
1645
|
+
logger.debug(`sql: ${file} start explain!`);
|
|
1646
|
+
const parser = new MUParser(rootName || name, globalThis[_fs].readFileSync(file, { encoding: 'utf-8' }).toString());
|
|
1552
1647
|
let source = parser.next();
|
|
1553
1648
|
while (source != null) {
|
|
1554
1649
|
ct++;
|
|
@@ -1556,37 +1651,91 @@ export class SqlCache {
|
|
|
1556
1651
|
logger.debug(`sql: ${source[0]} found!`);
|
|
1557
1652
|
source = parser.next();
|
|
1558
1653
|
}
|
|
1559
|
-
|
|
1560
|
-
} else if (extname === '.js') {
|
|
1561
|
-
|
|
1654
|
+
logger.debug(`sql: ${file} explain over[${ct}]!`);
|
|
1655
|
+
} else if (jsMode === true && extname === '.js') {
|
|
1656
|
+
logger.debug(`sql: ${file} start explain!`);
|
|
1657
|
+
const obj = (await import(globalThis[_path].join(sqlDir, modeName))).default as _SqlModel;
|
|
1562
1658
|
for (const [key, fn] of Object.entries(obj)) {
|
|
1563
1659
|
ct++;
|
|
1564
1660
|
|
|
1565
|
-
this.sqlMap[`${name}.${String(key)}`] = fn;
|
|
1661
|
+
this.sqlMap[`${rootName || name}.${String(key)}`] = fn;
|
|
1566
1662
|
}
|
|
1663
|
+
logger.debug(`sql: ${file} explain over[${ct}]!`);
|
|
1567
1664
|
} else if (extname === '.xml') {
|
|
1665
|
+
logger.debug(`sql: ${file} start explain!`);
|
|
1568
1666
|
const root = (HTML.parse(replaceCdata(globalThis[_fs].readFileSync(file, { encoding: 'utf-8' }).toString())) as XML[])[0];
|
|
1569
|
-
if(root){
|
|
1667
|
+
if (root) {
|
|
1570
1668
|
const mappers = root.children;
|
|
1571
1669
|
for (const mapper of mappers) {
|
|
1572
|
-
console.log(mapper);
|
|
1573
1670
|
if (mapper.type === 'tag' && mapper.name === 'mapper') {
|
|
1574
1671
|
for (const am of mapper.children) {
|
|
1575
1672
|
if (am.type === 'tag') {
|
|
1576
|
-
Throw.if(!queryTypes.includes(am.name), `${name}错误,${am.name}不支持!`);
|
|
1673
|
+
Throw.if(!queryTypes.includes(am.name), `${rootName} ${name}错误,${am.name}不支持!`);
|
|
1577
1674
|
am.id = am.attrs['id'];
|
|
1578
|
-
Throw.if(!am.id, `${name}错误,没有为此块设置id:${am}`);
|
|
1579
|
-
|
|
1675
|
+
Throw.if(!am.id, `${rootName} ${name}错误,没有为此块设置id:${am}`);
|
|
1676
|
+
if (am.name === 'resultMap') {
|
|
1677
|
+
ct++;
|
|
1678
|
+
globalThis[_resultMap] ??= {};
|
|
1679
|
+
const keys: SqlMapper = [];
|
|
1680
|
+
this.readResultMap(am.children, keys, []);
|
|
1681
|
+
globalThis[_resultMap][am.id!] = keys;
|
|
1682
|
+
logger.debug(`sql_resultMap: ${am.id!} found!`);
|
|
1683
|
+
} else {
|
|
1684
|
+
this.sqlMap[`${rootName || name}.${am.id!}`] = am.children;
|
|
1685
|
+
if (am.attrs['resultMap']) {
|
|
1686
|
+
globalThis[_resultMap_SQLID][`${rootName || name}.${am.id!}`] = am.attrs['resultMap'];
|
|
1687
|
+
logger.debug(`sql: autoMapper: ${rootName || name}.${am.id!}-${am.attrs['resultMap']}`);
|
|
1688
|
+
}
|
|
1689
|
+
logger.debug(`sql: ${rootName || name}.${am.id!} found!`);
|
|
1690
|
+
ct++;
|
|
1691
|
+
}
|
|
1580
1692
|
}
|
|
1581
1693
|
}
|
|
1582
1694
|
}
|
|
1583
1695
|
}
|
|
1584
1696
|
}
|
|
1697
|
+
logger.debug(`sql: ${file} explain over[${ct}]!`);
|
|
1698
|
+
}
|
|
1585
1699
|
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
*
|
|
1705
|
+
* ```
|
|
1706
|
+
// 第一个元素=列名,第二个元素是属性路径,
|
|
1707
|
+
[
|
|
1708
|
+
['dit_id', ['id']], // 列名ditid,对应属性id
|
|
1709
|
+
['event_id', ['eventMainInfo', 'id']] // 列名event_id对应属性eventMainInfo.id
|
|
1710
|
+
]
|
|
1711
|
+
* ```
|
|
1712
|
+
* @param am
|
|
1713
|
+
* @param keys
|
|
1714
|
+
*/
|
|
1715
|
+
private readResultMap(ams: XML[], keys: SqlMapper, key: string[]) {
|
|
1716
|
+
for (const am of ams) {
|
|
1717
|
+
if (am.type === 'tag') {
|
|
1718
|
+
if (am.name === 'result' || am.name === 'id') {
|
|
1719
|
+
keys.push([am.attrs['column']!, [...key, am.attrs['property']!]]);
|
|
1720
|
+
} else {
|
|
1721
|
+
this.readResultMap(am.children, keys, [...key, am.attrs['property']!])
|
|
1586
1722
|
}
|
|
1587
|
-
logger.debug(`sql: ${modeName} explain over[${ct}]!`);
|
|
1588
1723
|
}
|
|
1589
1724
|
}
|
|
1725
|
+
}
|
|
1726
|
+
async init(options: {
|
|
1727
|
+
sqlMap?: _SqlModel; sqlDir?: string;
|
|
1728
|
+
sqlFNMap?: Record<string, string>; sqlFNDir?: string;
|
|
1729
|
+
sqlMapperMap?: SqlMappers; sqlMapperDir?: string;
|
|
1730
|
+
jsMode?: boolean;
|
|
1731
|
+
}) {
|
|
1732
|
+
if (options.sqlMap) {
|
|
1733
|
+
this.sqlMap = options.sqlMap;
|
|
1734
|
+
}
|
|
1735
|
+
const queryTypes = ['sql', 'select', 'insert', 'update', 'delete', 'resultMap'];
|
|
1736
|
+
if (options.sqlDir) {
|
|
1737
|
+
await this._read(options.jsMode === true, options.sqlDir, queryTypes, '');
|
|
1738
|
+
}
|
|
1590
1739
|
if (options.sqlFNMap) {
|
|
1591
1740
|
this.sqlFNMap = options.sqlFNMap;
|
|
1592
1741
|
}
|
|
@@ -1601,6 +1750,21 @@ export class SqlCache {
|
|
|
1601
1750
|
}
|
|
1602
1751
|
}
|
|
1603
1752
|
}
|
|
1753
|
+
if (options.sqlMapperMap) {
|
|
1754
|
+
globalThis[_resultMap] = options.sqlFNMap;
|
|
1755
|
+
}
|
|
1756
|
+
if (options.sqlMapperDir) {
|
|
1757
|
+
const sqlFis = globalThis[_fs].readdirSync(options.sqlDir);
|
|
1758
|
+
globalThis[_resultMap] ??= {};
|
|
1759
|
+
for (const modeName of sqlFis) {
|
|
1760
|
+
const extname = globalThis[_path].extname(modeName);
|
|
1761
|
+
const name = globalThis[_path].basename(modeName, extname);
|
|
1762
|
+
const file = globalThis[_path].join(options.sqlDir, modeName);
|
|
1763
|
+
if (extname === 'json') {
|
|
1764
|
+
globalThis[_resultMap][name] = JSON.parse(globalThis[_fs].readFileSync(file, { encoding: 'utf-8' }).toString());
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1604
1768
|
}
|
|
1605
1769
|
load(sqlids: string[], options: {
|
|
1606
1770
|
ctx: any;
|
|
@@ -1620,17 +1784,19 @@ export class SqlCache {
|
|
|
1620
1784
|
}
|
|
1621
1785
|
const matchSqlid = sqlids.map(i => i.split('.')[0]!);
|
|
1622
1786
|
Throw.if(!sqlSource, `指定的语句${sqlids.join('|')}不存在!`);
|
|
1787
|
+
const buildParam = new Build(options.isCount === true, options.isSum === true, options);
|
|
1623
1788
|
if (typeof sqlSource === 'function') {
|
|
1624
1789
|
const _sql = sqlSource(options);
|
|
1625
|
-
const buildParam = new Build(options.isCount === true, options.isSum === true, options);
|
|
1626
1790
|
const sql = mustache.render(_sql, buildParam, this.sqlFNMap);
|
|
1627
1791
|
return format(sql);
|
|
1628
1792
|
} else if (typeof sqlSource === 'string') {
|
|
1629
|
-
const buildParam = new Build(options.isCount === true, options.isSum === true, options);
|
|
1630
1793
|
const sql = mustache.render(sqlSource, buildParam, this.sqlFNMap);
|
|
1631
1794
|
return format(sql);
|
|
1632
1795
|
} else if (typeof sqlSource === 'object') {
|
|
1633
|
-
const
|
|
1796
|
+
const _sql = convert(sqlSource, options, matchSqlid, this.sqlMap as Record<string, XML[]>);
|
|
1797
|
+
console.log(_sql);
|
|
1798
|
+
const sql = mustache.render(_sql, buildParam, this.sqlFNMap);
|
|
1799
|
+
console.log(sql);
|
|
1634
1800
|
return format(sql);
|
|
1635
1801
|
}
|
|
1636
1802
|
return '';
|
|
@@ -2771,9 +2937,10 @@ export class SqlService<T extends object> {
|
|
|
2771
2937
|
)`;
|
|
2772
2938
|
}).join(' OR ');
|
|
2773
2939
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2940
|
+
params.unshift(this[_deleteState]);
|
|
2774
2941
|
sqls.push({
|
|
2775
2942
|
sql: format(`
|
|
2776
|
-
UPDATE ${tableNameESC} SET ${this[_fields]![this[_stateFileName]]?.C2()} =
|
|
2943
|
+
UPDATE ${tableNameESC} SET ${this[_fields]![this[_stateFileName]]?.C2()} = ?
|
|
2777
2944
|
WHERE ${whereSql};
|
|
2778
2945
|
`), params
|
|
2779
2946
|
});
|
|
@@ -2790,7 +2957,8 @@ export class SqlService<T extends object> {
|
|
|
2790
2957
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2791
2958
|
sqls.push({
|
|
2792
2959
|
sql: format(`UPDATE ${tableNameESC} a INNER JOIN ${tableTempESC} b ON ${delWhere.map(K => `a.${this[_fields]![K]?.C2()} = b.${this[_fields]![K]?.C2()}`).join(' AND ')}
|
|
2793
|
-
SET a.${this[_fields]![this[_stateFileName]]?.C2()} =
|
|
2960
|
+
SET a.${this[_fields]![this[_stateFileName]]?.C2()} = ?;`),
|
|
2961
|
+
params: [this[_deleteState]]
|
|
2794
2962
|
});
|
|
2795
2963
|
} else {
|
|
2796
2964
|
sqls.push({
|
|
@@ -2804,8 +2972,9 @@ export class SqlService<T extends object> {
|
|
|
2804
2972
|
const columnNames = iterare(delWhere).map(K => this[_fields]![K]?.C2()).join(',');
|
|
2805
2973
|
if (this[_stateFileName] !== undefined && option.forceDelete !== true) {
|
|
2806
2974
|
sqls.push({
|
|
2807
|
-
sql: format(`UPDATE ${tableNameESC} SET ${this[_fields]![this[_stateFileName]]?.C2()} =
|
|
2808
|
-
WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`)
|
|
2975
|
+
sql: format(`UPDATE ${tableNameESC} SET ${this[_fields]![this[_stateFileName]]?.C2()} = ?
|
|
2976
|
+
WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`),
|
|
2977
|
+
params: [this[_deleteState]]
|
|
2809
2978
|
});
|
|
2810
2979
|
} else {
|
|
2811
2980
|
sqls.push({ sql: format(`DELETE FROM ${tableNameESC} WHERE (${columnNames}) IN (SELECT ${columnNames} FROM ${tableTempESC});`) });
|
|
@@ -2869,6 +3038,9 @@ export class SqlService<T extends object> {
|
|
|
2869
3038
|
case TemplateResult.Count: {
|
|
2870
3039
|
return result[0].ct;
|
|
2871
3040
|
}
|
|
3041
|
+
case TemplateResult.ManyList: {
|
|
3042
|
+
return new ArrayList(result[0]);
|
|
3043
|
+
}
|
|
2872
3044
|
}
|
|
2873
3045
|
}
|
|
2874
3046
|
/**
|
|
@@ -2894,20 +3066,18 @@ export class SqlService<T extends object> {
|
|
|
2894
3066
|
8. `dao`: 永远不需要传入该值
|
|
2895
3067
|
|
|
2896
3068
|
*/
|
|
2897
|
-
template<L = T>(option: MethodOption & { templateResult?: TemplateResult.AssertOne; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<L>;
|
|
2898
3069
|
template<L = T>(option: MethodOption & { sync: SyncMode.Sync; templateResult?: TemplateResult.AssertOne; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): L;
|
|
2899
|
-
template<L = T>(option: MethodOption & { sync
|
|
2900
|
-
template<L = T>(option: MethodOption & { templateResult: TemplateResult.Count; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<number>;
|
|
3070
|
+
template<L = T>(option: MethodOption & { sync?: SyncMode.Async; templateResult?: TemplateResult.AssertOne; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<L>;
|
|
2901
3071
|
template<L = T>(option: MethodOption & { sync: SyncMode.Sync; templateResult: TemplateResult.Count; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): number;
|
|
2902
|
-
template<L = T>(option: MethodOption & { sync
|
|
2903
|
-
template<L = T>(option: MethodOption & { templateResult: TemplateResult.NotSureOne; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<L | null>;
|
|
3072
|
+
template<L = T>(option: MethodOption & { sync?: SyncMode.Async; templateResult: TemplateResult.Count; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<number>;
|
|
2904
3073
|
template<L = T>(option: MethodOption & { sync: SyncMode.Sync; templateResult: TemplateResult.NotSureOne; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): L | null;
|
|
2905
|
-
template<L = T>(option: MethodOption & { sync
|
|
2906
|
-
template<L = T>(option: MethodOption & { templateResult: TemplateResult.Many; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<L[]>;
|
|
3074
|
+
template<L = T>(option: MethodOption & { sync?: SyncMode.Async; templateResult: TemplateResult.NotSureOne; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<L | null>;
|
|
2907
3075
|
template<L = T>(option: MethodOption & { sync: SyncMode.Sync; templateResult: TemplateResult.Many; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): L[];
|
|
2908
|
-
template<L = T>(option: MethodOption & { sync
|
|
3076
|
+
template<L = T>(option: MethodOption & { sync?: SyncMode.Async; templateResult: TemplateResult.Many; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<L[]>;
|
|
3077
|
+
template<L = T>(option: MethodOption & { sync: SyncMode.Sync; templateResult: TemplateResult.ManyList; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): ArrayList<L>;
|
|
3078
|
+
template<L = T>(option: MethodOption & { sync?: SyncMode.Async; templateResult: TemplateResult.ManyList; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): Promise<ArrayList<L>>;
|
|
2909
3079
|
@P<T>()
|
|
2910
|
-
template<L = T>(option: MethodOption & { sync?: SyncMode; templateResult?: TemplateResult; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): number | L | null | L[] | Promise<number | L | null | L[]
|
|
3080
|
+
template<L = T>(option: MethodOption & { sync?: SyncMode; templateResult?: TemplateResult; id?: string | number | Array<string | number>; where?: Partial<L> | Array<Partial<L>>; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; mode?: SelectMode; error?: string; columns?: (keyof L)[]; }): number | L | null | L[] | ArrayList<L> | Promise<number | L | null | L[] | ArrayList<L>> {
|
|
2911
3081
|
Throw.if(!!this[_ids] && this[_ids].length > 1 && !option.where, 'muit id must set where!');
|
|
2912
3082
|
Throw.if((!this[_ids] || this[_ids].length === 0) && !option.where, 'if not set id on class, must set where!');
|
|
2913
3083
|
Throw.if(!option.id && !option.where, 'not found id or where!');
|
|
@@ -2980,100 +3150,75 @@ export class SqlService<T extends object> {
|
|
|
2980
3150
|
}
|
|
2981
3151
|
}
|
|
2982
3152
|
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
}
|
|
2992
|
-
case SelectResult.One_Row_One_Column_Assert: {
|
|
2993
|
-
try {
|
|
2994
|
-
return iterare(result).map((r: any) => Object.values(r)[0] as L).filter((r: L) => r !== null).toArray();
|
|
2995
|
-
} catch (error) {
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
case SelectResult.One_Row_Many_Column_NotSure: {
|
|
2999
|
-
try {
|
|
3000
|
-
if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3001
|
-
return result.map((r: any) => C2P2(r[0]) as L);
|
|
3002
|
-
}
|
|
3003
|
-
return result.map((r: any) => r[0] as L);
|
|
3004
|
-
} catch (error) {
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
case SelectResult.One_Row_Many_Column_Assert: {
|
|
3008
|
-
try {
|
|
3009
|
-
if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3010
|
-
return iterare(result).map((r: any) => C2P2(r[0]) as L).filter((r: L) => r !== null).toArray();
|
|
3011
|
-
}
|
|
3012
|
-
return iterare(result).map((r: any) => r[0] as L).filter((r: L) => r !== null).toArray();
|
|
3013
|
-
} catch (error) {
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
case SelectResult.Many_Row_One_Column: {
|
|
3017
|
-
try {
|
|
3018
|
-
return result.map((rx: any) => rx.map((r: any) => Object.values(r)[0] as L));
|
|
3019
|
-
} catch (error) {
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
case SelectResult.Many_Row_Many_Column: {
|
|
3023
|
-
if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3024
|
-
return iterare(result).map((r: any) => r.map((rr: any) => C2P2(rr) as L)).toArray();
|
|
3025
|
-
} else {
|
|
3026
|
-
return result as L[];
|
|
3027
|
-
}
|
|
3153
|
+
|
|
3154
|
+
private _select<L = T>(templateResult: SelectResult, result: any, def: L | null, errorMsg?: string, hump?: boolean, mapper?: string | SqlMapper, mapperIfUndefined?: MapperIfUndefined) {
|
|
3155
|
+
switch (templateResult) {
|
|
3156
|
+
case SelectResult.R_C_NotSure: {
|
|
3157
|
+
try {
|
|
3158
|
+
return Object.values(result[0])[0] as L;
|
|
3159
|
+
} catch (error) {
|
|
3160
|
+
return def;
|
|
3028
3161
|
}
|
|
3029
3162
|
}
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
return def;
|
|
3037
|
-
}
|
|
3163
|
+
case SelectResult.R_C_Assert: {
|
|
3164
|
+
try {
|
|
3165
|
+
return Object.values(result[0])[0] as L;
|
|
3166
|
+
} catch (error) {
|
|
3167
|
+
if (def !== undefined) return def;
|
|
3168
|
+
Throw.now(errorMsg ?? 'not found data!');
|
|
3038
3169
|
}
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3170
|
+
}
|
|
3171
|
+
case SelectResult.R_CS_NotSure: {
|
|
3172
|
+
if (mapper) {
|
|
3173
|
+
return flatData<L>({ data: result[0], mapper, mapperIfUndefined });
|
|
3174
|
+
} else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3175
|
+
return (C2P2(result[0]) as L) ?? null;
|
|
3176
|
+
} else {
|
|
3177
|
+
return (result[0] as L) ?? null;
|
|
3046
3178
|
}
|
|
3047
|
-
case SelectResult.One_Row_Many_Column_NotSure: {
|
|
3048
|
-
if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3049
|
-
return (C2P2(result[0]) as L) ?? null;
|
|
3050
|
-
} else {
|
|
3051
|
-
return (result[0] as L) ?? null;
|
|
3052
|
-
}
|
|
3053
3179
|
|
|
3180
|
+
}
|
|
3181
|
+
case SelectResult.R_CS_Assert: {
|
|
3182
|
+
const data = result[0] as L;
|
|
3183
|
+
Throw.if(data === null || data === undefined, errorMsg ?? 'not found data!');
|
|
3184
|
+
if (mapper) {
|
|
3185
|
+
return flatData<L>({ data, mapper, mapperIfUndefined });
|
|
3186
|
+
} else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3187
|
+
return C2P2(data as any) ?? null;
|
|
3188
|
+
} else {
|
|
3189
|
+
return data ?? null;
|
|
3054
3190
|
}
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
return data ?? null;
|
|
3062
|
-
}
|
|
3191
|
+
}
|
|
3192
|
+
case SelectResult.RS_C: {
|
|
3193
|
+
try {
|
|
3194
|
+
return result.map((r: any) => Object.values(r)[0] as L);
|
|
3195
|
+
} catch (error) {
|
|
3196
|
+
return result as L[];
|
|
3063
3197
|
}
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3198
|
+
}
|
|
3199
|
+
case SelectResult.RS_CS: {
|
|
3200
|
+
if (mapper) {
|
|
3201
|
+
return iterare(result).map((data: any) => flatData<L>({ data, mapper, mapperIfUndefined })).toArray();
|
|
3202
|
+
} else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3203
|
+
return iterare(result).map((r: any) => C2P2(r) as L).toArray();
|
|
3204
|
+
} else {
|
|
3205
|
+
return result as L[];
|
|
3070
3206
|
}
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3207
|
+
}
|
|
3208
|
+
case SelectResult.RS_C_List: {
|
|
3209
|
+
try {
|
|
3210
|
+
return new ArrayList<L>(result.map((r: any) => Object.values(r)[0] as L));
|
|
3211
|
+
} catch (error) {
|
|
3212
|
+
return new ArrayList<L>();
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
case SelectResult.RS_CS_List: {
|
|
3216
|
+
if (mapper) {
|
|
3217
|
+
return new ArrayList<L>(iterare(result).map((data: any) => flatData<L>({ data, mapper, mapperIfUndefined })).toArray());
|
|
3218
|
+
} else if (hump === true || (hump === undefined && globalThis[_Hump] === true)) {
|
|
3219
|
+
return new ArrayList<L>(iterare(result).map((r: any) => C2P2(r) as L).toArray());
|
|
3220
|
+
} else {
|
|
3221
|
+
return new ArrayList<L>();
|
|
3077
3222
|
}
|
|
3078
3223
|
}
|
|
3079
3224
|
}
|
|
@@ -3081,20 +3226,19 @@ export class SqlService<T extends object> {
|
|
|
3081
3226
|
/**
|
|
3082
3227
|
# 自由查询
|
|
3083
3228
|
0. `sync`: 同步(sqlite)或者异步(mysql、remote),影响返回值类型,默认`异步模式`
|
|
3084
|
-
1. `templateResult`:
|
|
3085
|
-
1.
|
|
3086
|
-
2.
|
|
3087
|
-
3.
|
|
3088
|
-
4.
|
|
3089
|
-
5.
|
|
3090
|
-
6.
|
|
3229
|
+
1. `templateResult`: 返回值类型断言,6种, R表示行,C表示列,带S表示复数
|
|
3230
|
+
1. R_C_Assert,
|
|
3231
|
+
2. R_C_NotSure,
|
|
3232
|
+
3. R_CS_Assert,
|
|
3233
|
+
4. R_CS_NotSure,
|
|
3234
|
+
5. RS_C,
|
|
3235
|
+
6. RS_C_List
|
|
3236
|
+
7. RS_CS[默认]
|
|
3237
|
+
8. RS_CS_List
|
|
3091
3238
|
2. `sql` 或者 `sqlid`
|
|
3092
3239
|
3. `params`
|
|
3093
3240
|
4. `defValue`: One_Row_One_Column 时有效
|
|
3094
|
-
5.
|
|
3095
|
-
此时 `One_Row_One_Column` 将返回多个单值组成的数组: `[1, 'ok', 3]`
|
|
3096
|
-
`One_Row_Many_Column` 将返回多个对象组成的数组: `[{ob1}, {ob2}, {ob3}]`
|
|
3097
|
-
`Many_Row_One_Column` 将返回多个单值数组组成的数组: `[[1,2,3], ['a', 'b']]`
|
|
3241
|
+
5. 禁止一次查询多个语句
|
|
3098
3242
|
6. `dbName`: 默认使用service注解的`dbName`,可以在某个方法中覆盖
|
|
3099
3243
|
7. `conn`: 仅在开启事务时需要主动传入,传入示例:
|
|
3100
3244
|
```
|
|
@@ -3103,50 +3247,63 @@ export class SqlService<T extends object> {
|
|
|
3103
3247
|
});
|
|
3104
3248
|
```
|
|
3105
3249
|
9. `dao`: 永远不需要传入该值
|
|
3250
|
+
10. `hump`: 是否将列名改为驼峰写法?默认情况下按照全局配置
|
|
3251
|
+
11. `mapper`: 列名-属性 映射工具,优先级高于hump
|
|
3106
3252
|
|
|
3107
3253
|
*/
|
|
3108
|
-
select<L = T>(option: MethodOption & {
|
|
3109
|
-
select<L = T>(option: MethodOption & {
|
|
3110
|
-
select<L = T>(option: MethodOption & {
|
|
3111
|
-
select<L = T>(option: MethodOption & {
|
|
3112
|
-
select<L = T>(option: MethodOption & {
|
|
3113
|
-
select<L = T>(option: MethodOption & {
|
|
3254
|
+
select<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult?: SelectResult.RS_CS | SelectResult.RS_C; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<L[]>;
|
|
3255
|
+
select<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult: SelectResult.RS_CS_List | SelectResult.RS_C_List; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<ArrayList<L>>;
|
|
3256
|
+
select<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult: SelectResult.R_CS_Assert | SelectResult.R_C_Assert; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<L>;
|
|
3257
|
+
select<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult: SelectResult.R_CS_NotSure | SelectResult.R_C_NotSure; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<L | null>;
|
|
3258
|
+
select<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult?: SelectResult.RS_CS | SelectResult.RS_C; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): L[];
|
|
3259
|
+
select<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.RS_CS_List | SelectResult.RS_C_List; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): ArrayList<L>;
|
|
3260
|
+
select<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.R_CS_Assert | SelectResult.R_C_Assert; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): L;
|
|
3261
|
+
select<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.R_CS_NotSure | SelectResult.R_C_NotSure; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): L | null;
|
|
3114
3262
|
@P<T>()
|
|
3115
|
-
select<L = T>(option: MethodOption & {
|
|
3263
|
+
select<L = T>(option: MethodOption & { sync?: SyncMode; selectResult?: SelectResult; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; isCount?: boolean; defValue?: L | null; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): null | L | L[] | ArrayList<L> | Promise<null | L | L[] | ArrayList<L>> {
|
|
3116
3264
|
Throw.if(!option.sqlId && !option.sql, 'not found sql!');
|
|
3117
|
-
option.selectResult ??= SelectResult.
|
|
3265
|
+
option.selectResult ??= SelectResult.RS_CS;
|
|
3118
3266
|
option.defValue ??= null;
|
|
3267
|
+
if (option.sqlId && globalThis[_resultMap_SQLID][option.sqlId] && !option.mapper) {
|
|
3268
|
+
option.mapper = globalThis[_resultMap_SQLID][option.sqlId];
|
|
3269
|
+
}
|
|
3119
3270
|
const _params = Object.assign({}, option.context, option.params);
|
|
3120
3271
|
option.sql ??= globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: option.isCount, ..._params });
|
|
3121
3272
|
const params: any[] = [];
|
|
3122
|
-
const sql = option.sql?.replace(/\:(
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3273
|
+
const sql = option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
|
|
3274
|
+
let V = LGet(_params, key);
|
|
3275
|
+
if (V) {
|
|
3276
|
+
if (V !== undefined) {
|
|
3277
|
+
params.push(V);
|
|
3278
|
+
}
|
|
3279
|
+
return '?';
|
|
3127
3280
|
}
|
|
3128
3281
|
const _key = C2P(key);
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3282
|
+
V = LGet(_params, _key);
|
|
3283
|
+
if (V) {
|
|
3284
|
+
if (V !== undefined) {
|
|
3285
|
+
params.push(V);
|
|
3286
|
+
}
|
|
3287
|
+
return '?';
|
|
3133
3288
|
}
|
|
3134
3289
|
const __key = P2C(key);
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3290
|
+
V = LGet(_params, __key);
|
|
3291
|
+
if (V) {
|
|
3292
|
+
if (V !== undefined) {
|
|
3293
|
+
params.push(V);
|
|
3294
|
+
}
|
|
3295
|
+
return '?';
|
|
3139
3296
|
}
|
|
3140
3297
|
return txt;
|
|
3141
3298
|
});
|
|
3142
3299
|
if (option.sync === SyncMode.Sync) {
|
|
3143
3300
|
const result = option!.conn!.query(SyncMode.Sync, sql, params);
|
|
3144
|
-
return this._select<L>(option.selectResult, result, option.defValue, option.errorMsg, option.
|
|
3301
|
+
return this._select<L>(option.selectResult, result, option.defValue, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined);
|
|
3145
3302
|
} else {
|
|
3146
3303
|
return new Promise<L | null | L[]>(async (resolve, reject) => {
|
|
3147
3304
|
try {
|
|
3148
3305
|
const result = await option!.conn!.query(SyncMode.Async, sql, params);
|
|
3149
|
-
resolve(this._select<L>(option.selectResult!, result, option.defValue!, option.errorMsg, option.
|
|
3306
|
+
resolve(this._select<L>(option.selectResult!, result, option.defValue!, option.errorMsg, option.hump, option.mapper, option.mapperIfUndefined));
|
|
3150
3307
|
} catch (error) {
|
|
3151
3308
|
reject(error);
|
|
3152
3309
|
}
|
|
@@ -3167,7 +3324,7 @@ export class SqlService<T extends object> {
|
|
|
3167
3324
|
});
|
|
3168
3325
|
```
|
|
3169
3326
|
5. `dao`: 永远不需要传入该值
|
|
3170
|
-
|
|
3327
|
+
|
|
3171
3328
|
*/
|
|
3172
3329
|
excute<L = T>(option: MethodOption & { sync?: SyncMode.Async; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; }): Promise<number>;
|
|
3173
3330
|
excute<L = T>(option: MethodOption & { sync: SyncMode.Sync; sqlId?: string; sql?: string; params?: Record<string, any>; context?: any; }): number;
|
|
@@ -3178,22 +3335,28 @@ export class SqlService<T extends object> {
|
|
|
3178
3335
|
option.sql ??= globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, ..._params });
|
|
3179
3336
|
const params: any[] = [];
|
|
3180
3337
|
const sql = option.sql?.replace(/\:(\w+)/g, (txt, key) => {
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3338
|
+
let V = LGet(_params, key);
|
|
3339
|
+
if (V) {
|
|
3340
|
+
if (V !== undefined) {
|
|
3341
|
+
params.push(V);
|
|
3342
|
+
}
|
|
3343
|
+
return '?';
|
|
3185
3344
|
}
|
|
3186
3345
|
const _key = C2P(key);
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3346
|
+
V = LGet(_params, _key);
|
|
3347
|
+
if (V) {
|
|
3348
|
+
if (V !== undefined) {
|
|
3349
|
+
params.push(V);
|
|
3350
|
+
}
|
|
3351
|
+
return '?';
|
|
3191
3352
|
}
|
|
3192
3353
|
const __key = P2C(key);
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3354
|
+
V = LGet(_params, __key);
|
|
3355
|
+
if (V) {
|
|
3356
|
+
if (V !== undefined) {
|
|
3357
|
+
params.push(V);
|
|
3358
|
+
}
|
|
3359
|
+
return '?';
|
|
3197
3360
|
}
|
|
3198
3361
|
return txt;
|
|
3199
3362
|
});
|
|
@@ -3252,10 +3415,10 @@ export class SqlService<T extends object> {
|
|
|
3252
3415
|
}
|
|
3253
3416
|
|
|
3254
3417
|
|
|
3255
|
-
page<L = T>(option: MethodOption & { sync?: SyncMode.Async; sqlId: string; context?: any; params: Record<string, any>; pageSize: number; pageNumber: number; limitSelf
|
|
3256
|
-
page<L = T>(option: MethodOption & { sync: SyncMode.Sync; sqlId: string; context?: any; params: Record<string, any>; pageSize: number; pageNumber: number; limitSelf
|
|
3418
|
+
page<L = T>(option: MethodOption & { sync?: SyncMode.Async; sqlId: string; context?: any; params: Record<string, any>; pageSize: number; pageNumber: number; limitSelf?: boolean; countSelf?: boolean; sumSelf?: boolean; orderBy?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<PageQuery<L>>;
|
|
3419
|
+
page<L = T>(option: MethodOption & { sync: SyncMode.Sync; sqlId: string; context?: any; params: Record<string, any>; pageSize: number; pageNumber: number; limitSelf?: boolean; countSelf?: boolean; sumSelf?: boolean; orderBy?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): PageQuery<L>;
|
|
3257
3420
|
@P<T>()
|
|
3258
|
-
page<L = T>(option: MethodOption & { sync?: SyncMode; sqlId: string; context?: any; params: Record<string, any>; pageSize: number; pageNumber: number; limitSelf
|
|
3421
|
+
page<L = T>(option: MethodOption & { sync?: SyncMode; sqlId: string; context?: any; params: Record<string, any>; pageSize: number; pageNumber: number; limitSelf?: boolean; countSelf?: boolean; sumSelf?: boolean; orderBy?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): PageQuery<L> | Promise<PageQuery<L>> {
|
|
3259
3422
|
const result: PageQuery<L> = {
|
|
3260
3423
|
sum: {},
|
|
3261
3424
|
records: [],
|
|
@@ -3296,7 +3459,7 @@ export class SqlService<T extends object> {
|
|
|
3296
3459
|
...option,
|
|
3297
3460
|
sql: sqlCount,
|
|
3298
3461
|
sync: SyncMode.Sync,
|
|
3299
|
-
selectResult: SelectResult.
|
|
3462
|
+
selectResult: SelectResult.R_C_Assert
|
|
3300
3463
|
});
|
|
3301
3464
|
result.size = calc(result.total)
|
|
3302
3465
|
.add(option.pageSize - 1)
|
|
@@ -3309,7 +3472,7 @@ export class SqlService<T extends object> {
|
|
|
3309
3472
|
...option,
|
|
3310
3473
|
sql: sqlSum,
|
|
3311
3474
|
sync: SyncMode.Sync,
|
|
3312
|
-
selectResult: SelectResult.
|
|
3475
|
+
selectResult: SelectResult.R_CS_Assert
|
|
3313
3476
|
});
|
|
3314
3477
|
}
|
|
3315
3478
|
if (sql) {
|
|
@@ -3317,7 +3480,7 @@ export class SqlService<T extends object> {
|
|
|
3317
3480
|
...option,
|
|
3318
3481
|
sql,
|
|
3319
3482
|
sync: SyncMode.Sync,
|
|
3320
|
-
selectResult: SelectResult.
|
|
3483
|
+
selectResult: SelectResult.RS_CS
|
|
3321
3484
|
});
|
|
3322
3485
|
}
|
|
3323
3486
|
return result;
|
|
@@ -3329,7 +3492,7 @@ export class SqlService<T extends object> {
|
|
|
3329
3492
|
...option,
|
|
3330
3493
|
sql: sqlCount,
|
|
3331
3494
|
sync: SyncMode.Async,
|
|
3332
|
-
selectResult: SelectResult.
|
|
3495
|
+
selectResult: SelectResult.R_C_Assert
|
|
3333
3496
|
});
|
|
3334
3497
|
result.size = calc(result.total)
|
|
3335
3498
|
.add(option.pageSize - 1)
|
|
@@ -3342,7 +3505,7 @@ export class SqlService<T extends object> {
|
|
|
3342
3505
|
...option,
|
|
3343
3506
|
sql: sqlSum,
|
|
3344
3507
|
sync: SyncMode.Async,
|
|
3345
|
-
selectResult: SelectResult.
|
|
3508
|
+
selectResult: SelectResult.R_CS_Assert
|
|
3346
3509
|
});
|
|
3347
3510
|
}
|
|
3348
3511
|
if (sql) {
|
|
@@ -3350,7 +3513,7 @@ export class SqlService<T extends object> {
|
|
|
3350
3513
|
...option,
|
|
3351
3514
|
sql,
|
|
3352
3515
|
sync: SyncMode.Async,
|
|
3353
|
-
selectResult: SelectResult.
|
|
3516
|
+
selectResult: SelectResult.RS_CS
|
|
3354
3517
|
});
|
|
3355
3518
|
}
|
|
3356
3519
|
resolve(result);
|
|
@@ -3463,7 +3626,7 @@ export class SqlService<T extends object> {
|
|
|
3463
3626
|
|
|
3464
3627
|
private _matchSqlid(sqlid?: string) {
|
|
3465
3628
|
sqlid ??= '';
|
|
3466
|
-
if(sqlid.includes('.')) return [sqlid];
|
|
3629
|
+
if (sqlid.includes('.')) return [sqlid];
|
|
3467
3630
|
else return [`${this[_tableName]}.${sqlid}`, `${this[_className]}.${sqlid}`, `${this[_ClassName]}.${sqlid}`, `${this[_vueName]}.${sqlid}`];
|
|
3468
3631
|
}
|
|
3469
3632
|
|
|
@@ -3558,9 +3721,10 @@ class StreamQuery<T extends object> {
|
|
|
3558
3721
|
return this;
|
|
3559
3722
|
}
|
|
3560
3723
|
@IF_PROCEED<T>()
|
|
3561
|
-
eq(key: keyof T, value: string | number, {
|
|
3724
|
+
eq(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '=', { paramName, skipEmptyString, breakExcuteIfSkip }); }
|
|
3562
3725
|
@IF_PROCEED<T>()
|
|
3563
|
-
eqT(t: Partial<T>, { name
|
|
3726
|
+
eqT(t: Partial<T>, { name: paramName = '', breakExcuteIfSkip = false } = {}) {
|
|
3727
|
+
let exe = false;
|
|
3564
3728
|
if (t) {
|
|
3565
3729
|
t = this._service[_transformer]!(t, {
|
|
3566
3730
|
skipNull: true,
|
|
@@ -3569,8 +3733,8 @@ class StreamQuery<T extends object> {
|
|
|
3569
3733
|
});
|
|
3570
3734
|
const keys = Object.keys(t);
|
|
3571
3735
|
if (keys.length > 0) {
|
|
3572
|
-
if (
|
|
3573
|
-
for (const [key, pname] of Object.entries(this._paramKeys[
|
|
3736
|
+
if (paramName && this._paramKeys[paramName]) {
|
|
3737
|
+
for (const [key, pname] of Object.entries(this._paramKeys[paramName] as Record<string, string>)) {
|
|
3574
3738
|
this._param[pname as string] = t[key];
|
|
3575
3739
|
}
|
|
3576
3740
|
} else {
|
|
@@ -3579,124 +3743,128 @@ class StreamQuery<T extends object> {
|
|
|
3579
3743
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
3580
3744
|
this._wheres.push(`AND ${this[_fields]![String(key)]?.C2()} = :${pkey} `);
|
|
3581
3745
|
this._param[pkey] = value;
|
|
3582
|
-
if (
|
|
3746
|
+
if (paramName) {
|
|
3583
3747
|
paramKeys[key] = pkey;
|
|
3584
3748
|
}
|
|
3585
3749
|
}
|
|
3586
|
-
if (
|
|
3587
|
-
this._paramKeys[
|
|
3750
|
+
if (paramName) {
|
|
3751
|
+
this._paramKeys[paramName] = paramKeys;
|
|
3588
3752
|
}
|
|
3589
3753
|
}
|
|
3754
|
+
exe = true;
|
|
3590
3755
|
}
|
|
3591
3756
|
}
|
|
3757
|
+
if (breakExcuteIfSkip === true && exe === false) {
|
|
3758
|
+
this.if_exec = false;
|
|
3759
|
+
}
|
|
3592
3760
|
return this;
|
|
3593
3761
|
}
|
|
3594
3762
|
@IF_PROCEED<T>()
|
|
3595
|
-
notEq(key: keyof T, value: string | number, {
|
|
3763
|
+
notEq(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._(key, value, '<>', { paramName, skipEmptyString, breakExcuteIfSkip }); }
|
|
3596
3764
|
@IF_PROCEED<T>()
|
|
3597
3765
|
eqWith(key1: keyof T, key2: keyof T) { return this._key(key1, key2, '='); }
|
|
3598
3766
|
@IF_PROCEED<T>()
|
|
3599
3767
|
notEqWith(key1: keyof T, key2: keyof T) { return this._key(key1, key2, '<>'); }
|
|
3600
3768
|
@IF_PROCEED<T>()
|
|
3601
|
-
regexp(key: keyof T, regexp: string, {
|
|
3769
|
+
regexp(key: keyof T, regexp: string, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
|
|
3602
3770
|
@IF_PROCEED<T>()
|
|
3603
|
-
notRegexp(key: keyof T, regexp: string, {
|
|
3771
|
+
notRegexp(key: keyof T, regexp: string, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, regexp, 'REGEXP', { paramName, skipEmptyString: true, not: 'NOT', breakExcuteIfSkip }); }
|
|
3604
3772
|
/** (key1 << 8) + key2 = value */
|
|
3605
3773
|
@IF_PROCEED<T>()
|
|
3606
|
-
shiftEq(key1: keyof T, key2: keyof T, value: number, {
|
|
3774
|
+
shiftEq(key1: keyof T, key2: keyof T, value: number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '=', { paramName, breakExcuteIfSkip }); }
|
|
3607
3775
|
/** (key1 << 8) + key2 <> value */
|
|
3608
3776
|
@IF_PROCEED<T>()
|
|
3609
|
-
shiftNotEq(key1: keyof T, key2: keyof T, value: number, {
|
|
3777
|
+
shiftNotEq(key1: keyof T, key2: keyof T, value: number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._shift(key1, key2, value, '<>', { paramName, breakExcuteIfSkip }); }
|
|
3610
3778
|
@IF_PROCEED<T>()
|
|
3611
|
-
grate(key: keyof T, value: string | number, {
|
|
3779
|
+
grate(key: keyof T, value: string | number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
|
|
3612
3780
|
@IF_PROCEED<T>()
|
|
3613
|
-
grateEq(key: keyof T, value: string | number, {
|
|
3781
|
+
grateEq(key: keyof T, value: string | number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '>=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
|
|
3614
3782
|
@IF_PROCEED<T>()
|
|
3615
3783
|
grateWith(key1: keyof T, key2: keyof T) { return this._key(key1, key2, '>'); }
|
|
3616
3784
|
@IF_PROCEED<T>()
|
|
3617
3785
|
grateEqWith(key1: keyof T, key2: keyof T) { return this._key(key1, key2, '>='); }
|
|
3618
3786
|
@IF_PROCEED<T>()
|
|
3619
|
-
less(key: keyof T, value: string | number, {
|
|
3787
|
+
less(key: keyof T, value: string | number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
|
|
3620
3788
|
@IF_PROCEED<T>()
|
|
3621
|
-
lessEq(key: keyof T, value: string | number, {
|
|
3789
|
+
lessEq(key: keyof T, value: string | number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._(key, value, '<=', { paramName, skipEmptyString: true, breakExcuteIfSkip }); }
|
|
3622
3790
|
@IF_PROCEED<T>()
|
|
3623
3791
|
lessWith(key1: keyof T, key2: keyof T) { return this._key(key1, key2, '<'); }
|
|
3624
3792
|
@IF_PROCEED<T>()
|
|
3625
3793
|
lessEqWith(key1: keyof T, key2: keyof T) { return this._key(key1, key2, '<='); }
|
|
3626
3794
|
@IF_PROCEED<T>()
|
|
3627
|
-
like(key: keyof T, value: string | number, {
|
|
3795
|
+
like(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip }); }
|
|
3628
3796
|
@IF_PROCEED<T>()
|
|
3629
|
-
notLike(key: keyof T, value: string | number, {
|
|
3797
|
+
notLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip }); }
|
|
3630
3798
|
@IF_PROCEED<T>()
|
|
3631
|
-
leftLike(key: keyof T, value: string | number, {
|
|
3799
|
+
leftLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip }); }
|
|
3632
3800
|
@IF_PROCEED<T>()
|
|
3633
|
-
notLeftLike(key: keyof T, value: string | number, {
|
|
3801
|
+
notLeftLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip }); }
|
|
3634
3802
|
@IF_PROCEED<T>()
|
|
3635
|
-
rightLike(key: keyof T, value: string | number, {
|
|
3803
|
+
rightLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip }); }
|
|
3636
3804
|
@IF_PROCEED<T>()
|
|
3637
|
-
notRightLike(key: keyof T, value: string | number, {
|
|
3805
|
+
notRightLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip }); }
|
|
3638
3806
|
@IF_PROCEED<T>()
|
|
3639
|
-
PreciseLike(key: keyof T, value: string | number, {
|
|
3807
|
+
PreciseLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
|
|
3640
3808
|
@IF_PROCEED<T>()
|
|
3641
|
-
notPreciseLike(key: keyof T, value: string | number, {
|
|
3809
|
+
notPreciseLike(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
|
|
3642
3810
|
@IF_PROCEED<T>()
|
|
3643
|
-
glob(key: keyof T, value: string | number, {
|
|
3811
|
+
glob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3644
3812
|
@IF_PROCEED<T>()
|
|
3645
|
-
notGlob(key: keyof T, value: string | number, {
|
|
3813
|
+
notGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3646
3814
|
@IF_PROCEED<T>()
|
|
3647
|
-
leftGlob(key: keyof T, value: string | number, {
|
|
3815
|
+
leftGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3648
3816
|
@IF_PROCEED<T>()
|
|
3649
|
-
notLeftGlob(key: keyof T, value: string | number, {
|
|
3817
|
+
notLeftGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, left: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3650
3818
|
@IF_PROCEED<T>()
|
|
3651
|
-
rightGlob(key: keyof T, value: string | number, {
|
|
3819
|
+
rightGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3652
3820
|
@IF_PROCEED<T>()
|
|
3653
|
-
notRightGlob(key: keyof T, value: string | number, {
|
|
3821
|
+
notRightGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, right: '%', not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3654
3822
|
@IF_PROCEED<T>()
|
|
3655
|
-
PreciseGlob(key: keyof T, value: string | number, {
|
|
3823
|
+
PreciseGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3656
3824
|
@IF_PROCEED<T>()
|
|
3657
|
-
notPreciseGlob(key: keyof T, value: string | number, {
|
|
3825
|
+
notPreciseGlob(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._like(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip, op: 'GLOB' }); }
|
|
3658
3826
|
@IF_PROCEED<T>()
|
|
3659
|
-
in(key: keyof T, value: Array<string | number>, {
|
|
3827
|
+
in(key: keyof T, value: Array<string | number>, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, breakExcuteIfSkip }); }
|
|
3660
3828
|
@IF_PROCEED<T>()
|
|
3661
|
-
notIn(key: keyof T, value: Array<string | number>, {
|
|
3829
|
+
notIn(key: keyof T, value: Array<string | number>, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._in(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
|
|
3662
3830
|
@IF_PROCEED<T>()
|
|
3663
3831
|
isNULL(key: keyof T) { return this._null(key); }
|
|
3664
3832
|
@IF_PROCEED<T>()
|
|
3665
3833
|
isNotNULL(key: keyof T) { return this._null(key, 'NOT'); }
|
|
3666
3834
|
@IF_PROCEED<T>()
|
|
3667
|
-
between(key: keyof T, value1: string | number, value2: string | number, {
|
|
3835
|
+
between(key: keyof T, value1: string | number, value2: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, breakExcuteIfSkip }); }
|
|
3668
3836
|
@IF_PROCEED<T>()
|
|
3669
|
-
notBetween(key: keyof T, value1: string | number, value2: string | number, {
|
|
3837
|
+
notBetween(key: keyof T, value1: string | number, value2: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._between(key, value1, value2, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
|
|
3670
3838
|
@IF_PROCEED<T>()
|
|
3671
|
-
pow(key: keyof T, value: number, {
|
|
3839
|
+
pow(key: keyof T, value: number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, breakExcuteIfSkip }); }
|
|
3672
3840
|
@IF_PROCEED<T>()
|
|
3673
|
-
notPow(key: keyof T, value: number, {
|
|
3841
|
+
notPow(key: keyof T, value: number, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, value, { paramName, not: 'NOT', breakExcuteIfSkip }); }
|
|
3674
3842
|
@IF_PROCEED<T>()
|
|
3675
|
-
powWith(key: keyof T, values: Array<number | string>, {
|
|
3843
|
+
powWith(key: keyof T, values: Array<number | string>, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, breakExcuteIfSkip }); }
|
|
3676
3844
|
@IF_PROCEED<T>()
|
|
3677
|
-
notPowWith(key: keyof T, values: Array<number | string>, {
|
|
3845
|
+
notPowWith(key: keyof T, values: Array<number | string>, { paramName = '', breakExcuteIfSkip = false } = {}) { return this._pow(key, add(...values.map(value => Math.pow(2, +value))), { paramName, not: 'NOT', breakExcuteIfSkip }); }
|
|
3678
3846
|
/** MATCH(key1, key2, key3) AGAINST (value) */
|
|
3679
3847
|
@IF_PROCEED<T>()
|
|
3680
|
-
match(value: string, keys: (keyof T)[], {
|
|
3848
|
+
match(value: string, keys: (keyof T)[], { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip }); }
|
|
3681
3849
|
/** NOT MATCH(key1, key2, key3) AGAINST (value) */
|
|
3682
3850
|
@IF_PROCEED<T>()
|
|
3683
|
-
notMatch(value: string, keys: (keyof T)[], {
|
|
3851
|
+
notMatch(value: string, keys: (keyof T)[], { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
|
|
3684
3852
|
/** MATCH(key1, key2, key3) AGAINST (value) IN BOOLEAN MODE*/
|
|
3685
3853
|
@IF_PROCEED<T>()
|
|
3686
|
-
matchBoolean(value: string, keys: (keyof T)[], {
|
|
3854
|
+
matchBoolean(value: string, keys: (keyof T)[], { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'IN BOOLEAN MODE' }); }
|
|
3687
3855
|
/** NOT MATCH(key1, key2, key3) AGAINST (value) IN BOOLEAN MODE */
|
|
3688
3856
|
@IF_PROCEED<T>()
|
|
3689
|
-
notMatchBoolean(value: string, keys: (keyof T)[], {
|
|
3857
|
+
notMatchBoolean(value: string, keys: (keyof T)[], { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'IN BOOLEAN MODE' }); }
|
|
3690
3858
|
/** MATCH(key1, key2, key3) AGAINST (value) WITH QUERY EXPANSION*/
|
|
3691
3859
|
@IF_PROCEED<T>()
|
|
3692
|
-
matchQuery(value: string, keys: (keyof T)[], {
|
|
3860
|
+
matchQuery(value: string, keys: (keyof T)[], { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, append: 'WITH QUERY EXPANSION' }); }
|
|
3693
3861
|
/** NOT MATCH(key1, key2, key3) AGAINST (value) WITH QUERY EXPANSION*/
|
|
3694
3862
|
@IF_PROCEED<T>()
|
|
3695
|
-
notMatchQuery(value: string, keys: (keyof T)[], {
|
|
3863
|
+
notMatchQuery(value: string, keys: (keyof T)[], { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._match(value, keys, { paramName, skipEmptyString, breakExcuteIfSkip, not: 'NOT', append: 'WITH QUERY EXPANSION' }); }
|
|
3696
3864
|
@IF_PROCEED<T>()
|
|
3697
|
-
includes(key: keyof T, value: string | number, {
|
|
3865
|
+
includes(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, breakExcuteIfSkip }); }
|
|
3698
3866
|
@IF_PROCEED<T>()
|
|
3699
|
-
notIncludes(key: keyof T, value: string | number, {
|
|
3867
|
+
notIncludes(key: keyof T, value: string | number, { paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) { return this._includes(key, value, { paramName, skipEmptyString, not: 'NOT', breakExcuteIfSkip }); }
|
|
3700
3868
|
@IF_PROCEED<T>()
|
|
3701
3869
|
and(fn: StreamQuery<T> | ((stream: StreamQuery<T>) => boolean | void)) {
|
|
3702
3870
|
if (fn instanceof StreamQuery) {
|
|
@@ -3782,17 +3950,19 @@ class StreamQuery<T extends object> {
|
|
|
3782
3950
|
}
|
|
3783
3951
|
// #endregion
|
|
3784
3952
|
|
|
3785
|
-
excuteSelect<L = T>(option?: MethodOption & { sync?: SyncMode.Async; selectResult?: SelectResult.
|
|
3786
|
-
excuteSelect<L = T>(option
|
|
3787
|
-
excuteSelect<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult: SelectResult.
|
|
3788
|
-
excuteSelect<L = T>(option: MethodOption & { sync
|
|
3789
|
-
excuteSelect<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.
|
|
3790
|
-
excuteSelect<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.
|
|
3953
|
+
excuteSelect<L = T>(option?: MethodOption & { sync?: SyncMode.Async; selectResult?: SelectResult.RS_CS | SelectResult.RS_C; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<L[]>;
|
|
3954
|
+
excuteSelect<L = T>(option?: MethodOption & { sync?: SyncMode.Async; selectResult?: SelectResult.RS_CS_List | SelectResult.RS_C_List; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<ArrayList<L>>;
|
|
3955
|
+
excuteSelect<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult: SelectResult.R_CS_Assert | SelectResult.R_C_Assert; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<L>;
|
|
3956
|
+
excuteSelect<L = T>(option: MethodOption & { sync?: SyncMode.Async; selectResult: SelectResult.R_CS_NotSure | SelectResult.R_C_NotSure; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): Promise<L | null>;
|
|
3957
|
+
excuteSelect<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.RS_CS | SelectResult.RS_C; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): L[];
|
|
3958
|
+
excuteSelect<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.RS_CS_List | SelectResult.RS_C_List; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): ArrayList<L>;
|
|
3959
|
+
excuteSelect<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.R_CS_Assert | SelectResult.R_C_Assert; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): L;
|
|
3960
|
+
excuteSelect<L = T>(option: MethodOption & { sync: SyncMode.Sync; selectResult: SelectResult.R_CS_NotSure | SelectResult.R_C_NotSure; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): L | null;
|
|
3791
3961
|
@IF_EXEC<T>(null)
|
|
3792
|
-
excuteSelect<L = T>(option?: MethodOption & { sync?: SyncMode; selectResult?: SelectResult; errorMsg?: string; }): null | L | L[] | Promise<null | L | L[]
|
|
3962
|
+
excuteSelect<L = T>(option?: MethodOption & { sync?: SyncMode; selectResult?: SelectResult; errorMsg?: string; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): null | L | L[] | ArrayList<L> | Promise<null | L | L[] | ArrayList<L>> {
|
|
3793
3963
|
option ??= {};
|
|
3794
3964
|
option.sync ??= SyncMode.Async;
|
|
3795
|
-
option.selectResult ??= SelectResult.
|
|
3965
|
+
option.selectResult ??= SelectResult.RS_CS;
|
|
3796
3966
|
const { where, params } = this._where();
|
|
3797
3967
|
let sql = `
|
|
3798
3968
|
SELECT
|
|
@@ -3800,6 +3970,8 @@ class StreamQuery<T extends object> {
|
|
|
3800
3970
|
FROM ${this._table}
|
|
3801
3971
|
${where ? ' WHERE ' : ''}
|
|
3802
3972
|
${where}
|
|
3973
|
+
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
3974
|
+
${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
|
|
3803
3975
|
`;
|
|
3804
3976
|
if (this._startRow && this._pageSize) {
|
|
3805
3977
|
sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
|
|
@@ -3808,24 +3980,110 @@ class StreamQuery<T extends object> {
|
|
|
3808
3980
|
}
|
|
3809
3981
|
if (option.sync === SyncMode.Async) {
|
|
3810
3982
|
switch (option.selectResult) {
|
|
3811
|
-
case SelectResult.
|
|
3812
|
-
case SelectResult.
|
|
3813
|
-
case SelectResult.
|
|
3814
|
-
case SelectResult.
|
|
3815
|
-
case SelectResult.
|
|
3816
|
-
case SelectResult.
|
|
3983
|
+
case SelectResult.RS_CS: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS, sql, params });
|
|
3984
|
+
case SelectResult.RS_C: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C, sql, params });
|
|
3985
|
+
case SelectResult.RS_CS_List: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_CS_List, sql, params });
|
|
3986
|
+
case SelectResult.RS_C_List: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.RS_C_List, sql, params });
|
|
3987
|
+
case SelectResult.R_CS_Assert: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_Assert, sql, params });
|
|
3988
|
+
case SelectResult.R_C_Assert: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_Assert, sql, params });
|
|
3989
|
+
case SelectResult.R_CS_NotSure: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_CS_NotSure, sql, params });
|
|
3990
|
+
case SelectResult.R_C_NotSure: return this._service.select<L>({ ...option, sync: SyncMode.Async, selectResult: SelectResult.R_C_NotSure, sql, params });
|
|
3817
3991
|
}
|
|
3818
3992
|
} else {
|
|
3819
3993
|
switch (option.selectResult) {
|
|
3820
|
-
case SelectResult.
|
|
3821
|
-
case SelectResult.
|
|
3822
|
-
case SelectResult.
|
|
3823
|
-
case SelectResult.
|
|
3824
|
-
case SelectResult.
|
|
3825
|
-
case SelectResult.
|
|
3994
|
+
case SelectResult.RS_CS: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS, sql, params });
|
|
3995
|
+
case SelectResult.RS_C: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C, sql, params });
|
|
3996
|
+
case SelectResult.RS_CS_List: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_CS_List, sql, params });
|
|
3997
|
+
case SelectResult.RS_C_List: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.RS_C_List, sql, params });
|
|
3998
|
+
case SelectResult.R_CS_Assert: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_Assert, sql, params });
|
|
3999
|
+
case SelectResult.R_C_Assert: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_Assert, sql, params });
|
|
4000
|
+
case SelectResult.R_CS_NotSure: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_CS_NotSure, sql, params });
|
|
4001
|
+
case SelectResult.R_C_NotSure: return this._service.select<L>({ ...option, sync: SyncMode.Sync, selectResult: SelectResult.R_C_NotSure, sql, params });
|
|
3826
4002
|
}
|
|
3827
4003
|
}
|
|
3828
4004
|
}
|
|
4005
|
+
@IF_EXEC<T>(null)
|
|
4006
|
+
excutePage<L = T>(option?: MethodOption & { sync?: SyncMode; hump?: boolean; mapper?: string | SqlMapper; mapperIfUndefined?: MapperIfUndefined; }): PageQuery<L> | Promise<PageQuery<L>> {
|
|
4007
|
+
option ??= {};
|
|
4008
|
+
option.sync ??= SyncMode.Async;
|
|
4009
|
+
const { where, params } = this._where();
|
|
4010
|
+
const result: PageQuery<L> = {
|
|
4011
|
+
records: [],
|
|
4012
|
+
size: 0,
|
|
4013
|
+
total: 0
|
|
4014
|
+
};
|
|
4015
|
+
let sql = `
|
|
4016
|
+
SELECT
|
|
4017
|
+
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields]![String(key)]?.C3()).join(',')}
|
|
4018
|
+
FROM ${this._table}
|
|
4019
|
+
${where ? ' WHERE ' : ''}
|
|
4020
|
+
${where}
|
|
4021
|
+
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
4022
|
+
${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
|
|
4023
|
+
`;
|
|
4024
|
+
if (this._startRow && this._pageSize) {
|
|
4025
|
+
sql += `LIMIT ${this._startRow}, ${this._pageSize}`;
|
|
4026
|
+
} else if (this._startRow) {
|
|
4027
|
+
sql += `LIMIT ${this._startRow}`;
|
|
4028
|
+
}
|
|
4029
|
+
const sqlCount = `
|
|
4030
|
+
SELECT COUNT(1)
|
|
4031
|
+
FROM ${this._table}
|
|
4032
|
+
${where ? ' WHERE ' : ''}
|
|
4033
|
+
${where}
|
|
4034
|
+
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
4035
|
+
${this._orders.length > 0 ? `ORDER BY ${this._orders.join(',')} ` : ''}
|
|
4036
|
+
`;
|
|
4037
|
+
if (option.sync === SyncMode.Sync) {
|
|
4038
|
+
result.total = this._service.select<number>({
|
|
4039
|
+
...option,
|
|
4040
|
+
params,
|
|
4041
|
+
sql: sqlCount,
|
|
4042
|
+
sync: SyncMode.Sync,
|
|
4043
|
+
selectResult: SelectResult.R_C_Assert
|
|
4044
|
+
});
|
|
4045
|
+
result.size = calc(result.total)
|
|
4046
|
+
.add(this._pageSize - 1)
|
|
4047
|
+
.div(this._pageSize)
|
|
4048
|
+
.round(0, 2)
|
|
4049
|
+
.over();
|
|
4050
|
+
result.records = this._service.select<L>({
|
|
4051
|
+
...option,
|
|
4052
|
+
params,
|
|
4053
|
+
sql,
|
|
4054
|
+
sync: SyncMode.Sync,
|
|
4055
|
+
selectResult: SelectResult.RS_CS
|
|
4056
|
+
});
|
|
4057
|
+
return result;
|
|
4058
|
+
} else {
|
|
4059
|
+
return new Promise<PageQuery<L>>(async (resolve, reject) => {
|
|
4060
|
+
try {
|
|
4061
|
+
result.total = await this._service.select<number>({
|
|
4062
|
+
...option,
|
|
4063
|
+
params,
|
|
4064
|
+
sql: sqlCount,
|
|
4065
|
+
sync: SyncMode.Async,
|
|
4066
|
+
selectResult: SelectResult.R_C_Assert
|
|
4067
|
+
});
|
|
4068
|
+
result.size = calc(result.total)
|
|
4069
|
+
.add(this._pageSize - 1)
|
|
4070
|
+
.div(this._pageSize)
|
|
4071
|
+
.round(0, 2)
|
|
4072
|
+
.over();
|
|
4073
|
+
result.records = await this._service.select<L>({
|
|
4074
|
+
...option,
|
|
4075
|
+
params,
|
|
4076
|
+
sql,
|
|
4077
|
+
sync: SyncMode.Async,
|
|
4078
|
+
selectResult: SelectResult.RS_CS
|
|
4079
|
+
});
|
|
4080
|
+
resolve(result);
|
|
4081
|
+
} catch (error) {
|
|
4082
|
+
reject(error);
|
|
4083
|
+
}
|
|
4084
|
+
});
|
|
4085
|
+
}
|
|
4086
|
+
}
|
|
3829
4087
|
excuteUpdate(option?: MethodOption & { sync?: SyncMode.Async }): Promise<number>;
|
|
3830
4088
|
excuteUpdate(option: MethodOption & { sync: SyncMode.Sync }): number;
|
|
3831
4089
|
@IF_EXEC<T>(0)
|
|
@@ -3892,15 +4150,26 @@ class StreamQuery<T extends object> {
|
|
|
3892
4150
|
}
|
|
3893
4151
|
return { where: wheres.join(' '), params: this._param };
|
|
3894
4152
|
}
|
|
3895
|
-
private _(key: keyof T, value: any, op: string, { not = '',
|
|
3896
|
-
if (
|
|
3897
|
-
|
|
4153
|
+
private _(key: keyof T, value: any, op: string, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
|
|
4154
|
+
if (
|
|
4155
|
+
value === null
|
|
4156
|
+
|| value === undefined
|
|
4157
|
+
|| (emptyString(`${value ?? ''}`) && skipEmptyString === true)
|
|
4158
|
+
) {
|
|
4159
|
+
if (breakExcuteIfSkip === true) {
|
|
4160
|
+
this.if_exec = false;
|
|
4161
|
+
}
|
|
4162
|
+
return this;
|
|
4163
|
+
}
|
|
4164
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4165
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
3898
4166
|
} else {
|
|
4167
|
+
paramName
|
|
3899
4168
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
3900
4169
|
this._wheres.push(`AND ${this[_fields]![String(key)]?.C2()} ${not} ${op} :${pkey} `);
|
|
3901
4170
|
this._param[pkey] = value;
|
|
3902
|
-
if (
|
|
3903
|
-
this._paramKeys[
|
|
4171
|
+
if (paramName) {
|
|
4172
|
+
this._paramKeys[paramName] = pkey;
|
|
3904
4173
|
}
|
|
3905
4174
|
}
|
|
3906
4175
|
return this;
|
|
@@ -3913,103 +4182,163 @@ class StreamQuery<T extends object> {
|
|
|
3913
4182
|
this._wheres.push(`AND ${this[_fields]![String(key1)]?.C2()} ${not} ${op} ${this[_fields]![String(key2)]?.C2()} `);
|
|
3914
4183
|
return this;
|
|
3915
4184
|
}
|
|
3916
|
-
private _between(key: keyof T, value1: string | number, value2: string | number, { not = '',
|
|
3917
|
-
if (
|
|
3918
|
-
|
|
3919
|
-
|
|
4185
|
+
private _between(key: keyof T, value1: string | number, value2: string | number, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
|
|
4186
|
+
if (
|
|
4187
|
+
value1 === null
|
|
4188
|
+
|| value1 === undefined
|
|
4189
|
+
|| (emptyString(`${value1 ?? ''}`) && skipEmptyString === true)
|
|
4190
|
+
|| value2 === null
|
|
4191
|
+
|| value2 === undefined
|
|
4192
|
+
|| (emptyString(`${value2 ?? ''}`) && skipEmptyString === true)
|
|
4193
|
+
) {
|
|
4194
|
+
if (breakExcuteIfSkip === true) {
|
|
4195
|
+
this.if_exec = false;
|
|
4196
|
+
}
|
|
4197
|
+
return this;
|
|
4198
|
+
}
|
|
4199
|
+
if (paramName && this._paramKeys[paramName]) {
|
|
4200
|
+
this._param[this._paramKeys[paramName]![0]] = value1;
|
|
4201
|
+
this._param[this._paramKeys[paramName]![1]] = value2;
|
|
3920
4202
|
} else {
|
|
3921
4203
|
const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
|
|
3922
4204
|
this._wheres.push(`AND ${this[_fields]![String(key)]?.C2()} ${not} BETWEEN :${pkey1} AND :${pkey2}`);
|
|
3923
4205
|
this._param[pkey1] = value1;
|
|
3924
4206
|
this._param[pkey2] = value2;
|
|
3925
|
-
if (
|
|
3926
|
-
this._paramKeys[
|
|
4207
|
+
if (paramName) {
|
|
4208
|
+
this._paramKeys[paramName] = [pkey1, pkey2];
|
|
3927
4209
|
}
|
|
3928
4210
|
}
|
|
3929
4211
|
return this;
|
|
3930
4212
|
}
|
|
3931
|
-
private _in(key: keyof T, value: any, { not = '',
|
|
4213
|
+
private _in(key: keyof T, value: any, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
|
|
3932
4214
|
if (value && value.length > 0) {
|
|
3933
|
-
if (
|
|
3934
|
-
this._param[this._paramKeys[
|
|
4215
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4216
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
3935
4217
|
} else {
|
|
3936
4218
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
3937
4219
|
this._wheres.push(`AND ${this[_fields]![String(key)]?.C2()} ${not} IN (:${pkey}) `);
|
|
3938
4220
|
this._param[pkey] = value;
|
|
3939
|
-
if (
|
|
3940
|
-
this._paramKeys[
|
|
4221
|
+
if (paramName) {
|
|
4222
|
+
this._paramKeys[paramName] = pkey;
|
|
3941
4223
|
}
|
|
3942
4224
|
}
|
|
3943
|
-
} else if (
|
|
4225
|
+
} else if (breakExcuteIfSkip !== true) {
|
|
3944
4226
|
this.if_exec = false;
|
|
3945
4227
|
}
|
|
3946
4228
|
return this;
|
|
3947
4229
|
}
|
|
3948
|
-
private _shift(key1: keyof T, key2: keyof T, value: number, op: string, { not = '',
|
|
3949
|
-
if (
|
|
3950
|
-
|
|
4230
|
+
private _shift(key1: keyof T, key2: keyof T, value: number, op: string, { not = '', paramName = '', breakExcuteIfSkip = false } = {}) {
|
|
4231
|
+
if (
|
|
4232
|
+
value === null
|
|
4233
|
+
|| value === undefined
|
|
4234
|
+
|| emptyString(`${value ?? ''}`)
|
|
4235
|
+
) {
|
|
4236
|
+
if (breakExcuteIfSkip === true) {
|
|
4237
|
+
this.if_exec = false;
|
|
4238
|
+
}
|
|
4239
|
+
return this;
|
|
4240
|
+
}
|
|
4241
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4242
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
3951
4243
|
} else {
|
|
3952
4244
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
3953
4245
|
this._wheres.push(`AND (${this[_fields]![String(key1)]?.C2()} << 8) + ${this[_fields]![String(key2)]?.C2()} ${not} ${op} :${pkey} `);
|
|
3954
4246
|
this._param[pkey] = value;
|
|
3955
|
-
if (
|
|
3956
|
-
this._paramKeys[
|
|
4247
|
+
if (paramName) {
|
|
4248
|
+
this._paramKeys[paramName] = pkey;
|
|
3957
4249
|
}
|
|
3958
4250
|
}
|
|
3959
4251
|
return this;
|
|
3960
4252
|
}
|
|
3961
|
-
private _match(value: string, keys: (keyof T)[], {
|
|
3962
|
-
if (
|
|
3963
|
-
|
|
4253
|
+
private _match(value: string, keys: (keyof T)[], { paramName = '', not = '', append = '', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
|
|
4254
|
+
if (
|
|
4255
|
+
value === null
|
|
4256
|
+
|| value === undefined
|
|
4257
|
+
|| emptyString(`${value ?? ''}`)
|
|
4258
|
+
) {
|
|
4259
|
+
if (breakExcuteIfSkip === true) {
|
|
4260
|
+
this.if_exec = false;
|
|
4261
|
+
}
|
|
4262
|
+
return this;
|
|
4263
|
+
}
|
|
4264
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4265
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
3964
4266
|
} else {
|
|
3965
4267
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
3966
|
-
this._wheres.push(`AND MATCH(${keys.map(key => this[_fields]![String(key)]?.C2()).join(',')}) AGAINST (:${pkey} ${append ?? ''})`);
|
|
4268
|
+
this._wheres.push(`AND ${not} MATCH(${keys.map(key => this[_fields]![String(key)]?.C2()).join(',')}) AGAINST (:${pkey} ${append ?? ''})`);
|
|
3967
4269
|
this._param[pkey] = value;
|
|
3968
|
-
if (
|
|
3969
|
-
this._paramKeys[
|
|
4270
|
+
if (paramName) {
|
|
4271
|
+
this._paramKeys[paramName] = pkey;
|
|
3970
4272
|
}
|
|
3971
4273
|
}
|
|
3972
4274
|
return this;
|
|
3973
4275
|
}
|
|
3974
|
-
private _pow(key: keyof T, value: number, {
|
|
3975
|
-
if (
|
|
3976
|
-
|
|
4276
|
+
private _pow(key: keyof T, value: number, { not = '', paramName = '', breakExcuteIfSkip = false } = {}) {
|
|
4277
|
+
if (
|
|
4278
|
+
value === null
|
|
4279
|
+
|| value === undefined
|
|
4280
|
+
|| emptyString(`${value ?? ''}`)
|
|
4281
|
+
) {
|
|
4282
|
+
if (breakExcuteIfSkip === true) {
|
|
4283
|
+
this.if_exec = false;
|
|
4284
|
+
}
|
|
4285
|
+
return this;
|
|
4286
|
+
}
|
|
4287
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4288
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
3977
4289
|
} else {
|
|
3978
4290
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
3979
|
-
this._wheres.push(`AND
|
|
4291
|
+
this._wheres.push(`AND ${not} POW(2, ${this[_fields]![String(key)]?.C2()}) & :${pkey}`);
|
|
3980
4292
|
this._param[pkey] = value;
|
|
3981
|
-
if (
|
|
3982
|
-
this._paramKeys[
|
|
4293
|
+
if (paramName) {
|
|
4294
|
+
this._paramKeys[paramName] = pkey;
|
|
3983
4295
|
}
|
|
3984
4296
|
}
|
|
3985
4297
|
return this;
|
|
3986
4298
|
}
|
|
3987
|
-
private _like(key: keyof T, value: any, { not = '', left = '', right = '',
|
|
3988
|
-
if (
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
}
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
this.
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
4299
|
+
private _like(key: keyof T, value: any, { not = '', left = '', right = '', paramName = '', op = 'LIKE', skipEmptyString = true, breakExcuteIfSkip = false } = {}) {
|
|
4300
|
+
if (
|
|
4301
|
+
value === null
|
|
4302
|
+
|| value === undefined
|
|
4303
|
+
|| (emptyString(`${value ?? ''}`) && skipEmptyString === true)
|
|
4304
|
+
) {
|
|
4305
|
+
if (breakExcuteIfSkip === true) {
|
|
4306
|
+
this.if_exec = false;
|
|
4307
|
+
}
|
|
4308
|
+
return this;
|
|
4309
|
+
}
|
|
4310
|
+
|
|
4311
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4312
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
4313
|
+
} else {
|
|
4314
|
+
const pkey = `p${this._prefix}${this._index++}`;
|
|
4315
|
+
this._wheres.push(`AND ${this[_fields]![String(key)]?.C2()} ${not} ${op} CONCAT('${left}', :${pkey}, '${right}') `);
|
|
4316
|
+
this._param[pkey] = value;
|
|
4317
|
+
if (paramName) {
|
|
4318
|
+
this._paramKeys[paramName] = pkey;
|
|
3998
4319
|
}
|
|
3999
|
-
} else if (force !== true) {
|
|
4000
|
-
this.if_exec = false;
|
|
4001
4320
|
}
|
|
4002
4321
|
return this;
|
|
4003
4322
|
}
|
|
4004
|
-
private _includes(key: keyof T, value: any, { not = '',
|
|
4005
|
-
if (
|
|
4006
|
-
|
|
4323
|
+
private _includes(key: keyof T, value: any, { not = '', paramName = '', skipEmptyString = true, breakExcuteIfSkip = true } = {}) {
|
|
4324
|
+
if (
|
|
4325
|
+
value === null
|
|
4326
|
+
|| value === undefined
|
|
4327
|
+
|| (emptyString(`${value ?? ''}`) && skipEmptyString === true)
|
|
4328
|
+
) {
|
|
4329
|
+
if (breakExcuteIfSkip === true) {
|
|
4330
|
+
this.if_exec = false;
|
|
4331
|
+
}
|
|
4332
|
+
return this;
|
|
4333
|
+
}
|
|
4334
|
+
if (paramName !== undefined && this._paramKeys.hasOwnProperty(paramName)) {
|
|
4335
|
+
this._param[this._paramKeys[paramName] as string] = value;
|
|
4007
4336
|
} else {
|
|
4008
4337
|
const pkey = `p${this._prefix}${this._index++}`;
|
|
4009
|
-
this._wheres.push(`AND LOCATE(${this[_fields]![String(key)]?.C2()}, :${pkey}) ${not ? '=' : ''} 0`);
|
|
4338
|
+
this._wheres.push(`AND LOCATE(${this[_fields]![String(key)]?.C2()}, :${pkey}) ${not ? '=' : '>'} 0`);
|
|
4010
4339
|
this._param[pkey] = value;
|
|
4011
|
-
if (
|
|
4012
|
-
this._paramKeys[
|
|
4340
|
+
if (paramName) {
|
|
4341
|
+
this._paramKeys[paramName] = pkey;
|
|
4013
4342
|
}
|
|
4014
4343
|
}
|
|
4015
4344
|
return this;
|