baja-lite 1.0.25 → 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 +9 -11
- package/cjs/sql.js +26 -30
- package/cjs/sqlite.d.ts +5 -5
- package/cjs/sqlite.js +5 -5
- package/es/sql.d.ts +9 -11
- package/es/sql.js +26 -30
- package/es/sqlite.d.ts +5 -5
- package/es/sqlite.js +5 -5
- package/package.json +3 -3
- package/src/sql.ts +33 -33
- package/src/sqlite.ts +5 -5
package/cjs/sql.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare const _def: unique symbol;
|
|
|
21
21
|
declare const _comment: unique symbol;
|
|
22
22
|
export declare const _sqlCache: unique symbol;
|
|
23
23
|
export declare const _dao: unique symbol;
|
|
24
|
-
export declare const _primaryDB
|
|
24
|
+
export declare const _primaryDB = "______primaryDB_______";
|
|
25
25
|
declare const _dbType: unique symbol;
|
|
26
26
|
declare const _formatDialect: unique symbol;
|
|
27
27
|
declare const _sqlite_version: unique symbol;
|
|
@@ -485,11 +485,11 @@ export interface PageQuery<L> {
|
|
|
485
485
|
}
|
|
486
486
|
/** sqlite electron服务端需要支持的接口 */
|
|
487
487
|
export interface SqliteRemoteInterface {
|
|
488
|
-
execute(inData: Uint8Array): Uint8Array
|
|
489
|
-
pluck(inData: Uint8Array): Uint8Array
|
|
490
|
-
get(inData: Uint8Array): Uint8Array
|
|
491
|
-
raw(inData: Uint8Array): Uint8Array
|
|
492
|
-
query(inData: Uint8Array): Uint8Array
|
|
488
|
+
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
489
|
+
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
490
|
+
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
491
|
+
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
492
|
+
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
493
493
|
initDB(dbName: string): void;
|
|
494
494
|
export(dbName: string, exportPath: string): Promise<void>;
|
|
495
495
|
restore(dbName: string, importPath: string): void;
|
|
@@ -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
|
@@ -109,7 +109,7 @@ const _def = Symbol('def');
|
|
|
109
109
|
const _comment = Symbol('comment');
|
|
110
110
|
exports._sqlCache = Symbol('sqlMap');
|
|
111
111
|
exports._dao = Symbol('dao');
|
|
112
|
-
exports._primaryDB =
|
|
112
|
+
exports._primaryDB = '______primaryDB_______';
|
|
113
113
|
const _dbType = Symbol('dbType');
|
|
114
114
|
const _formatDialect = Symbol('FormatDialect');
|
|
115
115
|
const _sqlite_version = Symbol('sqlite_version');
|
|
@@ -1543,12 +1543,14 @@ function P(skipConn = false) {
|
|
|
1543
1543
|
const dbName = option?.dbName ?? this[_daoDBName] ?? exports._primaryDB;
|
|
1544
1544
|
option.dao = globalThis[exports._dao][this[_dbType]][dbName];
|
|
1545
1545
|
if (this[_dbType] === DBType.Sqlite) {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
globalThis[exports._dao][this[_dbType]][exports._primaryDB]
|
|
1546
|
+
if (!option.dao) {
|
|
1547
|
+
const db = new Sqlite(new globalThis[exports._GlobalSqlOption].BetterSqlite3(dbName, { fileMustExist: false }));
|
|
1548
|
+
if (globalThis[exports._dao][this[_dbType]][exports._primaryDB] === undefined) {
|
|
1549
|
+
globalThis[exports._dao][this[_dbType]][exports._primaryDB] = db;
|
|
1550
|
+
}
|
|
1551
|
+
globalThis[exports._dao][this[_dbType]][dbName] = db;
|
|
1552
|
+
option.dao = db;
|
|
1549
1553
|
}
|
|
1550
|
-
globalThis[exports._dao][this[_dbType]][dbName] = db;
|
|
1551
|
-
option.dao = db;
|
|
1552
1554
|
error_1.Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!');
|
|
1553
1555
|
// 连接共享
|
|
1554
1556
|
if (skipConn === false && !option.conn) {
|
|
@@ -1581,13 +1583,15 @@ function P(skipConn = false) {
|
|
|
1581
1583
|
}
|
|
1582
1584
|
}
|
|
1583
1585
|
else if (this[_dbType] === DBType.SqliteRemote) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
globalThis[exports._dao][this[_dbType]][exports._primaryDB]
|
|
1586
|
+
if (!option.dao) {
|
|
1587
|
+
globalThis[exports._GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
1588
|
+
const db = new SqliteRemote(globalThis[exports._GlobalSqlOption].SqliteRemote.service, dbName);
|
|
1589
|
+
if (globalThis[exports._dao][this[_dbType]][exports._primaryDB] === undefined) {
|
|
1590
|
+
globalThis[exports._dao][this[_dbType]][exports._primaryDB] = db;
|
|
1591
|
+
}
|
|
1592
|
+
globalThis[exports._dao][this[_dbType]][dbName] = db;
|
|
1593
|
+
option.dao = db;
|
|
1588
1594
|
}
|
|
1589
|
-
globalThis[exports._dao][this[_dbType]][dbName] = db;
|
|
1590
|
-
option.dao = db;
|
|
1591
1595
|
error_1.Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!');
|
|
1592
1596
|
return new Promise(async (resolve, reject) => {
|
|
1593
1597
|
// 连接共享
|
|
@@ -2866,8 +2870,8 @@ class SqlService {
|
|
|
2866
2870
|
});
|
|
2867
2871
|
}
|
|
2868
2872
|
}
|
|
2869
|
-
stream(
|
|
2870
|
-
return new StreamQuery(
|
|
2873
|
+
stream() {
|
|
2874
|
+
return new StreamQuery(this, this[_fields], this[_columns]);
|
|
2871
2875
|
}
|
|
2872
2876
|
page(option) {
|
|
2873
2877
|
const result = {
|
|
@@ -3354,7 +3358,7 @@ const IF_EXEC = function (def) {
|
|
|
3354
3358
|
};
|
|
3355
3359
|
};
|
|
3356
3360
|
class StreamQuery {
|
|
3357
|
-
constructor(
|
|
3361
|
+
constructor(service, __fields, __columns) {
|
|
3358
3362
|
this._prefix = 0;
|
|
3359
3363
|
this._index = 0;
|
|
3360
3364
|
this._wheres = [];
|
|
@@ -3372,7 +3376,6 @@ class StreamQuery {
|
|
|
3372
3376
|
this._startRow = 0;
|
|
3373
3377
|
this._pageSize = 0;
|
|
3374
3378
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3375
|
-
this._table = table;
|
|
3376
3379
|
this._service = service;
|
|
3377
3380
|
this[_fields] = __fields;
|
|
3378
3381
|
this[_columns] = __columns;
|
|
@@ -3497,7 +3500,7 @@ class StreamQuery {
|
|
|
3497
3500
|
this._andQuerys.push(fn);
|
|
3498
3501
|
}
|
|
3499
3502
|
else {
|
|
3500
|
-
const stream = new StreamQuery(this.
|
|
3503
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3501
3504
|
const ret = fn(stream);
|
|
3502
3505
|
if (ret !== false) {
|
|
3503
3506
|
this._andQuerys.push(stream);
|
|
@@ -3510,7 +3513,7 @@ class StreamQuery {
|
|
|
3510
3513
|
this._andQuerys.push(fn);
|
|
3511
3514
|
}
|
|
3512
3515
|
else {
|
|
3513
|
-
const stream = new StreamQuery(this.
|
|
3516
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3514
3517
|
const ret = fn(stream);
|
|
3515
3518
|
if (ret !== false) {
|
|
3516
3519
|
this._orQuerys.push(stream);
|
|
@@ -3526,7 +3529,6 @@ class StreamQuery {
|
|
|
3526
3529
|
desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
|
|
3527
3530
|
limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
|
|
3528
3531
|
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3529
|
-
table(_table) { this._table = _table; return this; }
|
|
3530
3532
|
distinct(on = true) { this._distinct = on; return this; }
|
|
3531
3533
|
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3532
3534
|
count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
|
|
@@ -3570,7 +3572,7 @@ class StreamQuery {
|
|
|
3570
3572
|
let sql = `
|
|
3571
3573
|
SELECT
|
|
3572
3574
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3573
|
-
FROM ${this.
|
|
3575
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3574
3576
|
${where ? ' WHERE ' : ''}
|
|
3575
3577
|
${where}
|
|
3576
3578
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3619,7 +3621,7 @@ class StreamQuery {
|
|
|
3619
3621
|
let sql = `
|
|
3620
3622
|
SELECT
|
|
3621
3623
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3622
|
-
FROM ${this.
|
|
3624
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3623
3625
|
${where ? ' WHERE ' : ''}
|
|
3624
3626
|
${where}
|
|
3625
3627
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3633,7 +3635,7 @@ class StreamQuery {
|
|
|
3633
3635
|
}
|
|
3634
3636
|
const sqlCount = `
|
|
3635
3637
|
SELECT COUNT(1)
|
|
3636
|
-
FROM ${this.
|
|
3638
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3637
3639
|
${where ? ' WHERE ' : ''}
|
|
3638
3640
|
${where}
|
|
3639
3641
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3704,7 +3706,7 @@ class StreamQuery {
|
|
|
3704
3706
|
}
|
|
3705
3707
|
}
|
|
3706
3708
|
if (sets.length > 0) {
|
|
3707
|
-
const sql = `UPDATE ${this.
|
|
3709
|
+
const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
|
|
3708
3710
|
${where ? ' WHERE ' : ''}
|
|
3709
3711
|
${where}
|
|
3710
3712
|
`;
|
|
@@ -3723,7 +3725,7 @@ class StreamQuery {
|
|
|
3723
3725
|
option ?? (option = {});
|
|
3724
3726
|
option.sync ?? (option.sync = SyncMode.Async);
|
|
3725
3727
|
const { where, params } = this._where();
|
|
3726
|
-
const sql = `DELETE FROM ${this.
|
|
3728
|
+
const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
|
|
3727
3729
|
${where ? ' WHERE ' : ''}
|
|
3728
3730
|
${where}
|
|
3729
3731
|
`;
|
|
@@ -4320,12 +4322,6 @@ __decorate([
|
|
|
4320
4322
|
__metadata("design:paramtypes", [Number, Number]),
|
|
4321
4323
|
__metadata("design:returntype", void 0)
|
|
4322
4324
|
], StreamQuery.prototype, "page", null);
|
|
4323
|
-
__decorate([
|
|
4324
|
-
IF_PROCEED(),
|
|
4325
|
-
__metadata("design:type", Function),
|
|
4326
|
-
__metadata("design:paramtypes", [String]),
|
|
4327
|
-
__metadata("design:returntype", void 0)
|
|
4328
|
-
], StreamQuery.prototype, "table", null);
|
|
4329
4325
|
__decorate([
|
|
4330
4326
|
IF_PROCEED(),
|
|
4331
4327
|
__metadata("design:type", Function),
|
package/cjs/sqlite.d.ts
CHANGED
|
@@ -20,11 +20,11 @@ export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface
|
|
|
20
20
|
*/
|
|
21
21
|
abstract setMod(name: string): void;
|
|
22
22
|
abstract trace: boolean;
|
|
23
|
-
execute(inData: Uint8Array): Uint8Array
|
|
24
|
-
pluck(inData: Uint8Array): Uint8Array
|
|
25
|
-
get(inData: Uint8Array): Uint8Array
|
|
26
|
-
raw(inData: Uint8Array): Uint8Array
|
|
27
|
-
query(inData: Uint8Array): Uint8Array
|
|
23
|
+
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
24
|
+
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
25
|
+
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
26
|
+
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
28
28
|
initDB(dbName: string): void;
|
|
29
29
|
export(dbName: string, exportPath: string): Promise<void>;
|
|
30
30
|
restore(dbName: string, importPath: string): void;
|
package/cjs/sqlite.js
CHANGED
|
@@ -11,7 +11,7 @@ class SqliteRemoteClass {
|
|
|
11
11
|
constructor() {
|
|
12
12
|
this.dbList = {};
|
|
13
13
|
}
|
|
14
|
-
execute(inData) {
|
|
14
|
+
async execute(inData) {
|
|
15
15
|
const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
|
|
16
16
|
sql_1.logger.debug(sql, params ?? '');
|
|
17
17
|
try {
|
|
@@ -38,7 +38,7 @@ class SqliteRemoteClass {
|
|
|
38
38
|
throw error;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
pluck(inData) {
|
|
41
|
+
async pluck(inData) {
|
|
42
42
|
const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
|
|
43
43
|
sql_1.logger.debug(sql, params ?? '');
|
|
44
44
|
try {
|
|
@@ -61,7 +61,7 @@ class SqliteRemoteClass {
|
|
|
61
61
|
throw error;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
get(inData) {
|
|
64
|
+
async get(inData) {
|
|
65
65
|
const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
|
|
66
66
|
sql_1.logger.debug(sql, params ?? '');
|
|
67
67
|
try {
|
|
@@ -79,7 +79,7 @@ class SqliteRemoteClass {
|
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
raw(inData) {
|
|
82
|
+
async raw(inData) {
|
|
83
83
|
const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
|
|
84
84
|
sql_1.logger.debug(sql, params ?? '');
|
|
85
85
|
try {
|
|
@@ -101,7 +101,7 @@ class SqliteRemoteClass {
|
|
|
101
101
|
throw error;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
query(inData) {
|
|
104
|
+
async query(inData) {
|
|
105
105
|
const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
|
|
106
106
|
sql_1.logger.debug(sql, params ?? '');
|
|
107
107
|
try {
|
package/es/sql.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare const _def: unique symbol;
|
|
|
21
21
|
declare const _comment: unique symbol;
|
|
22
22
|
export declare const _sqlCache: unique symbol;
|
|
23
23
|
export declare const _dao: unique symbol;
|
|
24
|
-
export declare const _primaryDB
|
|
24
|
+
export declare const _primaryDB = "______primaryDB_______";
|
|
25
25
|
declare const _dbType: unique symbol;
|
|
26
26
|
declare const _formatDialect: unique symbol;
|
|
27
27
|
declare const _sqlite_version: unique symbol;
|
|
@@ -485,11 +485,11 @@ export interface PageQuery<L> {
|
|
|
485
485
|
}
|
|
486
486
|
/** sqlite electron服务端需要支持的接口 */
|
|
487
487
|
export interface SqliteRemoteInterface {
|
|
488
|
-
execute(inData: Uint8Array): Uint8Array
|
|
489
|
-
pluck(inData: Uint8Array): Uint8Array
|
|
490
|
-
get(inData: Uint8Array): Uint8Array
|
|
491
|
-
raw(inData: Uint8Array): Uint8Array
|
|
492
|
-
query(inData: Uint8Array): Uint8Array
|
|
488
|
+
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
489
|
+
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
490
|
+
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
491
|
+
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
492
|
+
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
493
493
|
initDB(dbName: string): void;
|
|
494
494
|
export(dbName: string, exportPath: string): Promise<void>;
|
|
495
495
|
restore(dbName: string, importPath: string): void;
|
|
@@ -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
|
@@ -70,7 +70,7 @@ const _def = Symbol('def');
|
|
|
70
70
|
const _comment = Symbol('comment');
|
|
71
71
|
export const _sqlCache = Symbol('sqlMap');
|
|
72
72
|
export const _dao = Symbol('dao');
|
|
73
|
-
export const _primaryDB =
|
|
73
|
+
export const _primaryDB = '______primaryDB_______';
|
|
74
74
|
const _dbType = Symbol('dbType');
|
|
75
75
|
const _formatDialect = Symbol('FormatDialect');
|
|
76
76
|
const _sqlite_version = Symbol('sqlite_version');
|
|
@@ -1499,12 +1499,14 @@ function P(skipConn = false) {
|
|
|
1499
1499
|
const dbName = option?.dbName ?? this[_daoDBName] ?? _primaryDB;
|
|
1500
1500
|
option.dao = globalThis[_dao][this[_dbType]][dbName];
|
|
1501
1501
|
if (this[_dbType] === DBType.Sqlite) {
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
globalThis[_dao][this[_dbType]][_primaryDB]
|
|
1502
|
+
if (!option.dao) {
|
|
1503
|
+
const db = new Sqlite(new globalThis[_GlobalSqlOption].BetterSqlite3(dbName, { fileMustExist: false }));
|
|
1504
|
+
if (globalThis[_dao][this[_dbType]][_primaryDB] === undefined) {
|
|
1505
|
+
globalThis[_dao][this[_dbType]][_primaryDB] = db;
|
|
1506
|
+
}
|
|
1507
|
+
globalThis[_dao][this[_dbType]][dbName] = db;
|
|
1508
|
+
option.dao = db;
|
|
1505
1509
|
}
|
|
1506
|
-
globalThis[_dao][this[_dbType]][dbName] = db;
|
|
1507
|
-
option.dao = db;
|
|
1508
1510
|
Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!');
|
|
1509
1511
|
// 连接共享
|
|
1510
1512
|
if (skipConn === false && !option.conn) {
|
|
@@ -1537,13 +1539,15 @@ function P(skipConn = false) {
|
|
|
1537
1539
|
}
|
|
1538
1540
|
}
|
|
1539
1541
|
else if (this[_dbType] === DBType.SqliteRemote) {
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
globalThis[_dao][this[_dbType]][_primaryDB]
|
|
1542
|
+
if (!option.dao) {
|
|
1543
|
+
globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
1544
|
+
const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
|
|
1545
|
+
if (globalThis[_dao][this[_dbType]][_primaryDB] === undefined) {
|
|
1546
|
+
globalThis[_dao][this[_dbType]][_primaryDB] = db;
|
|
1547
|
+
}
|
|
1548
|
+
globalThis[_dao][this[_dbType]][dbName] = db;
|
|
1549
|
+
option.dao = db;
|
|
1544
1550
|
}
|
|
1545
|
-
globalThis[_dao][this[_dbType]][dbName] = db;
|
|
1546
|
-
option.dao = db;
|
|
1547
1551
|
Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!');
|
|
1548
1552
|
return new Promise(async (resolve, reject) => {
|
|
1549
1553
|
// 连接共享
|
|
@@ -2820,8 +2824,8 @@ export class SqlService {
|
|
|
2820
2824
|
});
|
|
2821
2825
|
}
|
|
2822
2826
|
}
|
|
2823
|
-
stream(
|
|
2824
|
-
return new StreamQuery(
|
|
2827
|
+
stream() {
|
|
2828
|
+
return new StreamQuery(this, this[_fields], this[_columns]);
|
|
2825
2829
|
}
|
|
2826
2830
|
page(option) {
|
|
2827
2831
|
const result = {
|
|
@@ -3307,7 +3311,7 @@ const IF_EXEC = function (def) {
|
|
|
3307
3311
|
};
|
|
3308
3312
|
};
|
|
3309
3313
|
class StreamQuery {
|
|
3310
|
-
constructor(
|
|
3314
|
+
constructor(service, __fields, __columns) {
|
|
3311
3315
|
this._prefix = 0;
|
|
3312
3316
|
this._index = 0;
|
|
3313
3317
|
this._wheres = [];
|
|
@@ -3325,7 +3329,6 @@ class StreamQuery {
|
|
|
3325
3329
|
this._startRow = 0;
|
|
3326
3330
|
this._pageSize = 0;
|
|
3327
3331
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3328
|
-
this._table = table;
|
|
3329
3332
|
this._service = service;
|
|
3330
3333
|
this[_fields] = __fields;
|
|
3331
3334
|
this[_columns] = __columns;
|
|
@@ -3450,7 +3453,7 @@ class StreamQuery {
|
|
|
3450
3453
|
this._andQuerys.push(fn);
|
|
3451
3454
|
}
|
|
3452
3455
|
else {
|
|
3453
|
-
const stream = new StreamQuery(this.
|
|
3456
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3454
3457
|
const ret = fn(stream);
|
|
3455
3458
|
if (ret !== false) {
|
|
3456
3459
|
this._andQuerys.push(stream);
|
|
@@ -3463,7 +3466,7 @@ class StreamQuery {
|
|
|
3463
3466
|
this._andQuerys.push(fn);
|
|
3464
3467
|
}
|
|
3465
3468
|
else {
|
|
3466
|
-
const stream = new StreamQuery(this.
|
|
3469
|
+
const stream = new StreamQuery(this._service, this[_fields], this[_columns]);
|
|
3467
3470
|
const ret = fn(stream);
|
|
3468
3471
|
if (ret !== false) {
|
|
3469
3472
|
this._orQuerys.push(stream);
|
|
@@ -3479,7 +3482,6 @@ class StreamQuery {
|
|
|
3479
3482
|
desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
|
|
3480
3483
|
limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
|
|
3481
3484
|
page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
3482
|
-
table(_table) { this._table = _table; return this; }
|
|
3483
3485
|
distinct(on = true) { this._distinct = on; return this; }
|
|
3484
3486
|
countDistinct(key, countName) { this._columns.push(`COUNT(DISTINCT ${this[_fields][String(key)]?.C2()}) ${countName || `${this[_fields][String(key)]?.C2()}`}`); return this; }
|
|
3485
3487
|
count(countName) { this._columns.push(`COUNT(1) ${countName ?? 'ct'}`); return this; }
|
|
@@ -3523,7 +3525,7 @@ class StreamQuery {
|
|
|
3523
3525
|
let sql = `
|
|
3524
3526
|
SELECT
|
|
3525
3527
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3526
|
-
FROM ${this.
|
|
3528
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3527
3529
|
${where ? ' WHERE ' : ''}
|
|
3528
3530
|
${where}
|
|
3529
3531
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3572,7 +3574,7 @@ class StreamQuery {
|
|
|
3572
3574
|
let sql = `
|
|
3573
3575
|
SELECT
|
|
3574
3576
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields][String(key)]?.C3()).join(',')}
|
|
3575
|
-
FROM ${this.
|
|
3577
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3576
3578
|
${where ? ' WHERE ' : ''}
|
|
3577
3579
|
${where}
|
|
3578
3580
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3586,7 +3588,7 @@ class StreamQuery {
|
|
|
3586
3588
|
}
|
|
3587
3589
|
const sqlCount = `
|
|
3588
3590
|
SELECT COUNT(1)
|
|
3589
|
-
FROM ${this.
|
|
3591
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
3590
3592
|
${where ? ' WHERE ' : ''}
|
|
3591
3593
|
${where}
|
|
3592
3594
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -3657,7 +3659,7 @@ class StreamQuery {
|
|
|
3657
3659
|
}
|
|
3658
3660
|
}
|
|
3659
3661
|
if (sets.length > 0) {
|
|
3660
|
-
const sql = `UPDATE ${this.
|
|
3662
|
+
const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
|
|
3661
3663
|
${where ? ' WHERE ' : ''}
|
|
3662
3664
|
${where}
|
|
3663
3665
|
`;
|
|
@@ -3676,7 +3678,7 @@ class StreamQuery {
|
|
|
3676
3678
|
option ?? (option = {});
|
|
3677
3679
|
option.sync ?? (option.sync = SyncMode.Async);
|
|
3678
3680
|
const { where, params } = this._where();
|
|
3679
|
-
const sql = `DELETE FROM ${this.
|
|
3681
|
+
const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
|
|
3680
3682
|
${where ? ' WHERE ' : ''}
|
|
3681
3683
|
${where}
|
|
3682
3684
|
`;
|
|
@@ -4273,12 +4275,6 @@ __decorate([
|
|
|
4273
4275
|
__metadata("design:paramtypes", [Number, Number]),
|
|
4274
4276
|
__metadata("design:returntype", void 0)
|
|
4275
4277
|
], StreamQuery.prototype, "page", null);
|
|
4276
|
-
__decorate([
|
|
4277
|
-
IF_PROCEED(),
|
|
4278
|
-
__metadata("design:type", Function),
|
|
4279
|
-
__metadata("design:paramtypes", [String]),
|
|
4280
|
-
__metadata("design:returntype", void 0)
|
|
4281
|
-
], StreamQuery.prototype, "table", null);
|
|
4282
4278
|
__decorate([
|
|
4283
4279
|
IF_PROCEED(),
|
|
4284
4280
|
__metadata("design:type", Function),
|
package/es/sqlite.d.ts
CHANGED
|
@@ -20,11 +20,11 @@ export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface
|
|
|
20
20
|
*/
|
|
21
21
|
abstract setMod(name: string): void;
|
|
22
22
|
abstract trace: boolean;
|
|
23
|
-
execute(inData: Uint8Array): Uint8Array
|
|
24
|
-
pluck(inData: Uint8Array): Uint8Array
|
|
25
|
-
get(inData: Uint8Array): Uint8Array
|
|
26
|
-
raw(inData: Uint8Array): Uint8Array
|
|
27
|
-
query(inData: Uint8Array): Uint8Array
|
|
23
|
+
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
24
|
+
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
25
|
+
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
26
|
+
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
28
28
|
initDB(dbName: string): void;
|
|
29
29
|
export(dbName: string, exportPath: string): Promise<void>;
|
|
30
30
|
restore(dbName: string, importPath: string): void;
|
package/es/sqlite.js
CHANGED
|
@@ -5,7 +5,7 @@ export class SqliteRemoteClass {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
this.dbList = {};
|
|
7
7
|
}
|
|
8
|
-
execute(inData) {
|
|
8
|
+
async execute(inData) {
|
|
9
9
|
const [dbName, sql, params] = decode(inData);
|
|
10
10
|
logger.debug(sql, params ?? '');
|
|
11
11
|
try {
|
|
@@ -32,7 +32,7 @@ export class SqliteRemoteClass {
|
|
|
32
32
|
throw error;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
pluck(inData) {
|
|
35
|
+
async pluck(inData) {
|
|
36
36
|
const [dbName, sql, params] = decode(inData);
|
|
37
37
|
logger.debug(sql, params ?? '');
|
|
38
38
|
try {
|
|
@@ -55,7 +55,7 @@ export class SqliteRemoteClass {
|
|
|
55
55
|
throw error;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
get(inData) {
|
|
58
|
+
async get(inData) {
|
|
59
59
|
const [dbName, sql, params] = decode(inData);
|
|
60
60
|
logger.debug(sql, params ?? '');
|
|
61
61
|
try {
|
|
@@ -73,7 +73,7 @@ export class SqliteRemoteClass {
|
|
|
73
73
|
throw error;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
raw(inData) {
|
|
76
|
+
async raw(inData) {
|
|
77
77
|
const [dbName, sql, params] = decode(inData);
|
|
78
78
|
logger.debug(sql, params ?? '');
|
|
79
79
|
try {
|
|
@@ -95,7 +95,7 @@ export class SqliteRemoteClass {
|
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
query(inData) {
|
|
98
|
+
async query(inData) {
|
|
99
99
|
const [dbName, sql, params] = decode(inData);
|
|
100
100
|
logger.debug(sql, params ?? '');
|
|
101
101
|
try {
|
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
|
@@ -61,7 +61,7 @@ const _def = Symbol('def');
|
|
|
61
61
|
const _comment = Symbol('comment');
|
|
62
62
|
export const _sqlCache = Symbol('sqlMap');
|
|
63
63
|
export const _dao = Symbol('dao');
|
|
64
|
-
export const _primaryDB =
|
|
64
|
+
export const _primaryDB = '______primaryDB_______';
|
|
65
65
|
const _dbType = Symbol('dbType');
|
|
66
66
|
const _formatDialect = Symbol('FormatDialect');
|
|
67
67
|
const _sqlite_version = Symbol('sqlite_version');
|
|
@@ -551,11 +551,11 @@ export interface PageQuery<L> {
|
|
|
551
551
|
// #region 数据方言
|
|
552
552
|
/** sqlite electron服务端需要支持的接口 */
|
|
553
553
|
export interface SqliteRemoteInterface {
|
|
554
|
-
execute(inData: Uint8Array):Uint8Array
|
|
555
|
-
pluck(inData: Uint8Array):Uint8Array
|
|
556
|
-
get(inData: Uint8Array): Uint8Array
|
|
557
|
-
raw(inData: Uint8Array): Uint8Array
|
|
558
|
-
query(inData: Uint8Array): Uint8Array
|
|
554
|
+
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
555
|
+
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
556
|
+
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
557
|
+
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
558
|
+
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
559
559
|
initDB(dbName: string): void;
|
|
560
560
|
export(dbName: string, exportPath: string): Promise<void>;
|
|
561
561
|
restore(dbName: string, importPath: string): void;
|
|
@@ -1300,7 +1300,7 @@ export class SqliteRemote implements Dao {
|
|
|
1300
1300
|
restore(sync: SyncMode.Async, importPath: string): Promise<void>;
|
|
1301
1301
|
restore(sync: SyncMode, importPath: string): Promise<void> | void {
|
|
1302
1302
|
if (sync === SyncMode.Async) {
|
|
1303
|
-
return this[_daoDB]?.restore(this[_sqliteRemoteName], importPath,
|
|
1303
|
+
return this[_daoDB]?.restore(this[_sqliteRemoteName], importPath,);
|
|
1304
1304
|
};
|
|
1305
1305
|
}
|
|
1306
1306
|
}
|
|
@@ -1883,12 +1883,14 @@ function P<T extends object>(skipConn = false) {
|
|
|
1883
1883
|
option!.dao = globalThis[_dao][this[_dbType]!][dbName] as Dao;
|
|
1884
1884
|
|
|
1885
1885
|
if (this[_dbType] === DBType.Sqlite) {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
globalThis[_dao][this[_dbType]!][_primaryDB]
|
|
1886
|
+
if (!option!.dao) {
|
|
1887
|
+
const db = new Sqlite(new globalThis[_GlobalSqlOption].BetterSqlite3(dbName as any, { fileMustExist: false }));
|
|
1888
|
+
if (globalThis[_dao][this[_dbType]!][_primaryDB] === undefined) {
|
|
1889
|
+
globalThis[_dao][this[_dbType]!][_primaryDB] = db;
|
|
1890
|
+
}
|
|
1891
|
+
globalThis[_dao][this[_dbType]!][dbName] = db;
|
|
1892
|
+
option!.dao = db;
|
|
1889
1893
|
}
|
|
1890
|
-
globalThis[_dao][this[_dbType]!][dbName] = db;
|
|
1891
|
-
option!.dao = db;
|
|
1892
1894
|
|
|
1893
1895
|
Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!')
|
|
1894
1896
|
// 连接共享
|
|
@@ -1917,13 +1919,15 @@ function P<T extends object>(skipConn = false) {
|
|
|
1917
1919
|
}
|
|
1918
1920
|
}
|
|
1919
1921
|
} else if (this[_dbType] === DBType.SqliteRemote) {
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
globalThis[_dao][this[_dbType]!][_primaryDB]
|
|
1922
|
+
if (!option!.dao) {
|
|
1923
|
+
globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
1924
|
+
const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName as any);
|
|
1925
|
+
if (globalThis[_dao][this[_dbType]!][_primaryDB] === undefined) {
|
|
1926
|
+
globalThis[_dao][this[_dbType]!][_primaryDB] = db;
|
|
1927
|
+
}
|
|
1928
|
+
globalThis[_dao][this[_dbType]!][dbName] = db;
|
|
1929
|
+
option!.dao = db;
|
|
1924
1930
|
}
|
|
1925
|
-
globalThis[_dao][this[_dbType]!][dbName] = db;
|
|
1926
|
-
option!.dao = db;
|
|
1927
1931
|
|
|
1928
1932
|
Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!')
|
|
1929
1933
|
return new Promise(async (resolve, reject) => {
|
|
@@ -2393,7 +2397,7 @@ export function DeclareService(clz: any, config: ServiceOption) {
|
|
|
2393
2397
|
|
|
2394
2398
|
*/
|
|
2395
2399
|
export class SqlService<T extends object> {
|
|
2396
|
-
|
|
2400
|
+
[_tableName]?: string;
|
|
2397
2401
|
private [_className]?: string;
|
|
2398
2402
|
private [_ClassName]?: string;
|
|
2399
2403
|
private [_vueName]?: string;
|
|
@@ -3401,8 +3405,8 @@ export class SqlService<T extends object> {
|
|
|
3401
3405
|
}
|
|
3402
3406
|
}
|
|
3403
3407
|
|
|
3404
|
-
stream<L extends object = T>(
|
|
3405
|
-
return new StreamQuery<L>(
|
|
3408
|
+
stream<L extends object = T>() {
|
|
3409
|
+
return new StreamQuery<L>(this as any, this[_fields]!, this[_columns]!);
|
|
3406
3410
|
}
|
|
3407
3411
|
|
|
3408
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>>;
|
|
@@ -3851,7 +3855,6 @@ class StreamQuery<T extends object> {
|
|
|
3851
3855
|
private _param: Record<string, any> = {};
|
|
3852
3856
|
public if_proceed = true;
|
|
3853
3857
|
public if_exec = true;
|
|
3854
|
-
private _table: string;
|
|
3855
3858
|
|
|
3856
3859
|
private _distinct = false;
|
|
3857
3860
|
private _columns: string[] = [];
|
|
@@ -3868,9 +3871,8 @@ class StreamQuery<T extends object> {
|
|
|
3868
3871
|
private _service: SqlService<T>;
|
|
3869
3872
|
private [_fields]: Record<string, AField>;
|
|
3870
3873
|
private [_columns]: string[];
|
|
3871
|
-
constructor(
|
|
3874
|
+
constructor(service: SqlService<T>, __fields: Record<string, AField>, __columns: string[]) {
|
|
3872
3875
|
this._prefix = parseInt(`${Math.random() * 1000}`);
|
|
3873
|
-
this._table = table;
|
|
3874
3876
|
this._service = service;
|
|
3875
3877
|
this[_fields] = __fields;
|
|
3876
3878
|
this[_columns] = __columns;
|
|
@@ -4046,7 +4048,7 @@ class StreamQuery<T extends object> {
|
|
|
4046
4048
|
if (fn instanceof StreamQuery) {
|
|
4047
4049
|
this._andQuerys.push(fn);
|
|
4048
4050
|
} else {
|
|
4049
|
-
const stream = new StreamQuery<T>(this.
|
|
4051
|
+
const stream = new StreamQuery<T>(this._service, this[_fields], this[_columns]);
|
|
4050
4052
|
const ret = fn(stream);
|
|
4051
4053
|
if (ret !== false) { this._andQuerys.push(stream); }
|
|
4052
4054
|
}
|
|
@@ -4057,7 +4059,7 @@ class StreamQuery<T extends object> {
|
|
|
4057
4059
|
if (fn instanceof StreamQuery) {
|
|
4058
4060
|
this._andQuerys.push(fn);
|
|
4059
4061
|
} else {
|
|
4060
|
-
const stream = new StreamQuery<T>(this.
|
|
4062
|
+
const stream = new StreamQuery<T>(this._service, this[_fields], this[_columns]!);
|
|
4061
4063
|
const ret = fn(stream);
|
|
4062
4064
|
if (ret !== false) { this._orQuerys.push(stream); }
|
|
4063
4065
|
}
|
|
@@ -4081,8 +4083,6 @@ class StreamQuery<T extends object> {
|
|
|
4081
4083
|
@IF_PROCEED<T>()
|
|
4082
4084
|
page(pageNumber: number, pageSize: number) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
|
|
4083
4085
|
@IF_PROCEED<T>()
|
|
4084
|
-
table(_table: string) { this._table = _table; return this; }
|
|
4085
|
-
@IF_PROCEED<T>()
|
|
4086
4086
|
distinct(on = true) { this._distinct = on; return this; }
|
|
4087
4087
|
@IF_PROCEED<T>()
|
|
4088
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; }
|
|
@@ -4150,7 +4150,7 @@ class StreamQuery<T extends object> {
|
|
|
4150
4150
|
let sql = `
|
|
4151
4151
|
SELECT
|
|
4152
4152
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields]![String(key)]?.C3()).join(',')}
|
|
4153
|
-
FROM ${this.
|
|
4153
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
4154
4154
|
${where ? ' WHERE ' : ''}
|
|
4155
4155
|
${where}
|
|
4156
4156
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -4198,7 +4198,7 @@ class StreamQuery<T extends object> {
|
|
|
4198
4198
|
let sql = `
|
|
4199
4199
|
SELECT
|
|
4200
4200
|
${this._distinct ? 'DISTINCT' : ''} ${this._columns && this._columns.length > 0 ? this._columns.join(',') : this[_columns].map(key => this[_fields]![String(key)]?.C3()).join(',')}
|
|
4201
|
-
FROM ${this.
|
|
4201
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
4202
4202
|
${where ? ' WHERE ' : ''}
|
|
4203
4203
|
${where}
|
|
4204
4204
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -4211,7 +4211,7 @@ class StreamQuery<T extends object> {
|
|
|
4211
4211
|
}
|
|
4212
4212
|
const sqlCount = `
|
|
4213
4213
|
SELECT COUNT(1)
|
|
4214
|
-
FROM ${this.
|
|
4214
|
+
FROM ${option.tableName ?? this._service[_tableName]}
|
|
4215
4215
|
${where ? ' WHERE ' : ''}
|
|
4216
4216
|
${where}
|
|
4217
4217
|
${this._groups.length > 0 ? `GROUP BY ${this._groups.join(',')} ` : ''}
|
|
@@ -4283,7 +4283,7 @@ class StreamQuery<T extends object> {
|
|
|
4283
4283
|
}
|
|
4284
4284
|
}
|
|
4285
4285
|
if (sets.length > 0) {
|
|
4286
|
-
const sql = `UPDATE ${this.
|
|
4286
|
+
const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
|
|
4287
4287
|
${where ? ' WHERE ' : ''}
|
|
4288
4288
|
${where}
|
|
4289
4289
|
`;
|
|
@@ -4303,7 +4303,7 @@ class StreamQuery<T extends object> {
|
|
|
4303
4303
|
option ??= {};
|
|
4304
4304
|
option.sync ??= SyncMode.Async;
|
|
4305
4305
|
const { where, params } = this._where();
|
|
4306
|
-
const sql = `DELETE FROM ${this.
|
|
4306
|
+
const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
|
|
4307
4307
|
${where ? ' WHERE ' : ''}
|
|
4308
4308
|
${where}
|
|
4309
4309
|
`;
|
package/src/sqlite.ts
CHANGED
|
@@ -22,7 +22,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
|
22
22
|
*/
|
|
23
23
|
abstract setMod(name: string): void;
|
|
24
24
|
abstract trace: boolean;
|
|
25
|
-
execute(inData: Uint8Array): Uint8Array {
|
|
25
|
+
async execute(inData: Uint8Array): Promise<Uint8Array> {
|
|
26
26
|
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
27
27
|
logger.debug(sql, params ?? '');
|
|
28
28
|
try {
|
|
@@ -45,7 +45,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
|
45
45
|
throw error;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
pluck(inData: Uint8Array): Uint8Array {
|
|
48
|
+
async pluck(inData: Uint8Array): Promise<Uint8Array> {
|
|
49
49
|
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
50
50
|
logger.debug(sql, params ?? '');
|
|
51
51
|
try {
|
|
@@ -64,7 +64,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
|
64
64
|
throw error;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
get(inData: Uint8Array): Uint8Array {
|
|
67
|
+
async get(inData: Uint8Array): Promise<Uint8Array> {
|
|
68
68
|
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
69
69
|
logger.debug(sql, params ?? '');
|
|
70
70
|
try {
|
|
@@ -81,7 +81,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
|
81
81
|
throw error;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
raw(inData: Uint8Array): Uint8Array {
|
|
84
|
+
async raw(inData: Uint8Array): Promise<Uint8Array> {
|
|
85
85
|
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
86
86
|
logger.debug(sql, params ?? '');
|
|
87
87
|
try {
|
|
@@ -99,7 +99,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
|
99
99
|
throw error;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
query(inData: Uint8Array): Uint8Array {
|
|
102
|
+
async query(inData: Uint8Array): Promise<Uint8Array> {
|
|
103
103
|
const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
|
|
104
104
|
logger.debug(sql, params ?? '');
|
|
105
105
|
try {
|