baja-lite 1.0.33 → 1.0.34
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-remote.d.ts → boot-remote.d.ts} +1 -1
- package/{es/boot-remote.js → boot-remote.js} +2 -2
- package/{es/boot.d.ts → boot.d.ts} +1 -1
- package/{es/boot.js → boot.js} +2 -2
- package/{es/enum.js → enum.js} +1 -1
- package/{es/fn.js → fn.js} +2 -2
- package/index.d.ts +12 -0
- package/index.js +12 -0
- package/package.json +6 -8
- package/{cjs/sql.d.ts → sql.d.ts} +3 -3
- package/{es/sql.js → sql.js} +7 -7
- package/{es/sqlite.d.ts → sqlite.d.ts} +1 -1
- package/{es/sqlite.js → sqlite.js} +1 -1
- package/{es/test-mysql.js → test-mysql.js} +2 -2
- package/{es/test-postgresql.js → test-postgresql.js} +2 -2
- package/cjs/boot-remote.js +0 -49
- package/cjs/boot.d.ts +0 -2
- package/cjs/boot.js +0 -183
- package/cjs/code.js +0 -379
- package/cjs/convert-xml.js +0 -417
- package/cjs/enum.js +0 -64
- package/cjs/error.js +0 -16
- package/cjs/fn.js +0 -179
- package/cjs/index.d.ts +0 -10
- package/cjs/index.js +0 -26
- package/cjs/list.js +0 -60
- package/cjs/math.js +0 -474
- package/cjs/object.js +0 -242
- package/cjs/set-ex.js +0 -345
- package/cjs/sql.js +0 -5083
- package/cjs/sqlite.d.ts +0 -32
- package/cjs/sqlite.js +0 -169
- package/cjs/string.js +0 -119
- package/cjs/test-mysql.js +0 -138
- package/cjs/test-postgresql.js +0 -93
- package/cjs/test-sqlite.js +0 -91
- package/cjs/test-xml.js +0 -75
- package/cjs/test.js +0 -4
- package/es/boot-remote.d.ts +0 -2
- package/es/code.d.ts +0 -2
- package/es/convert-xml.d.ts +0 -10
- package/es/enum.d.ts +0 -18
- package/es/error.d.ts +0 -5
- package/es/fn.d.ts +0 -128
- package/es/index.d.ts +0 -10
- package/es/index.js +0 -10
- package/es/list.d.ts +0 -10
- package/es/math.d.ts +0 -83
- package/es/object.d.ts +0 -83
- package/es/set-ex.d.ts +0 -198
- package/es/sql.d.ts +0 -1858
- package/es/string.d.ts +0 -17
- package/es/test-mysql.d.ts +0 -2
- package/es/test-postgresql.d.ts +0 -2
- package/es/test-sqlite.d.ts +0 -1
- package/es/test-xml.d.ts +0 -1
- package/es/test.d.ts +0 -1
- package/src/boot-remote.ts +0 -46
- package/src/boot.ts +0 -153
- package/src/code.ts +0 -377
- package/src/convert-xml.ts +0 -460
- package/src/enum.ts +0 -71
- package/src/error.ts +0 -11
- package/src/fn.ts +0 -295
- package/src/index.ts +0 -10
- package/src/list.ts +0 -57
- package/src/math.ts +0 -405
- package/src/object.ts +0 -247
- package/src/set-ex.ts +0 -374
- package/src/sql.ts +0 -5281
- package/src/sqlite.ts +0 -161
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -126
- package/src/test-postgresql.ts +0 -79
- package/src/test-sqlite.ts +0 -80
- package/src/test-xml.ts +0 -70
- package/src/test.ts +0 -2
- /package/{cjs/code.d.ts → code.d.ts} +0 -0
- /package/{es/code.js → code.js} +0 -0
- /package/{cjs/convert-xml.d.ts → convert-xml.d.ts} +0 -0
- /package/{es/convert-xml.js → convert-xml.js} +0 -0
- /package/{cjs/enum.d.ts → enum.d.ts} +0 -0
- /package/{cjs/error.d.ts → error.d.ts} +0 -0
- /package/{es/error.js → error.js} +0 -0
- /package/{cjs/fn.d.ts → fn.d.ts} +0 -0
- /package/{cjs/list.d.ts → list.d.ts} +0 -0
- /package/{es/list.js → list.js} +0 -0
- /package/{cjs/math.d.ts → math.d.ts} +0 -0
- /package/{es/math.js → math.js} +0 -0
- /package/{cjs/object.d.ts → object.d.ts} +0 -0
- /package/{es/object.js → object.js} +0 -0
- /package/{cjs/set-ex.d.ts → set-ex.d.ts} +0 -0
- /package/{es/set-ex.js → set-ex.js} +0 -0
- /package/{cjs/string.d.ts → string.d.ts} +0 -0
- /package/{es/string.js → string.js} +0 -0
- /package/{cjs/test-mysql.d.ts → test-mysql.d.ts} +0 -0
- /package/{cjs/test-postgresql.d.ts → test-postgresql.d.ts} +0 -0
- /package/{cjs/test-sqlite.d.ts → test-sqlite.d.ts} +0 -0
- /package/{es/test-sqlite.js → test-sqlite.js} +0 -0
- /package/{cjs/test-xml.d.ts → test-xml.d.ts} +0 -0
- /package/{es/test-xml.js → test-xml.js} +0 -0
- /package/{cjs/test.d.ts → test.d.ts} +0 -0
- /package/{es/test.js → test.js} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GlobalSqlOptionForWeb } from './sql';
|
|
1
|
+
import { GlobalSqlOptionForWeb } from './sql.js';
|
|
2
2
|
export declare const BootRomote: (options: GlobalSqlOptionForWeb) => Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEnums } from './enum';
|
|
2
|
-
import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql';
|
|
1
|
+
import { getEnums } from './enum.js';
|
|
2
|
+
import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql.js';
|
|
3
3
|
export const BootRomote = async function (options) {
|
|
4
4
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
|
|
5
5
|
globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { GlobalSqlOption } from './sql';
|
|
1
|
+
import { GlobalSqlOption } from './sql.js';
|
|
2
2
|
export declare const Boot: (options: GlobalSqlOption) => Promise<void>;
|
package/{es/boot.js → boot.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEnums } from './enum';
|
|
2
|
-
import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql';
|
|
1
|
+
import { getEnums } from './enum.js';
|
|
2
|
+
import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql.js';
|
|
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;
|
package/{es/enum.js → enum.js}
RENAMED
package/{es/fn.js → fn.js}
RENAMED
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export * from './error.js';
|
|
3
|
+
export * from './fn.js';
|
|
4
|
+
export * from './math.js';
|
|
5
|
+
export * from './object.js';
|
|
6
|
+
export * from './set-ex.js';
|
|
7
|
+
export * from './sql.js';
|
|
8
|
+
export * from './string.js';
|
|
9
|
+
export * from './enum.js';
|
|
10
|
+
export * from './list.js';
|
|
11
|
+
export * from './boot.js';
|
|
12
|
+
export * from './boot-remote.js';
|
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
export * from './error.js';
|
|
3
|
+
export * from './fn.js';
|
|
4
|
+
export * from './math.js';
|
|
5
|
+
export * from './object.js';
|
|
6
|
+
export * from './set-ex.js';
|
|
7
|
+
export * from './sql.js';
|
|
8
|
+
export * from './string.js';
|
|
9
|
+
export * from './enum.js';
|
|
10
|
+
export * from './list.js';
|
|
11
|
+
export * from './boot.js';
|
|
12
|
+
export * from './boot-remote.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baja-lite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "some util for self",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/void-soul/util-man",
|
|
@@ -12,16 +12,14 @@
|
|
|
12
12
|
"author": "void-soul",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"types": "./
|
|
16
|
-
"import": "./
|
|
17
|
-
"require": "./cjs/index.js"
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"import": "./index.js"
|
|
18
17
|
},
|
|
19
18
|
"./*": "./*"
|
|
20
19
|
},
|
|
21
|
-
"
|
|
22
|
-
"types": "./es/index.d.ts",
|
|
20
|
+
"types": "./index.d.ts",
|
|
23
21
|
"bin": {
|
|
24
|
-
"baja": "./
|
|
22
|
+
"baja": "./code.js"
|
|
25
23
|
},
|
|
26
24
|
"scripts": {
|
|
27
25
|
"dist": "node ./ci.js",
|
|
@@ -50,7 +48,7 @@
|
|
|
50
48
|
"@types/better-sqlite3": "7.6.12",
|
|
51
49
|
"@types/lodash.get": "4.4.9",
|
|
52
50
|
"@types/mustache": "4.2.5",
|
|
53
|
-
"@types/node": "
|
|
51
|
+
"@types/node": "22.12.0",
|
|
54
52
|
"@types/pg-pool": "2.0.6",
|
|
55
53
|
"@types/shelljs": "0.8.15",
|
|
56
54
|
"@types/sqlstring": "2.3.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { XML } from './convert-xml';
|
|
2
|
-
import { ArrayList } from './list';
|
|
3
|
-
import { EnumMap } from './enum';
|
|
1
|
+
import { XML } from './convert-xml.js';
|
|
2
|
+
import { ArrayList } from './list.js';
|
|
3
|
+
import { EnumMap } from './enum.js';
|
|
4
4
|
import { ExtensionCodec } from "@msgpack/msgpack";
|
|
5
5
|
export declare const extensionCodec: ExtensionCodec<undefined>;
|
|
6
6
|
declare const _daoDBName: unique symbol;
|
package/{es/sql.js → sql.js}
RENAMED
|
@@ -9,19 +9,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
var _b, _c, _d, _e;
|
|
11
11
|
var _f, _g, _h, _j;
|
|
12
|
-
import { Throw } from './error';
|
|
12
|
+
import { Throw } from './error.js';
|
|
13
13
|
import tslib from 'tslib';
|
|
14
14
|
import iterare from 'iterare';
|
|
15
|
-
import { emptyString } from './string';
|
|
15
|
+
import { emptyString } from './string.js';
|
|
16
16
|
import pino from 'pino';
|
|
17
|
-
import { excuteSplit, ExcuteSplitMode, sleep } from './fn';
|
|
18
|
-
import { add, calc, ten2Any } from './math';
|
|
17
|
+
import { excuteSplit, ExcuteSplitMode, sleep } from './fn.js';
|
|
18
|
+
import { add, calc, ten2Any } from './math.js';
|
|
19
19
|
import mustache from 'mustache';
|
|
20
|
-
import { C2P, C2P2, P2C } from './object';
|
|
20
|
+
import { C2P, C2P2, P2C } from './object.js';
|
|
21
21
|
import { formatDialect, sqlite, mysql, postgresql } from 'sql-formatter';
|
|
22
22
|
import HTML from 'html-parse-stringify';
|
|
23
|
-
import { convert } from './convert-xml';
|
|
24
|
-
import { ArrayList } from './list';
|
|
23
|
+
import { convert } from './convert-xml.js';
|
|
24
|
+
import { ArrayList } from './list.js';
|
|
25
25
|
import LGet from 'lodash.get';
|
|
26
26
|
import { encode, decode, ExtensionCodec, DecodeError } from "@msgpack/msgpack";
|
|
27
27
|
BigInt.prototype.toJSON = function () { return this.toString(); };
|
|
@@ -8,8 +8,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import 'reflect-metadata';
|
|
11
|
-
import { Boot } from './boot';
|
|
12
|
-
import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql';
|
|
11
|
+
import { Boot } from './boot.js';
|
|
12
|
+
import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql.js';
|
|
13
13
|
class AmaFuck2 {
|
|
14
14
|
}
|
|
15
15
|
__decorate([
|
|
@@ -8,8 +8,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import 'reflect-metadata';
|
|
11
|
-
import { Boot } from './boot';
|
|
12
|
-
import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql';
|
|
11
|
+
import { Boot } from './boot.js';
|
|
12
|
+
import { SqlService, Field, DB, DBType, SqlType, ColumnMode, SelectResult, } from './sql.js';
|
|
13
13
|
class AmaFuck2 {
|
|
14
14
|
}
|
|
15
15
|
__decorate([
|
package/cjs/boot-remote.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BootRomote = void 0;
|
|
4
|
-
const enum_1 = require("./enum");
|
|
5
|
-
const sql_1 = require("./sql");
|
|
6
|
-
const BootRomote = async function (options) {
|
|
7
|
-
globalThis[sql_1._GlobalSqlOption] = Object.assign({}, sql_1._defOption, options);
|
|
8
|
-
globalThis[sql_1._Hump] = globalThis[sql_1._GlobalSqlOption].columnMode === sql_1.ColumnMode.HUMP;
|
|
9
|
-
sql_1.logger.level = options.log ?? 'info';
|
|
10
|
-
globalThis[sql_1._sqlCache] = new sql_1.SqlCache();
|
|
11
|
-
if (options.sqlMap) {
|
|
12
|
-
await globalThis[sql_1._sqlCache].init(options);
|
|
13
|
-
}
|
|
14
|
-
globalThis[sql_1._dao] = {
|
|
15
|
-
[sql_1.DBType.SqliteRemote]: {},
|
|
16
|
-
};
|
|
17
|
-
if (options.enums) {
|
|
18
|
-
globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
|
|
19
|
-
}
|
|
20
|
-
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
21
|
-
if (typeof options.SqliteRemote.db === 'string') {
|
|
22
|
-
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
23
|
-
globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = new sql_1.SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
let flag = false;
|
|
27
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
28
|
-
await options.SqliteRemote.service.initDB(fileName);
|
|
29
|
-
const db = new sql_1.SqliteRemote(options.SqliteRemote.service, fileName);
|
|
30
|
-
if (flag === false) {
|
|
31
|
-
globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = db;
|
|
32
|
-
flag = true;
|
|
33
|
-
}
|
|
34
|
-
globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][key] = db;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
exports.BootRomote = BootRomote;
|
|
40
|
-
// export const AppendRomote = async function (dbName: string) {
|
|
41
|
-
// if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
|
|
42
|
-
// globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
43
|
-
// const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
|
|
44
|
-
// if (globalThis[_dao][DBType.SqliteRemote][_primaryDB] === undefined) {
|
|
45
|
-
// globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
46
|
-
// }
|
|
47
|
-
// globalThis[_dao][DBType.SqliteRemote][dbName] = db;
|
|
48
|
-
// }
|
|
49
|
-
// }
|
package/cjs/boot.d.ts
DELETED
package/cjs/boot.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Boot = void 0;
|
|
37
|
-
const enum_1 = require("./enum");
|
|
38
|
-
const sql_1 = require("./sql");
|
|
39
|
-
const Boot = async function (options) {
|
|
40
|
-
globalThis[sql_1._GlobalSqlOption] = Object.assign({}, sql_1._defOption, options);
|
|
41
|
-
globalThis[sql_1._Hump] = globalThis[sql_1._GlobalSqlOption].columnMode === sql_1.ColumnMode.HUMP;
|
|
42
|
-
if (options.sqlDir) {
|
|
43
|
-
globalThis[sql_1._path] = await Promise.resolve().then(() => __importStar(require('path')));
|
|
44
|
-
globalThis[sql_1._fs] = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
45
|
-
}
|
|
46
|
-
sql_1.logger.level = options.log ?? 'info';
|
|
47
|
-
globalThis[sql_1._sqlCache] = new sql_1.SqlCache();
|
|
48
|
-
if (options.sqlMap || options.sqlDir) {
|
|
49
|
-
await globalThis[sql_1._sqlCache].init(options);
|
|
50
|
-
}
|
|
51
|
-
globalThis[sql_1._dao] = {
|
|
52
|
-
[sql_1.DBType.Mongo]: {},
|
|
53
|
-
[sql_1.DBType.Mysql]: {},
|
|
54
|
-
[sql_1.DBType.Postgresql]: {},
|
|
55
|
-
[sql_1.DBType.Sqlite]: {},
|
|
56
|
-
[sql_1.DBType.SqliteRemote]: {},
|
|
57
|
-
[sql_1.DBType.Redis]: {}
|
|
58
|
-
};
|
|
59
|
-
if (options.enums) {
|
|
60
|
-
globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
|
|
61
|
-
}
|
|
62
|
-
if (options.Mysql) {
|
|
63
|
-
const { createPool } = await Promise.resolve().then(() => __importStar(require('mysql2/promise')));
|
|
64
|
-
if (options.Mysql['host']) {
|
|
65
|
-
globalThis[sql_1._dao][sql_1.DBType.Mysql][sql_1._primaryDB] = new sql_1.Mysql(createPool({
|
|
66
|
-
...options.Mysql,
|
|
67
|
-
multipleStatements: true,
|
|
68
|
-
decimalNumbers: true,
|
|
69
|
-
supportBigNumbers: true
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
let flag = false;
|
|
74
|
-
for (const [key, option] of Object.entries(options.Mysql)) {
|
|
75
|
-
const db = new sql_1.Mysql(createPool({
|
|
76
|
-
...option,
|
|
77
|
-
multipleStatements: true,
|
|
78
|
-
decimalNumbers: true,
|
|
79
|
-
supportBigNumbers: true
|
|
80
|
-
}));
|
|
81
|
-
if (flag === false) {
|
|
82
|
-
globalThis[sql_1._dao][sql_1.DBType.Mysql][sql_1._primaryDB] = db;
|
|
83
|
-
flag = true;
|
|
84
|
-
}
|
|
85
|
-
globalThis[sql_1._dao][sql_1.DBType.Mysql][key] = db;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (options.Sqlite) {
|
|
90
|
-
if (typeof options.Sqlite === 'string') {
|
|
91
|
-
globalThis[sql_1._dao][sql_1.DBType.Sqlite][sql_1._primaryDB] = new sql_1.Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
let flag = false;
|
|
95
|
-
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
96
|
-
const db = new sql_1.Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
97
|
-
if (flag === false) {
|
|
98
|
-
globalThis[sql_1._dao][sql_1.DBType.Sqlite][sql_1._primaryDB] = db;
|
|
99
|
-
flag = true;
|
|
100
|
-
}
|
|
101
|
-
globalThis[sql_1._dao][sql_1.DBType.Sqlite][key] = db;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
106
|
-
if (typeof options.SqliteRemote.db === 'string') {
|
|
107
|
-
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
108
|
-
globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = new sql_1.SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
let flag = false;
|
|
112
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
113
|
-
options.SqliteRemote.service.initDB(fileName);
|
|
114
|
-
const db = new sql_1.SqliteRemote(options.SqliteRemote.service, fileName);
|
|
115
|
-
if (flag === false) {
|
|
116
|
-
globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = db;
|
|
117
|
-
flag = true;
|
|
118
|
-
}
|
|
119
|
-
globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][key] = db;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (options.Redis) {
|
|
124
|
-
const { Redis } = await Promise.resolve().then(() => __importStar(require('ioredis')));
|
|
125
|
-
if (options.Redis['host']) {
|
|
126
|
-
globalThis[sql_1._dao][sql_1.DBType.Redis][sql_1._primaryDB] = new Redis(options.Redis);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
let flag = false;
|
|
130
|
-
for (const [key, option] of Object.entries(options.Redis)) {
|
|
131
|
-
const db = new Redis(option);
|
|
132
|
-
if (flag === false) {
|
|
133
|
-
globalThis[sql_1._dao][sql_1.DBType.Redis][sql_1._primaryDB] = db;
|
|
134
|
-
flag = true;
|
|
135
|
-
}
|
|
136
|
-
globalThis[sql_1._dao][sql_1.DBType.Redis][key] = db;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const clients = Object.values(globalThis[sql_1._dao][sql_1.DBType.Redis]);
|
|
140
|
-
const Redlock = await Promise.resolve().then(() => __importStar(require('redlock')));
|
|
141
|
-
globalThis[sql_1._dao][sql_1.DBType.RedisLock] = new Redlock.default(clients, {
|
|
142
|
-
// The expected clock drift; for more details see:
|
|
143
|
-
// http://redis.io/topics/distlock
|
|
144
|
-
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
145
|
-
// The max number of times Redlock will attempt to lock a resource
|
|
146
|
-
// before erroring.
|
|
147
|
-
retryCount: 10,
|
|
148
|
-
// the time in ms between attempts
|
|
149
|
-
retryDelay: 200, // time in ms
|
|
150
|
-
// the max time in ms randomly added to retries
|
|
151
|
-
// to improve performance under high contention
|
|
152
|
-
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
153
|
-
retryJitter: 200, // time in ms
|
|
154
|
-
// The minimum remaining time on a lock before an extension is automatically
|
|
155
|
-
// attempted with the `using` API.
|
|
156
|
-
automaticExtensionThreshold: 500, // time in ms
|
|
157
|
-
});
|
|
158
|
-
const { EventEmitter } = await Promise.resolve().then(() => __importStar(require('events')));
|
|
159
|
-
const event = new EventEmitter({ captureRejections: true });
|
|
160
|
-
event.on('error', error => {
|
|
161
|
-
sql_1.logger.error('event-bus', error);
|
|
162
|
-
});
|
|
163
|
-
globalThis[sql_1._EventBus] = event;
|
|
164
|
-
}
|
|
165
|
-
if (options.Postgresql) {
|
|
166
|
-
const Pool = await Promise.resolve().then(() => __importStar(require('pg-pool')));
|
|
167
|
-
if (options.Postgresql['host']) {
|
|
168
|
-
globalThis[sql_1._dao][sql_1.DBType.Postgresql][sql_1._primaryDB] = new sql_1.Postgresql(new Pool.default(options.Postgresql));
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
let flag = false;
|
|
172
|
-
for (const [key, option] of Object.entries(options.Postgresql)) {
|
|
173
|
-
const db = new sql_1.Postgresql(new Pool.default(option));
|
|
174
|
-
if (flag === false) {
|
|
175
|
-
globalThis[sql_1._dao][sql_1.DBType.Postgresql][sql_1._primaryDB] = db;
|
|
176
|
-
flag = true;
|
|
177
|
-
}
|
|
178
|
-
globalThis[sql_1._dao][sql_1.DBType.Postgresql][key] = db;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
exports.Boot = Boot;
|