baja-lite 1.0.26 → 1.0.29
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.js +18 -0
- package/cjs/sql.d.ts +94 -29
- package/cjs/sql.js +583 -265
- package/cjs/test-postgresql.d.ts +2 -0
- package/cjs/test-postgresql.js +93 -0
- package/es/boot.js +19 -1
- package/es/sql.d.ts +94 -29
- package/es/sql.js +582 -265
- package/es/test-postgresql.d.ts +2 -0
- package/es/test-postgresql.js +90 -0
- package/package.json +13 -8
- package/src/boot.ts +22 -1
- package/src/sql.ts +624 -244
- package/src/test-postgresql.ts +79 -0
package/cjs/boot.js
CHANGED
|
@@ -41,6 +41,7 @@ const Boot = async function (options) {
|
|
|
41
41
|
globalThis[sql_1._dao] = {
|
|
42
42
|
[sql_1.DBType.Mongo]: {},
|
|
43
43
|
[sql_1.DBType.Mysql]: {},
|
|
44
|
+
[sql_1.DBType.Postgresql]: {},
|
|
44
45
|
[sql_1.DBType.Sqlite]: {},
|
|
45
46
|
[sql_1.DBType.SqliteRemote]: {},
|
|
46
47
|
[sql_1.DBType.Redis]: {}
|
|
@@ -151,5 +152,22 @@ const Boot = async function (options) {
|
|
|
151
152
|
});
|
|
152
153
|
globalThis[sql_1._EventBus] = event;
|
|
153
154
|
}
|
|
155
|
+
if (options.Postgresql) {
|
|
156
|
+
const Pool = await Promise.resolve().then(() => __importStar(require('pg-pool')));
|
|
157
|
+
if (options.Postgresql['host']) {
|
|
158
|
+
globalThis[sql_1._dao][sql_1.DBType.Postgresql][sql_1._primaryDB] = new sql_1.Postgresql(new Pool.default(options.Postgresql));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
let flag = false;
|
|
162
|
+
for (const [key, option] of Object.entries(options.Postgresql)) {
|
|
163
|
+
const db = new sql_1.Postgresql(new Pool.default(option));
|
|
164
|
+
if (flag === false) {
|
|
165
|
+
globalThis[sql_1._dao][sql_1.DBType.Postgresql][sql_1._primaryDB] = db;
|
|
166
|
+
flag = true;
|
|
167
|
+
}
|
|
168
|
+
globalThis[sql_1._dao][sql_1.DBType.Postgresql][key] = db;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
154
172
|
};
|
|
155
173
|
exports.Boot = Boot;
|
package/cjs/sql.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export declare const _sqlCache: unique symbol;
|
|
|
23
23
|
export declare const _dao: unique symbol;
|
|
24
24
|
export declare const _primaryDB = "______primaryDB_______";
|
|
25
25
|
declare const _dbType: unique symbol;
|
|
26
|
-
declare const _formatDialect: unique symbol;
|
|
27
26
|
declare const _sqlite_version: unique symbol;
|
|
28
27
|
declare const _daoConnection: unique symbol;
|
|
29
28
|
declare const _inTransaction: unique symbol;
|
|
@@ -36,14 +35,15 @@ export declare const _GlobalSqlOption: unique symbol;
|
|
|
36
35
|
export declare const _EventBus: unique symbol;
|
|
37
36
|
export declare const _path: unique symbol;
|
|
38
37
|
export declare const _fs: unique symbol;
|
|
39
|
-
export declare const logger: import("pino").Logger<never>;
|
|
38
|
+
export declare const logger: import("pino").Logger<never, boolean>;
|
|
40
39
|
export declare enum DBType {
|
|
41
40
|
Mysql = 0,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
Postgresql = 1,
|
|
42
|
+
Sqlite = 2,
|
|
43
|
+
Mongo = 3,
|
|
44
|
+
SqliteRemote = 4,
|
|
45
|
+
Redis = 5,
|
|
46
|
+
RedisLock = 6
|
|
47
47
|
}
|
|
48
48
|
export declare enum MapperIfUndefined {
|
|
49
49
|
Null = 0,
|
|
@@ -159,17 +159,7 @@ export declare enum SqlType {
|
|
|
159
159
|
mediumtext = 20,
|
|
160
160
|
longblob = 21,
|
|
161
161
|
longtext = 22,
|
|
162
|
-
|
|
163
|
-
enum = 24,
|
|
164
|
-
json = 25,
|
|
165
|
-
geometry = 26,
|
|
166
|
-
point = 27,
|
|
167
|
-
linestring = 28,
|
|
168
|
-
polygon = 29,
|
|
169
|
-
multipoint = 30,
|
|
170
|
-
multilinestring = 31,
|
|
171
|
-
multipolygon = 32,
|
|
172
|
-
geometrycollection = 33
|
|
162
|
+
json = 23
|
|
173
163
|
}
|
|
174
164
|
export declare enum ColumnMode {
|
|
175
165
|
NONE = 0,
|
|
@@ -180,6 +170,7 @@ interface MethodOption {
|
|
|
180
170
|
tableName?: string;
|
|
181
171
|
/** 数据库、连接名称,对于MYSQL、mongo,适用于多数据源,对于sqlite,适用于不同的数据库文件 */
|
|
182
172
|
dbName?: string;
|
|
173
|
+
dbType?: DBType;
|
|
183
174
|
/** 调用时,永远不需要传
|
|
184
175
|
* @deprecated
|
|
185
176
|
* */
|
|
@@ -225,7 +216,6 @@ interface ServiceOption {
|
|
|
225
216
|
}
|
|
226
217
|
/**
|
|
227
218
|
# 全局行为配置文件
|
|
228
|
-
MYSQL编码: 'utf8mb4', utf8mb4_general_ci'
|
|
229
219
|
### `sqlDir?: string;` 数据库查询语句存放目录.存放格式为 export.default 的js、ts, 存放内容满足格式:
|
|
230
220
|
|
|
231
221
|
```
|
|
@@ -250,7 +240,7 @@ export interface GlobalSqlOptionForWeb {
|
|
|
250
240
|
```
|
|
251
241
|
db: 'd:/1.db'
|
|
252
242
|
```
|
|
253
|
-
##
|
|
243
|
+
## 多数据源:传入多个连接配置
|
|
254
244
|
```
|
|
255
245
|
db: {
|
|
256
246
|
db1: 'd:/1.db',
|
|
@@ -300,6 +290,8 @@ export interface GlobalSqlOptionForWeb {
|
|
|
300
290
|
* ```
|
|
301
291
|
*/
|
|
302
292
|
columnMode?: ColumnMode;
|
|
293
|
+
/** 对于WEB模式,默认为SqliteRemote */
|
|
294
|
+
dbType?: DBType;
|
|
303
295
|
}
|
|
304
296
|
/**
|
|
305
297
|
# 全局行为配置文件
|
|
@@ -340,12 +332,70 @@ export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
|
|
|
340
332
|
```
|
|
341
333
|
*/
|
|
342
334
|
Mysql?: Record<string, Record<string, any>> | Record<string, any>;
|
|
335
|
+
/**
|
|
336
|
+
初始化postgresql链接 支持多数据源
|
|
337
|
+
## 单一数据源: 直接传入postgresql的连接配置
|
|
338
|
+
[Postgresql初始化文档](https://github.com/brianc/node-postgres/tree/master/packages/pg-pool)
|
|
339
|
+
```
|
|
340
|
+
Postgresql: {
|
|
341
|
+
database: 'postgres',
|
|
342
|
+
user: 'brianc',
|
|
343
|
+
password: 'secret!',
|
|
344
|
+
port: 5432,
|
|
345
|
+
ssl: true,
|
|
346
|
+
max: 20, // set pool max size to 20
|
|
347
|
+
idleTimeoutMillis: 1000, // close idle clients after 1 second
|
|
348
|
+
connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established
|
|
349
|
+
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
350
|
+
host?: string | undefined;
|
|
351
|
+
connectionString?: string | undefined;
|
|
352
|
+
keepAlive?: boolean | undefined;
|
|
353
|
+
stream?: () => stream.Duplex | stream.Duplex | undefined;
|
|
354
|
+
statement_timeout?: false | number | undefined;
|
|
355
|
+
query_timeout?: number | undefined;
|
|
356
|
+
keepAliveInitialDelayMillis?: number | undefined;
|
|
357
|
+
idle_in_transaction_session_timeout?: number | undefined;
|
|
358
|
+
application_name?: string | undefined;
|
|
359
|
+
types?: CustomTypesConfig | undefined;
|
|
360
|
+
options?: string | undefined;
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
## 多数据源:传入多个Postgresql的连接配置
|
|
364
|
+
```
|
|
365
|
+
Postgresql: {
|
|
366
|
+
db1: {
|
|
367
|
+
database: 'postgres',
|
|
368
|
+
user: 'brianc',
|
|
369
|
+
password: 'secret!',
|
|
370
|
+
port: 5432,
|
|
371
|
+
ssl: true,
|
|
372
|
+
max: 20, // set pool max size to 20
|
|
373
|
+
idleTimeoutMillis: 1000, // close idle clients after 1 second
|
|
374
|
+
connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established
|
|
375
|
+
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
376
|
+
},
|
|
377
|
+
db2: {
|
|
378
|
+
database: 'postgres',
|
|
379
|
+
user: 'brianc',
|
|
380
|
+
password: 'secret!',
|
|
381
|
+
port: 5432,
|
|
382
|
+
ssl: true,
|
|
383
|
+
max: 20, // set pool max size to 20
|
|
384
|
+
idleTimeoutMillis: 1000, // close idle clients after 1 second
|
|
385
|
+
connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established
|
|
386
|
+
maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)
|
|
387
|
+
},
|
|
388
|
+
...
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
*/
|
|
392
|
+
Postgresql?: Record<string, Record<string, any>> | Record<string, any>;
|
|
343
393
|
/**
|
|
344
394
|
## 单一数据源
|
|
345
395
|
```
|
|
346
396
|
Sqlite: 'd:/1.db'
|
|
347
397
|
```
|
|
348
|
-
##
|
|
398
|
+
## 多数据源:传入多个连接配置
|
|
349
399
|
```
|
|
350
400
|
Sqlite: {
|
|
351
401
|
db1: 'd:/1.db',
|
|
@@ -472,6 +522,7 @@ interface AField extends FieldOption {
|
|
|
472
522
|
C?: () => string;
|
|
473
523
|
/** 查询用:b_id bId */
|
|
474
524
|
C3: () => string;
|
|
525
|
+
[DBType.Postgresql]: () => string;
|
|
475
526
|
[DBType.Mysql]: () => string;
|
|
476
527
|
[DBType.Sqlite]: () => string;
|
|
477
528
|
[DBType.SqliteRemote]: () => string;
|
|
@@ -539,6 +590,24 @@ interface Dao {
|
|
|
539
590
|
export declare class Mysql implements Dao {
|
|
540
591
|
[_daoDB]: any;
|
|
541
592
|
constructor(pool: any);
|
|
593
|
+
keepAlive(): Promise<void>;
|
|
594
|
+
createConnection(sync: SyncMode.Sync): Connection | null;
|
|
595
|
+
createConnection(sync: SyncMode.Async): Promise<Connection | null>;
|
|
596
|
+
transaction<T = any>(sync: SyncMode.Sync, fn: (conn: Connection) => T, conn?: Connection | null): T | null;
|
|
597
|
+
transaction<T = any>(sync: SyncMode.Async, fn: (conn: Connection) => Promise<T>, conn?: Connection | null): Promise<T | null>;
|
|
598
|
+
close(sync: SyncMode.Sync): void;
|
|
599
|
+
close(sync: SyncMode.Async): Promise<void>;
|
|
600
|
+
backup(sync: SyncMode.Sync, name: string): void;
|
|
601
|
+
backup(sync: SyncMode.Async, name: string): Promise<void>;
|
|
602
|
+
remove(sync: SyncMode.Sync): void;
|
|
603
|
+
remove(sync: SyncMode.Async): Promise<void>;
|
|
604
|
+
restore(sync: SyncMode.Sync, name: string): void;
|
|
605
|
+
restore(sync: SyncMode.Async, name: string): Promise<void>;
|
|
606
|
+
}
|
|
607
|
+
export declare class Postgresql implements Dao {
|
|
608
|
+
[_daoDB]: any;
|
|
609
|
+
constructor(pool: any);
|
|
610
|
+
keepAlive(): Promise<void>;
|
|
542
611
|
createConnection(sync: SyncMode.Sync): Connection | null;
|
|
543
612
|
createConnection(sync: SyncMode.Async): Promise<Connection | null>;
|
|
544
613
|
transaction<T = any>(sync: SyncMode.Sync, fn: (conn: Connection) => T, conn?: Connection | null): T | null;
|
|
@@ -684,8 +753,7 @@ export declare const DB: (config: ServiceOption) => <C extends {
|
|
|
684
753
|
[_ClassName]: string | undefined;
|
|
685
754
|
[_vueName]: string | undefined;
|
|
686
755
|
[_daoDBName]: string | undefined;
|
|
687
|
-
[_dbType]: DBType;
|
|
688
|
-
[_formatDialect]: any;
|
|
756
|
+
[_dbType]: DBType | undefined;
|
|
689
757
|
[_sqlite_version]: string | undefined;
|
|
690
758
|
[_SqlOption]: {
|
|
691
759
|
maxDeal: number;
|
|
@@ -752,7 +820,7 @@ export declare function DeclareService(clz: any, config: ServiceOption): any;
|
|
|
752
820
|
|
|
753
821
|
*/
|
|
754
822
|
export declare class SqlService<T extends object> {
|
|
755
|
-
|
|
823
|
+
[_tableName]?: string;
|
|
756
824
|
private [_className]?;
|
|
757
825
|
private [_ClassName]?;
|
|
758
826
|
private [_vueName]?;
|
|
@@ -766,7 +834,6 @@ export declare class SqlService<T extends object> {
|
|
|
766
834
|
private [_deleteState]?;
|
|
767
835
|
private [_SqlOption]?;
|
|
768
836
|
private [_dbType]?;
|
|
769
|
-
private [_formatDialect]?;
|
|
770
837
|
private [_sqlite_version]?;
|
|
771
838
|
private [_index]?;
|
|
772
839
|
private [_def]?;
|
|
@@ -1266,7 +1333,7 @@ export declare class SqlService<T extends object> {
|
|
|
1266
1333
|
sync: SyncMode.Sync;
|
|
1267
1334
|
fn: (conn: Connection) => L;
|
|
1268
1335
|
}): L | null;
|
|
1269
|
-
stream<L extends object = T>(
|
|
1336
|
+
stream<L extends object = T>(): StreamQuery<L>;
|
|
1270
1337
|
page<L = T>(option: MethodOption & {
|
|
1271
1338
|
sync?: SyncMode.Async;
|
|
1272
1339
|
sqlId: string;
|
|
@@ -1362,7 +1429,6 @@ declare class StreamQuery<T extends object> {
|
|
|
1362
1429
|
private _param;
|
|
1363
1430
|
if_proceed: boolean;
|
|
1364
1431
|
if_exec: boolean;
|
|
1365
|
-
private _table;
|
|
1366
1432
|
private _distinct;
|
|
1367
1433
|
private _columns;
|
|
1368
1434
|
private _updates?;
|
|
@@ -1374,7 +1440,7 @@ declare class StreamQuery<T extends object> {
|
|
|
1374
1440
|
private _service;
|
|
1375
1441
|
private [_fields];
|
|
1376
1442
|
private [_columns];
|
|
1377
|
-
constructor(
|
|
1443
|
+
constructor(service: SqlService<T>, __fields: Record<string, AField>, __columns: string[]);
|
|
1378
1444
|
/** 将当前stream重置 */
|
|
1379
1445
|
reset(): this;
|
|
1380
1446
|
/** 为下次链条执行提供条件判断:非异步方法跳过,异步方法不执行并返回默认值 */
|
|
@@ -1606,7 +1672,6 @@ declare class StreamQuery<T extends object> {
|
|
|
1606
1672
|
desc2(...keys: string[]): this;
|
|
1607
1673
|
limit(startRow: number, pageSize: number): this;
|
|
1608
1674
|
page(pageNumber: number, pageSize: number): this;
|
|
1609
|
-
table(_table: string): this;
|
|
1610
1675
|
distinct(on?: boolean): this;
|
|
1611
1676
|
countDistinct(key: keyof T, countName?: string): this;
|
|
1612
1677
|
count(countName?: string): this;
|