baja-lite 1.0.27 → 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.
@@ -0,0 +1,2 @@
1
+ import 'reflect-metadata';
2
+ export declare function go2(): Promise<void>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.go2 = go2;
13
+ require("reflect-metadata");
14
+ const boot_1 = require("./boot");
15
+ const sql_1 = require("./sql");
16
+ class AmaFuck2 {
17
+ }
18
+ __decorate([
19
+ (0, sql_1.Field)({ type: sql_1.SqlType.int, length: 200, id: true, uuid: true }),
20
+ __metadata("design:type", Number)
21
+ ], AmaFuck2.prototype, "userid", void 0);
22
+ __decorate([
23
+ (0, sql_1.Field)({ type: sql_1.SqlType.varchar, length: 200, def: '333' }),
24
+ __metadata("design:type", String)
25
+ ], AmaFuck2.prototype, "username", void 0);
26
+ __decorate([
27
+ (0, sql_1.Field)({ type: sql_1.SqlType.varchar, length: 200 }),
28
+ __metadata("design:type", String)
29
+ ], AmaFuck2.prototype, "pwd", void 0);
30
+ let AmaService2 = class AmaService2 extends sql_1.SqlService {
31
+ };
32
+ AmaService2 = __decorate([
33
+ (0, sql_1.DB)({
34
+ tableName: 'nfc_user', clz: AmaFuck2, dbType: sql_1.DBType.Postgresql
35
+ })
36
+ ], AmaService2);
37
+ // interface Menu {
38
+ // resourceid: string;
39
+ // resourcepid: string;
40
+ // resourcename: string;
41
+ // children: Menu[];
42
+ // }
43
+ async function go2() {
44
+ await (0, boot_1.Boot)({
45
+ Postgresql: {
46
+ database: 'nfc',
47
+ user: 'postgres',
48
+ password: 'abcd1234',
49
+ port: 5432,
50
+ host: '127.0.0.1'
51
+ },
52
+ log: 'info',
53
+ columnMode: sql_1.ColumnMode.HUMP,
54
+ sqlDir: 'E:/pro/baja-lite/xml',
55
+ sqlMap: {
56
+ ['test.test']: `SELECT * FROM nfc_user {{#username}} WHERE username = :username {{/username}}`
57
+ }
58
+ });
59
+ const service = new AmaService2();
60
+ await service.transaction({
61
+ fn: async (conn) => {
62
+ const rt5 = await service.select({
63
+ sqlId: 'test.test',
64
+ params: { username: '1111' },
65
+ selectResult: sql_1.SelectResult.RS_CS,
66
+ conn
67
+ });
68
+ console.log(55, rt5.length);
69
+ await service.insert({
70
+ data: {
71
+ userid: 22,
72
+ username: '222',
73
+ pwd: '333'
74
+ }
75
+ });
76
+ return 1;
77
+ }
78
+ });
79
+ // const data = await service.select<Menu>({
80
+ // sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
81
+ // params: {
82
+ // site: '1234',
83
+ // matchInfo: { reportType: 'yyyy', id: '11' }
84
+ // },
85
+ // // mapper: [
86
+ // // ['site', ['info', 'bSist'], 989],
87
+ // // ['site', ['info2', 'bSist'], 33],
88
+ // // ['site', ['Bsite'], 0]
89
+ // // ]
90
+ // });
91
+ // console.log(data);
92
+ }
93
+ go2();
package/es/boot.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getEnums } from './enum';
2
- import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode } from './sql';
2
+ import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql';
3
3
  export const Boot = async function (options) {
4
4
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
5
5
  globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
@@ -15,6 +15,7 @@ export const Boot = async function (options) {
15
15
  globalThis[_dao] = {
16
16
  [DBType.Mongo]: {},
17
17
  [DBType.Mysql]: {},
18
+ [DBType.Postgresql]: {},
18
19
  [DBType.Sqlite]: {},
19
20
  [DBType.SqliteRemote]: {},
20
21
  [DBType.Redis]: {}
@@ -125,4 +126,21 @@ export const Boot = async function (options) {
125
126
  });
126
127
  globalThis[_EventBus] = event;
127
128
  }
129
+ if (options.Postgresql) {
130
+ const Pool = await import('pg-pool');
131
+ if (options.Postgresql['host']) {
132
+ globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
133
+ }
134
+ else {
135
+ let flag = false;
136
+ for (const [key, option] of Object.entries(options.Postgresql)) {
137
+ const db = new Postgresql(new Pool.default(option));
138
+ if (flag === false) {
139
+ globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
140
+ flag = true;
141
+ }
142
+ globalThis[_dao][DBType.Postgresql][key] = db;
143
+ }
144
+ }
145
+ }
128
146
  };
package/es/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
- Sqlite = 1,
43
- Mongo = 2,
44
- SqliteRemote = 3,
45
- Redis = 4,
46
- RedisLock = 5
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
- set = 23,
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
- ## 多数据源:传入多个Mysql2的连接配置
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
- ## 多数据源:传入多个Mysql2的连接配置
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;
@@ -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]?;