baja-lite 1.0.26 → 1.0.27
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/sql.d.ts +3 -5
- package/cjs/sql.js +10 -18
- package/es/sql.d.ts +3 -5
- package/es/sql.js +10 -18
- package/package.json +3 -3
- package/src/sql.ts +11 -15
package/cjs/sql.d.ts
CHANGED
|
@@ -752,7 +752,7 @@ export declare function DeclareService(clz: any, config: ServiceOption): any;
|
|
|
752
752
|
|
|
753
753
|
*/
|
|
754
754
|
export declare class SqlService<T extends object> {
|
|
755
|
-
|
|
755
|
+
[_tableName]?: string;
|
|
756
756
|
private [_className]?;
|
|
757
757
|
private [_ClassName]?;
|
|
758
758
|
private [_vueName]?;
|
|
@@ -1266,7 +1266,7 @@ export declare class SqlService<T extends object> {
|
|
|
1266
1266
|
sync: SyncMode.Sync;
|
|
1267
1267
|
fn: (conn: Connection) => L;
|
|
1268
1268
|
}): L | null;
|
|
1269
|
-
stream<L extends object = T>(
|
|
1269
|
+
stream<L extends object = T>(): StreamQuery<L>;
|
|
1270
1270
|
page<L = T>(option: MethodOption & {
|
|
1271
1271
|
sync?: SyncMode.Async;
|
|
1272
1272
|
sqlId: string;
|
|
@@ -1362,7 +1362,6 @@ declare class StreamQuery<T extends object> {
|
|
|
1362
1362
|
private _param;
|
|
1363
1363
|
if_proceed: boolean;
|
|
1364
1364
|
if_exec: boolean;
|
|
1365
|
-
private _table;
|
|
1366
1365
|
private _distinct;
|
|
1367
1366
|
private _columns;
|
|
1368
1367
|
private _updates?;
|
|
@@ -1374,7 +1373,7 @@ declare class StreamQuery<T extends object> {
|
|
|
1374
1373
|
private _service;
|
|
1375
1374
|
private [_fields];
|
|
1376
1375
|
private [_columns];
|
|
1377
|
-
constructor(
|
|
1376
|
+
constructor(service: SqlService<T>, __fields: Record<string, AField>, __columns: string[]);
|
|
1378
1377
|
/** 将当前stream重置 */
|
|
1379
1378
|
reset(): this;
|
|
1380
1379
|
/** 为下次链条执行提供条件判断:非异步方法跳过,异步方法不执行并返回默认值 */
|
|
@@ -1606,7 +1605,6 @@ declare class StreamQuery<T extends object> {
|
|
|
1606
1605
|
desc2(...keys: string[]): this;
|
|
1607
1606
|
limit(startRow: number, pageSize: number): this;
|
|
1608
1607
|
page(pageNumber: number, pageSize: number): this;
|
|
1609
|
-
table(_table: string): this;
|
|
1610
1608
|
distinct(on?: boolean): this;
|
|
1611
1609
|
countDistinct(key: keyof T, countName?: string): this;
|
|
1612
1610
|
count(countName?: string): this;
|
package/cjs/sql.js
CHANGED
|
@@ -2870,8 +2870,8 @@ class SqlService {
|
|
|
2870
2870
|
});
|
|
2871
2871
|
}
|
|
2872
2872
|
}
|
|
2873
|
-
stream(
|
|
2874
|
-
return new StreamQuery(
|
|
2873
|
+
stream() {
|
|
2874
|
+
return new StreamQuery(this, this[_fields], this[_columns]);
|
|
2875
2875
|
}
|
|
2876
2876
|
page(option) {
|
|
2877
2877
|
const result = {
|
|
@@ -3358,7 +3358,7 @@ const IF_EXEC = function (def) {
|
|
|
3358
3358
|
};
|
|
3359
3359
|
};
|
|
3360
3360
|
class StreamQuery {
|
|
3361
|
-
constructor(
|
|
3361
|
+
constructor(service, __fields, __columns) {
|
|
3362
3362
|
this._prefix = 0;
|
|
3363
3363
|
this._index = 0;
|
|
3364
3364
|
this._wheres = [];
|
|
@@ -3376,7 +3376,6 @@ class StreamQuery {
|
|
|
3376
3376
|
this._startRow = 0;
|
|
3377
3377
|
this._pageSize = 0;
|
|
3378
3378
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3379
|
-
this._table = table;
|
|
3380
3379
|
this._service = service;
|
|
3381
3380
|
this[_fields] = __fields;
|
|
3382
3381
|
this[_columns] = __columns;
|
|
@@ -3501,7 +3500,7 @@ class StreamQuery {
|
|
|
3501
3500
|
this._andQuerys.push(fn);
|
|
3502
3501
|
}
|
|
3503
3502
|
else {
|
|
3504
|
-
const stream = new StreamQuery(this.
|
|
3503
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3505
3504
|
const ret = fn(stream);
|
|
3506
3505
|
if (ret !== false) {
|
|
3507
3506
|
this._andQuerys.push(stream);
|
|
@@ -3514,7 +3513,7 @@ class StreamQuery {
|
|
|
3514
3513
|
this._andQuerys.push(fn);
|
|
3515
3514
|
}
|
|
3516
3515
|
else {
|
|
3517
|
-
const stream = new StreamQuery(this.
|
|
3516
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3518
3517
|
const ret = fn(stream);
|
|
3519
3518
|
if (ret !== false) {
|
|
3520
3519
|
this._orQuerys.push(stream);
|
|
@@ -3530,7 +3529,6 @@ class StreamQuery {
|
|
|
3530
3529
|
desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
|
|
3531
3530
|
limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
|
|
3532
3531
|
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3533
|
-
table(_table) { this._table = _table; return this; }
|
|
3534
3532
|
distinct(on = true) { this._distinct = on; return this; }
|
|
3535
3533
|
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3536
3534
|
count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
|
|
@@ -3574,7 +3572,7 @@ class StreamQuery {
|
|
|
3574
3572
|
let sql = `
|
|
3575
3573
|
SELECT
|
|
3576
3574
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3577
|
-
FROM ${this.
|
|
3575
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3578
3576
|
${where ? ' WHERE ' : ''}
|
|
3579
3577
|
${where}
|
|
3580
3578
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3623,7 +3621,7 @@ class StreamQuery {
|
|
|
3623
3621
|
let sql = `
|
|
3624
3622
|
SELECT
|
|
3625
3623
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3626
|
-
FROM ${this.
|
|
3624
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3627
3625
|
${where ? ' WHERE ' : ''}
|
|
3628
3626
|
${where}
|
|
3629
3627
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3637,7 +3635,7 @@ class StreamQuery {
|
|
|
3637
3635
|
}
|
|
3638
3636
|
const sqlCount = `
|
|
3639
3637
|
SELECT COUNT(1)
|
|
3640
|
-
FROM ${this.
|
|
3638
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3641
3639
|
${where ? ' WHERE ' : ''}
|
|
3642
3640
|
${where}
|
|
3643
3641
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3708,7 +3706,7 @@ class StreamQuery {
|
|
|
3708
3706
|
}
|
|
3709
3707
|
}
|
|
3710
3708
|
if (sets.length > 0) {
|
|
3711
|
-
const sql = `UPDATE ${this.
|
|
3709
|
+
const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
|
|
3712
3710
|
${where ? ' WHERE ' : ''}
|
|
3713
3711
|
${where}
|
|
3714
3712
|
`;
|
|
@@ -3727,7 +3725,7 @@ class StreamQuery {
|
|
|
3727
3725
|
option ?? (option = {});
|
|
3728
3726
|
option.sync ?? (option.sync = SyncMode.Async);
|
|
3729
3727
|
const { where, params } = this._where();
|
|
3730
|
-
const sql = `DELETE FROM ${this.
|
|
3728
|
+
const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
|
|
3731
3729
|
${where ? ' WHERE ' : ''}
|
|
3732
3730
|
${where}
|
|
3733
3731
|
`;
|
|
@@ -4324,12 +4322,6 @@ __decorate([
|
|
|
4324
4322
|
__metadata("design:paramtypes", [Number, Number]),
|
|
4325
4323
|
__metadata("design:returntype", void 0)
|
|
4326
4324
|
], StreamQuery.prototype, "page", null);
|
|
4327
|
-
__decorate([
|
|
4328
|
-
IF_PROCEED(),
|
|
4329
|
-
__metadata("design:type", Function),
|
|
4330
|
-
__metadata("design:paramtypes", [String]),
|
|
4331
|
-
__metadata("design:returntype", void 0)
|
|
4332
|
-
], StreamQuery.prototype, "table", null);
|
|
4333
4325
|
__decorate([
|
|
4334
4326
|
IF_PROCEED(),
|
|
4335
4327
|
__metadata("design:type", Function),
|
package/es/sql.d.ts
CHANGED
|
@@ -752,7 +752,7 @@ export declare function DeclareService(clz: any, config: ServiceOption): any;
|
|
|
752
752
|
|
|
753
753
|
*/
|
|
754
754
|
export declare class SqlService<T extends object> {
|
|
755
|
-
|
|
755
|
+
[_tableName]?: string;
|
|
756
756
|
private [_className]?;
|
|
757
757
|
private [_ClassName]?;
|
|
758
758
|
private [_vueName]?;
|
|
@@ -1266,7 +1266,7 @@ export declare class SqlService<T extends object> {
|
|
|
1266
1266
|
sync: SyncMode.Sync;
|
|
1267
1267
|
fn: (conn: Connection) => L;
|
|
1268
1268
|
}): L | null;
|
|
1269
|
-
stream<L extends object = T>(
|
|
1269
|
+
stream<L extends object = T>(): StreamQuery<L>;
|
|
1270
1270
|
page<L = T>(option: MethodOption & {
|
|
1271
1271
|
sync?: SyncMode.Async;
|
|
1272
1272
|
sqlId: string;
|
|
@@ -1362,7 +1362,6 @@ declare class StreamQuery<T extends object> {
|
|
|
1362
1362
|
private _param;
|
|
1363
1363
|
if_proceed: boolean;
|
|
1364
1364
|
if_exec: boolean;
|
|
1365
|
-
private _table;
|
|
1366
1365
|
private _distinct;
|
|
1367
1366
|
private _columns;
|
|
1368
1367
|
private _updates?;
|
|
@@ -1374,7 +1373,7 @@ declare class StreamQuery<T extends object> {
|
|
|
1374
1373
|
private _service;
|
|
1375
1374
|
private [_fields];
|
|
1376
1375
|
private [_columns];
|
|
1377
|
-
constructor(
|
|
1376
|
+
constructor(service: SqlService<T>, __fields: Record<string, AField>, __columns: string[]);
|
|
1378
1377
|
/** 将当前stream重置 */
|
|
1379
1378
|
reset(): this;
|
|
1380
1379
|
/** 为下次链条执行提供条件判断:非异步方法跳过,异步方法不执行并返回默认值 */
|
|
@@ -1606,7 +1605,6 @@ declare class StreamQuery<T extends object> {
|
|
|
1606
1605
|
desc2(...keys: string[]): this;
|
|
1607
1606
|
limit(startRow: number, pageSize: number): this;
|
|
1608
1607
|
page(pageNumber: number, pageSize: number): this;
|
|
1609
|
-
table(_table: string): this;
|
|
1610
1608
|
distinct(on?: boolean): this;
|
|
1611
1609
|
countDistinct(key: keyof T, countName?: string): this;
|
|
1612
1610
|
count(countName?: string): this;
|
package/es/sql.js
CHANGED
|
@@ -2824,8 +2824,8 @@ export class SqlService {
|
|
|
2824
2824
|
});
|
|
2825
2825
|
}
|
|
2826
2826
|
}
|
|
2827
|
-
stream(
|
|
2828
|
-
return new StreamQuery(
|
|
2827
|
+
stream() {
|
|
2828
|
+
return new StreamQuery(this, this[_fields], this[_columns]);
|
|
2829
2829
|
}
|
|
2830
2830
|
page(option) {
|
|
2831
2831
|
const result = {
|
|
@@ -3311,7 +3311,7 @@ const IF_EXEC = function (def) {
|
|
|
3311
3311
|
};
|
|
3312
3312
|
};
|
|
3313
3313
|
class StreamQuery {
|
|
3314
|
-
constructor(
|
|
3314
|
+
constructor(service, __fields, __columns) {
|
|
3315
3315
|
this._prefix = 0;
|
|
3316
3316
|
this._index = 0;
|
|
3317
3317
|
this._wheres = [];
|
|
@@ -3329,7 +3329,6 @@ class StreamQuery {
|
|
|
3329
3329
|
this._startRow = 0;
|
|
3330
3330
|
this._pageSize = 0;
|
|
3331
3331
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3332
|
-
this._table = table;
|
|
3333
3332
|
this._service = service;
|
|
3334
3333
|
this[_fields] = __fields;
|
|
3335
3334
|
this[_columns] = __columns;
|
|
@@ -3454,7 +3453,7 @@ class StreamQuery {
|
|
|
3454
3453
|
this._andQuerys.push(fn);
|
|
3455
3454
|
}
|
|
3456
3455
|
else {
|
|
3457
|
-
const stream = new StreamQuery(this.
|
|
3456
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3458
3457
|
const ret = fn(stream);
|
|
3459
3458
|
if (ret !== false) {
|
|
3460
3459
|
this._andQuerys.push(stream);
|
|
@@ -3467,7 +3466,7 @@ class StreamQuery {
|
|
|
3467
3466
|
this._andQuerys.push(fn);
|
|
3468
3467
|
}
|
|
3469
3468
|
else {
|
|
3470
|
-
const stream = new StreamQuery(this.
|
|
3469
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3471
3470
|
const ret = fn(stream);
|
|
3472
3471
|
if (ret !== false) {
|
|
3473
3472
|
this._orQuerys.push(stream);
|
|
@@ -3483,7 +3482,6 @@ class StreamQuery {
|
|
|
3483
3482
|
desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
|
|
3484
3483
|
limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
|
|
3485
3484
|
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3486
|
-
table(_table) { this._table = _table; return this; }
|
|
3487
3485
|
distinct(on = true) { this._distinct = on; return this; }
|
|
3488
3486
|
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3489
3487
|
count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
|
|
@@ -3527,7 +3525,7 @@ class StreamQuery {
|
|
|
3527
3525
|
let sql = `
|
|
3528
3526
|
SELECT
|
|
3529
3527
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3530
|
-
FROM ${this.
|
|
3528
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3531
3529
|
${where ? ' WHERE ' : ''}
|
|
3532
3530
|
${where}
|
|
3533
3531
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3576,7 +3574,7 @@ class StreamQuery {
|
|
|
3576
3574
|
let sql = `
|
|
3577
3575
|
SELECT
|
|
3578
3576
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3579
|
-
FROM ${this.
|
|
3577
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3580
3578
|
${where ? ' WHERE ' : ''}
|
|
3581
3579
|
${where}
|
|
3582
3580
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3590,7 +3588,7 @@ class StreamQuery {
|
|
|
3590
3588
|
}
|
|
3591
3589
|
const sqlCount = `
|
|
3592
3590
|
SELECT COUNT(1)
|
|
3593
|
-
FROM ${this.
|
|
3591
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3594
3592
|
${where ? ' WHERE ' : ''}
|
|
3595
3593
|
${where}
|
|
3596
3594
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3661,7 +3659,7 @@ class StreamQuery {
|
|
|
3661
3659
|
}
|
|
3662
3660
|
}
|
|
3663
3661
|
if (sets.length > 0) {
|
|
3664
|
-
const sql = `UPDATE ${this.
|
|
3662
|
+
const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
|
|
3665
3663
|
${where ? ' WHERE ' : ''}
|
|
3666
3664
|
${where}
|
|
3667
3665
|
`;
|
|
@@ -3680,7 +3678,7 @@ class StreamQuery {
|
|
|
3680
3678
|
option ?? (option = {});
|
|
3681
3679
|
option.sync ?? (option.sync = SyncMode.Async);
|
|
3682
3680
|
const { where, params } = this._where();
|
|
3683
|
-
const sql = `DELETE FROM ${this.
|
|
3681
|
+
const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
|
|
3684
3682
|
${where ? ' WHERE ' : ''}
|
|
3685
3683
|
${where}
|
|
3686
3684
|
`;
|
|
@@ -4277,12 +4275,6 @@ __decorate([
|
|
|
4277
4275
|
__metadata("design:paramtypes", [Number, Number]),
|
|
4278
4276
|
__metadata("design:returntype", void 0)
|
|
4279
4277
|
], StreamQuery.prototype, "page", null);
|
|
4280
|
-
__decorate([
|
|
4281
|
-
IF_PROCEED(),
|
|
4282
|
-
__metadata("design:type", Function),
|
|
4283
|
-
__metadata("design:paramtypes", [String]),
|
|
4284
|
-
__metadata("design:returntype", void 0)
|
|
4285
|
-
], StreamQuery.prototype, "table", null);
|
|
4286
4278
|
__decorate([
|
|
4287
4279
|
IF_PROCEED(),
|
|
4288
4280
|
__metadata("design:type", Function),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baja-lite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "some util for self",
|
|
5
5
|
"homepage": "https://github.com/void-soul/util-man",
|
|
6
6
|
"repository": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"@types/mustache": "4.2.5",
|
|
51
51
|
"@types/node": "20.14.14",
|
|
52
52
|
"@types/sqlstring": "2.3.2",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
54
|
-
"@typescript-eslint/parser": "8.
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "8.3.0",
|
|
54
|
+
"@typescript-eslint/parser": "8.3.0",
|
|
55
55
|
"better-sqlite3": "11.2.1",
|
|
56
56
|
"ioredis": "5.4.1",
|
|
57
57
|
"mongodb": "6.8.0",
|
package/src/sql.ts
CHANGED
|
@@ -2397,7 +2397,7 @@ export function DeclareService(clz: any, config: ServiceOption) {
|
|
|
2397
2397
|
|
|
2398
2398
|
*/
|
|
2399
2399
|
export class SqlService<T extends object> {
|
|
2400
|
-
|
|
2400
|
+
[_tableName]?: string;
|
|
2401
2401
|
private [_className]?: string;
|
|
2402
2402
|
private [_ClassName]?: string;
|
|
2403
2403
|
private [_vueName]?: string;
|
|
@@ -3405,8 +3405,8 @@ export class SqlService<T extends object> {
|
|
|
3405
3405
|
}
|
|
3406
3406
|
}
|
|
3407
3407
|
|
|
3408
|
-
stream<L extends object = T>(
|
|
3409
|
-
return new StreamQuery<L>(
|
|
3408
|
+
stream<L extends object = T>() {
|
|
3409
|
+
return new StreamQuery<L>(this as any, this[_fields]!, this[_columns]!);
|
|
3410
3410
|
}
|
|
3411
3411
|
|
|
3412
3412
|
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>>;
|
|
@@ -3855,7 +3855,6 @@ class StreamQuery<T extends object> {
|
|
|
3855
3855
|
private _param: Record<string, any> = {};
|
|
3856
3856
|
public if_proceed = true;
|
|
3857
3857
|
public if_exec = true;
|
|
3858
|
-
private _table: string;
|
|
3859
3858
|
|
|
3860
3859
|
private _distinct = false;
|
|
3861
3860
|
private _columns: string[] = [];
|
|
@@ -3872,9 +3871,8 @@ class StreamQuery<T extends object> {
|
|
|
3872
3871
|
private _service: SqlService<T>;
|
|
3873
3872
|
private [_fields]: Record<string, AField>;
|
|
3874
3873
|
private [_columns]: string[];
|
|
3875
|
-
constructor(
|
|
3874
|
+
constructor(service: SqlService<T>, __fields: Record<string, AField>, __columns: string[]) {
|
|
3876
3875
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3877
|
-
this._table = table;
|
|
3878
3876
|
this._service = service;
|
|
3879
3877
|
this[_fields] = __fields;
|
|
3880
3878
|
this[_columns] = __columns;
|
|
@@ -4050,7 +4048,7 @@ class StreamQuery<T extends object> {
|
|
|
4050
4048
|
if (fn instanceof StreamQuery) {
|
|
4051
4049
|
this._andQuerys.push(fn);
|
|
4052
4050
|
} else {
|
|
4053
|
-
const stream = new StreamQuery<T>(this.
|
|
4051
|
+
const stream = new StreamQuery<T>(this._service, this[_fields], this[_columns]);
|
|
4054
4052
|
const ret = fn(stream);
|
|
4055
4053
|
if (ret !== false) { this._andQuerys.push(stream); }
|
|
4056
4054
|
}
|
|
@@ -4061,7 +4059,7 @@ class StreamQuery<T extends object> {
|
|
|
4061
4059
|
if (fn instanceof StreamQuery) {
|
|
4062
4060
|
this._andQuerys.push(fn);
|
|
4063
4061
|
} else {
|
|
4064
|
-
const stream = new StreamQuery<T>(this.
|
|
4062
|
+
const stream = new StreamQuery<T>(this._service, this[_fields], this[_columns]!);
|
|
4065
4063
|
const ret = fn(stream);
|
|
4066
4064
|
if (ret !== false) { this._orQuerys.push(stream); }
|
|
4067
4065
|
}
|
|
@@ -4085,8 +4083,6 @@ class StreamQuery<T extends object> {
|
|
|
4085
4083
|
@IF_PROCEED<T>()
|
|
4086
4084
|
page(pageNumber: number, pageSize: number) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
4087
4085
|
@IF_PROCEED<T>()
|
|
4088
|
-
table(_table: string) { this._table = _table; return this; }
|
|
4089
|
-
@IF_PROCEED<T>()
|
|
4090
4086
|
distinct(on = true) { this._distinct = on; return this; }
|
|
4091
4087
|
@IF_PROCEED<T>()
|
|
4092
4088
|
countDistinct(key: keyof T, countName?: string,) { this._columns.push(`COUNT(DISTINCT ${this[_fields]![String(key)]?.C2()}) ${countName || `${this[_fields]![String(key)]?.C2()}`}`); return this; }
|
|
@@ -4154,7 +4150,7 @@ class StreamQuery<T extends object> {
|
|
|
4154
4150
|
let sql = `
|
|
4155
4151
|
SELECT
|
|
4156
4152
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields]![String(key)]?.C3()).join(',')}
|
|
4157
|
-
FROM ${this.
|
|
4153
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
4158
4154
|
${where ? ' WHERE ' : ''}
|
|
4159
4155
|
${where}
|
|
4160
4156
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -4202,7 +4198,7 @@ class StreamQuery<T extends object> {
|
|
|
4202
4198
|
let sql = `
|
|
4203
4199
|
SELECT
|
|
4204
4200
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields]![String(key)]?.C3()).join(',')}
|
|
4205
|
-
FROM ${this.
|
|
4201
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
4206
4202
|
${where ? ' WHERE ' : ''}
|
|
4207
4203
|
${where}
|
|
4208
4204
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -4215,7 +4211,7 @@ class StreamQuery<T extends object> {
|
|
|
4215
4211
|
}
|
|
4216
4212
|
const sqlCount = `
|
|
4217
4213
|
SELECT COUNT(1)
|
|
4218
|
-
FROM ${this.
|
|
4214
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
4219
4215
|
${where ? ' WHERE ' : ''}
|
|
4220
4216
|
${where}
|
|
4221
4217
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -4287,7 +4283,7 @@ class StreamQuery<T extends object> {
|
|
|
4287
4283
|
}
|
|
4288
4284
|
}
|
|
4289
4285
|
if (sets.length > 0) {
|
|
4290
|
-
const sql = `UPDATE ${this.
|
|
4286
|
+
const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
|
|
4291
4287
|
${where ? ' WHERE ' : ''}
|
|
4292
4288
|
${where}
|
|
4293
4289
|
`;
|
|
@@ -4307,7 +4303,7 @@ class StreamQuery<T extends object> {
|
|
|
4307
4303
|
option ??= {};
|
|
4308
4304
|
option.sync ??= SyncMode.Async;
|
|
4309
4305
|
const { where, params } = this._where();
|
|
4310
|
-
const sql = `DELETE FROM ${this.
|
|
4306
|
+
const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
|
|
4311
4307
|
${where ? ' WHERE ' : ''}
|
|
4312
4308
|
${where}
|
|
4313
4309
|
`;
|