baja-lite 1.0.27 → 1.0.30

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,90 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import 'reflect-metadata';
11
+ import { Boot } from './boot';
12
+ import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql';
13
+ class AmaFuck2 {
14
+ }
15
+ __decorate([
16
+ Field({ type: SqlType.int, length: 200, id: true, uuid: true }),
17
+ __metadata("design:type", Number)
18
+ ], AmaFuck2.prototype, "userid", void 0);
19
+ __decorate([
20
+ Field({ type: SqlType.varchar, length: 200, def: '333' }),
21
+ __metadata("design:type", String)
22
+ ], AmaFuck2.prototype, "username", void 0);
23
+ __decorate([
24
+ Field({ type: SqlType.varchar, length: 200 }),
25
+ __metadata("design:type", String)
26
+ ], AmaFuck2.prototype, "pwd", void 0);
27
+ let AmaService2 = class AmaService2 extends SqlService {
28
+ };
29
+ AmaService2 = __decorate([
30
+ DB({
31
+ tableName: 'nfc_user', clz: AmaFuck2, dbType: DBType.Postgresql
32
+ })
33
+ ], AmaService2);
34
+ // interface Menu {
35
+ // resourceid: string;
36
+ // resourcepid: string;
37
+ // resourcename: string;
38
+ // children: Menu[];
39
+ // }
40
+ export async function go2() {
41
+ await Boot({
42
+ Postgresql: {
43
+ database: 'nfc',
44
+ user: 'postgres',
45
+ password: 'abcd1234',
46
+ port: 5432,
47
+ host: '127.0.0.1'
48
+ },
49
+ log: 'info',
50
+ columnMode: ColumnMode.HUMP,
51
+ sqlDir: 'E:/pro/baja-lite/xml',
52
+ sqlMap: {
53
+ ['test.test']: `SELECT * FROM nfc_user {{#username}} WHERE username = :username {{/username}}`
54
+ }
55
+ });
56
+ const service = new AmaService2();
57
+ await service.transaction({
58
+ fn: async (conn) => {
59
+ const rt5 = await service.select({
60
+ sqlId: 'test.test',
61
+ params: { username: '1111' },
62
+ selectResult: SelectResult.RS_CS,
63
+ conn
64
+ });
65
+ console.log(55, rt5.length);
66
+ await service.insert({
67
+ data: {
68
+ userid: 22,
69
+ username: '222',
70
+ pwd: '333'
71
+ }
72
+ });
73
+ return 1;
74
+ }
75
+ });
76
+ // const data = await service.select<Menu>({
77
+ // sql: 'SELECT resourceid, resourcepid,resourcename FROM cp_resource ',
78
+ // params: {
79
+ // site: '1234',
80
+ // matchInfo: { reportType: 'yyyy', id: '11' }
81
+ // },
82
+ // // mapper: [
83
+ // // ['site', ['info', 'bSist'], 989],
84
+ // // ['site', ['info2', 'bSist'], 33],
85
+ // // ['site', ['Bsite'], 0]
86
+ // // ]
87
+ // });
88
+ // console.log(data);
89
+ }
90
+ go2();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.0.27",
3
+ "version": "1.0.30",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
@@ -25,23 +25,26 @@
25
25
  "scripts": {
26
26
  "dist": "node ./ci.js",
27
27
  "mysql": "bun --inspect ./src/test-mysql.ts",
28
+ "postgres": "bun --inspect ./src/test-postgresql.ts",
28
29
  "xml": "bun --inspect ./src/test-xml.ts",
29
30
  "mysql2": "node inspect ./dist/cjs/test-mysql.js",
31
+ "postgres2": "node inspect ./dist/cjs/test-postgresql.js",
30
32
  "sqlite": "node inspect ./dist/cjs/test-sqlite.js"
31
33
  },
32
34
  "dependencies": {
33
35
  "@msgpack/msgpack": "3.0.0-beta2",
34
36
  "@types/lodash.get": "4.4.9",
37
+ "@types/pg-pool": "^2.0.6",
35
38
  "@types/shelljs": "0.8.15",
36
39
  "decimal.js": "10.4.3",
37
40
  "html-parse-stringify": "3.0.1",
38
41
  "iterare": "1.2.1",
39
42
  "lodash.get": "4.4.2",
40
43
  "mustache": "4.2.0",
41
- "pino": "9.3.2",
44
+ "pino": "9.4.0",
42
45
  "pino-pretty": "11.2.2",
43
46
  "reflect-metadata": "0.2.2",
44
- "sql-formatter": "15.4.0",
47
+ "sql-formatter": "15.4.3",
45
48
  "sqlstring": "2.3.3",
46
49
  "tslib": "2.7.0"
47
50
  },
@@ -50,15 +53,17 @@
50
53
  "@types/mustache": "4.2.5",
51
54
  "@types/node": "20.14.14",
52
55
  "@types/sqlstring": "2.3.2",
53
- "@typescript-eslint/eslint-plugin": "8.3.0",
54
- "@typescript-eslint/parser": "8.3.0",
55
- "better-sqlite3": "11.2.1",
56
+ "@typescript-eslint/eslint-plugin": "8.8.1",
57
+ "@typescript-eslint/parser": "8.8.1",
58
+ "better-sqlite3": "11.3.0",
56
59
  "ioredis": "5.4.1",
57
- "mongodb": "6.8.0",
58
- "mysql2": "3.11.0",
60
+ "mongodb": "6.9.0",
61
+ "mysql2": "3.11.3",
62
+ "pg": "^8.13.0",
63
+ "pg-pool": "^3.7.0",
59
64
  "redlock": "5.0.0-beta.2",
60
65
  "shelljs": "0.8.5",
61
- "typescript": "5.5.4"
66
+ "typescript": "5.6.3"
62
67
  },
63
68
  "engines": {
64
69
  "node": ">=20"
package/src/boot.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getEnums } from './enum';
2
- import { _GlobalSqlOption, GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode } from './sql';
2
+ import { _GlobalSqlOption, GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql';
3
3
 
4
4
  export const Boot = async function (options: GlobalSqlOption) {
5
5
  globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
@@ -16,6 +16,7 @@ export const Boot = async function (options: GlobalSqlOption) {
16
16
  globalThis[_dao] = {
17
17
  [DBType.Mongo]: {},
18
18
  [DBType.Mysql]: {},
19
+ [DBType.Postgresql]: {},
19
20
  [DBType.Sqlite]: {},
20
21
  [DBType.SqliteRemote]: {},
21
22
  [DBType.Redis]: {}
@@ -32,6 +33,7 @@ export const Boot = async function (options: GlobalSqlOption) {
32
33
  decimalNumbers: true,
33
34
  supportBigNumbers: true
34
35
  }));
36
+
35
37
  } else {
36
38
  let flag = false;
37
39
  for (const [key, option] of Object.entries(options.Mysql)) {
@@ -41,6 +43,7 @@ export const Boot = async function (options: GlobalSqlOption) {
41
43
  decimalNumbers: true,
42
44
  supportBigNumbers: true
43
45
  }));
46
+
44
47
  if (flag === false) {
45
48
  globalThis[_dao][DBType.Mysql][_primaryDB] = db;
46
49
  flag = true;
@@ -129,4 +132,22 @@ export const Boot = async function (options: GlobalSqlOption) {
129
132
  });
130
133
  globalThis[_EventBus] = event;
131
134
  }
135
+ if (options.Postgresql) {
136
+ const Pool = await import('pg-pool');
137
+ if (options.Postgresql['host']) {
138
+ globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
139
+
140
+ } else {
141
+ let flag = false;
142
+ for (const [key, option] of Object.entries(options.Postgresql)) {
143
+ const db = new Postgresql(new Pool.default(option));
144
+
145
+ if (flag === false) {
146
+ globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
147
+ flag = true;
148
+ }
149
+ globalThis[_dao][DBType.Postgresql][key] = db;
150
+ }
151
+ }
152
+ }
132
153
  }