baja-lite 1.6.2 → 1.6.4
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/.eslintignore +7 -0
- package/.eslintrc.cjs +89 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +9 -0
- package/ci.js +33 -0
- package/package-cjs.json +17 -0
- package/package.json +80 -80
- package/pnpm-lock.yaml +2840 -0
- package/pnpm-workspace.yaml +2 -0
- package/{boot-remote.js → src/boot-remote.ts} +64 -63
- package/{boot.js → src/boot.ts} +170 -163
- package/{code.js → src/code.ts} +526 -517
- package/{convert-xml.js → src/convert-xml.ts} +460 -410
- package/src/error.ts +11 -0
- package/src/event.ts +34 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +11 -10
- package/src/math.ts +405 -0
- package/src/object.ts +342 -0
- package/{snowflake.js → src/snowflake.ts} +127 -108
- package/src/sql.ts +5529 -0
- package/{sqlite.js → src/sqlite.ts} +157 -156
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +148 -0
- package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
- package/{test-xml.js → src/test-xml.ts} +70 -70
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +77 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +549 -560
- package/{wx.d.ts → src/wx.ts} +3 -3
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1977 -0
- package/boot-remote.d.ts +0 -2
- package/boot.d.ts +0 -2
- package/code.d.ts +0 -2
- package/convert-xml.d.ts +0 -10
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/event.d.ts +0 -10
- package/event.js +0 -38
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -126
- package/object.js +0 -321
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -2148
- package/sql.js +0 -5372
- package/sqlite.d.ts +0 -32
- package/string.d.ts +0 -17
- package/string.js +0 -105
- package/test-mysql.d.ts +0 -2
- package/test-mysql.js +0 -114
- package/test-postgresql.d.ts +0 -2
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -52
- package/wx/mini.js +0 -112
- package/wx/organ.d.ts +0 -65
- package/wx/organ.js +0 -171
- package/wx/types.js +0 -1
- package/wx.js +0 -3
- /package/{README.md → Readme.md} +0 -0
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
import { DBType, _Hump, getEnums } from 'baja-lite-field';
|
|
2
|
-
import { ColumnMode, SqlCache, SqliteRemote, _DataConvert, _GlobalSqlOption, _dao, _defOption, _enum, _primaryDB, _sqlCache, logger } from './sql.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else {
|
|
41
|
-
let flag = false;
|
|
42
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
43
|
-
await options.SqliteRemote.service.initDB(fileName);
|
|
44
|
-
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
45
|
-
if (flag === false) {
|
|
46
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
47
|
-
flag = true;
|
|
48
|
-
}
|
|
49
|
-
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
1
|
+
import { DBType, _Hump, getEnums } from 'baja-lite-field';
|
|
2
|
+
import { ColumnMode, GlobalSqlOptionForWeb, SqlCache, SqliteRemote, _DataConvert, _GlobalSqlOption, _dao, _defOption, _enum, _primaryDB, _sqlCache, logger } from './sql.js';
|
|
3
|
+
|
|
4
|
+
export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
|
|
5
|
+
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
6
|
+
if(options.skipEmptyString !== undefined){
|
|
7
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
8
|
+
}
|
|
9
|
+
if(options.skipNull !== undefined){
|
|
10
|
+
globalThis[_GlobalSqlOption].skipNull = options.skipNull;
|
|
11
|
+
}
|
|
12
|
+
if(options.skipEmptyString !== undefined){
|
|
13
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
14
|
+
}
|
|
15
|
+
if(options.maxDeal !== undefined){
|
|
16
|
+
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
17
|
+
}
|
|
18
|
+
if(options.SqliteRemote !== undefined){
|
|
19
|
+
globalThis[_GlobalSqlOption].SqliteRemote = options.SqliteRemote;
|
|
20
|
+
}
|
|
21
|
+
globalThis[_Hump] = options.columnMode === ColumnMode.HUMP;
|
|
22
|
+
logger.level = options.log ?? 'info';
|
|
23
|
+
globalThis[_sqlCache] = new SqlCache();
|
|
24
|
+
if (options.sqlMap) {
|
|
25
|
+
await globalThis[_sqlCache].init(options);
|
|
26
|
+
}
|
|
27
|
+
globalThis[_dao] = {
|
|
28
|
+
[DBType.SqliteRemote]: {},
|
|
29
|
+
};
|
|
30
|
+
if (options.enums) {
|
|
31
|
+
globalThis[_enum] = getEnums(options.enums);
|
|
32
|
+
}
|
|
33
|
+
if (options.dataConvert) {
|
|
34
|
+
globalThis[_DataConvert] = options.dataConvert;
|
|
35
|
+
}
|
|
36
|
+
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
37
|
+
if (typeof options.SqliteRemote.db === 'string') {
|
|
38
|
+
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
39
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
40
|
+
} else {
|
|
41
|
+
let flag = false;
|
|
42
|
+
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
43
|
+
await options.SqliteRemote.service.initDB(fileName);
|
|
44
|
+
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
45
|
+
if (flag === false) {
|
|
46
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
47
|
+
flag = true;
|
|
48
|
+
}
|
|
49
|
+
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// export const AppendRomote = async function (dbName: string) {
|
|
56
|
+
// if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
|
|
57
|
+
// globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
58
|
+
// const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
|
|
59
|
+
// if (globalThis[_dao][DBType.SqliteRemote][_primaryDB] === undefined) {
|
|
60
|
+
// globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
61
|
+
// }
|
|
62
|
+
// globalThis[_dao][DBType.SqliteRemote][dbName] = db;
|
|
63
|
+
// }
|
|
64
|
+
// }
|
package/{boot.js → src/boot.ts}
RENAMED
|
@@ -1,163 +1,170 @@
|
|
|
1
|
-
import { _Hump, DBType, getEnums } from 'baja-lite-field';
|
|
2
|
-
import events from 'events';
|
|
3
|
-
import { _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
globalThis[
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[DBType.
|
|
31
|
-
[DBType.
|
|
32
|
-
[DBType.
|
|
33
|
-
[DBType.
|
|
34
|
-
[DBType.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
else {
|
|
74
|
-
let flag = false;
|
|
75
|
-
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
76
|
-
const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
77
|
-
if (!flag) {
|
|
78
|
-
globalThis[_dao][DBType.Sqlite][_primaryDB] = db;
|
|
79
|
-
flag = true;
|
|
80
|
-
}
|
|
81
|
-
globalThis[_dao][DBType.Sqlite][key] = db;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
86
|
-
if (typeof options.SqliteRemote.db === 'string') {
|
|
87
|
-
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
88
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
let flag = false;
|
|
92
|
-
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
93
|
-
options.SqliteRemote.service.initDB(fileName);
|
|
94
|
-
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
95
|
-
if (!flag) {
|
|
96
|
-
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
97
|
-
flag = true;
|
|
98
|
-
}
|
|
99
|
-
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (options.Redis) {
|
|
104
|
-
events.setMaxListeners(0);
|
|
105
|
-
const { Redis } = await import('ioredis');
|
|
106
|
-
if (options.Redis['host']) {
|
|
107
|
-
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
let flag = false;
|
|
111
|
-
for (const [key, option] of Object.entries(options.Redis)) {
|
|
112
|
-
const db = new Redis(option);
|
|
113
|
-
if (!flag) {
|
|
114
|
-
globalThis[_dao][DBType.Redis][_primaryDB] = db;
|
|
115
|
-
flag = true;
|
|
116
|
-
}
|
|
117
|
-
globalThis[_dao][DBType.Redis][key] = db;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const clients = Object.values(globalThis[_dao][DBType.Redis]);
|
|
121
|
-
const Redlock = await import('redlock');
|
|
122
|
-
globalThis[_dao][DBType.RedisLock] = new Redlock.default(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
import { _Hump, DBType, getEnums } from 'baja-lite-field';
|
|
2
|
+
import events from 'events';
|
|
3
|
+
import { _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, GlobalSqlOption, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
4
|
+
|
|
5
|
+
export const Boot = async function (options: GlobalSqlOption) {
|
|
6
|
+
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
7
|
+
if (options.skipEmptyString !== undefined) {
|
|
8
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
9
|
+
}
|
|
10
|
+
if (options.skipNull !== undefined) {
|
|
11
|
+
globalThis[_GlobalSqlOption].skipNull = options.skipNull;
|
|
12
|
+
}
|
|
13
|
+
if (options.skipEmptyString !== undefined) {
|
|
14
|
+
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
15
|
+
}
|
|
16
|
+
if (options.maxDeal !== undefined) {
|
|
17
|
+
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
18
|
+
}
|
|
19
|
+
globalThis[_Hump] = options.columnMode === ColumnMode.HUMP;
|
|
20
|
+
logger.level = options.log ?? 'info';
|
|
21
|
+
globalThis[_sqlCache] = new SqlCache();
|
|
22
|
+
if (options.sqlDir) {
|
|
23
|
+
globalThis[_path] = await import('path');
|
|
24
|
+
globalThis[_fs] = await import('fs');
|
|
25
|
+
}
|
|
26
|
+
if (options.sqlMap || options.sqlDir) {
|
|
27
|
+
await globalThis[_sqlCache].init(options);
|
|
28
|
+
}
|
|
29
|
+
globalThis[_dao] = {
|
|
30
|
+
[DBType.Mongo]: {},
|
|
31
|
+
[DBType.Mysql]: {},
|
|
32
|
+
[DBType.Postgresql]: {},
|
|
33
|
+
[DBType.Sqlite]: {},
|
|
34
|
+
[DBType.SqliteRemote]: {},
|
|
35
|
+
[DBType.Redis]: {}
|
|
36
|
+
};
|
|
37
|
+
if (options.enums) {
|
|
38
|
+
globalThis[_enum] = getEnums(options.enums);
|
|
39
|
+
}
|
|
40
|
+
if (options.dataConvert) {
|
|
41
|
+
globalThis[_DataConvert] = options.dataConvert;
|
|
42
|
+
}
|
|
43
|
+
if (options.Mysql) {
|
|
44
|
+
const { createPool } = await import('mysql2/promise');
|
|
45
|
+
if (options.Mysql['host']) {
|
|
46
|
+
globalThis[_dao][DBType.Mysql][_primaryDB] = new Mysql(createPool({
|
|
47
|
+
...options.Mysql,
|
|
48
|
+
multipleStatements: true,
|
|
49
|
+
decimalNumbers: true,
|
|
50
|
+
supportBigNumbers: true
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
let flag = false;
|
|
55
|
+
for (const [key, option] of Object.entries(options.Mysql)) {
|
|
56
|
+
const db = new Mysql(createPool({
|
|
57
|
+
...option,
|
|
58
|
+
multipleStatements: true,
|
|
59
|
+
decimalNumbers: true,
|
|
60
|
+
supportBigNumbers: true
|
|
61
|
+
}));
|
|
62
|
+
if (!flag) {
|
|
63
|
+
globalThis[_dao][DBType.Mysql][_primaryDB] = db;
|
|
64
|
+
flag = true;
|
|
65
|
+
}
|
|
66
|
+
globalThis[_dao][DBType.Mysql][key] = db;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (options.Sqlite) {
|
|
71
|
+
if (typeof options.Sqlite === 'string') {
|
|
72
|
+
globalThis[_dao][DBType.Sqlite][_primaryDB] = new Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
|
|
73
|
+
} else {
|
|
74
|
+
let flag = false;
|
|
75
|
+
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
76
|
+
const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
77
|
+
if (!flag) {
|
|
78
|
+
globalThis[_dao][DBType.Sqlite][_primaryDB] = db;
|
|
79
|
+
flag = true;
|
|
80
|
+
}
|
|
81
|
+
globalThis[_dao][DBType.Sqlite][key] = db;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
86
|
+
if (typeof options.SqliteRemote.db === 'string') {
|
|
87
|
+
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
88
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let flag = false;
|
|
92
|
+
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
93
|
+
options.SqliteRemote.service.initDB(fileName);
|
|
94
|
+
const db = new SqliteRemote(options.SqliteRemote.service, fileName);
|
|
95
|
+
if (!flag) {
|
|
96
|
+
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
|
|
97
|
+
flag = true;
|
|
98
|
+
}
|
|
99
|
+
globalThis[_dao][DBType.SqliteRemote][key] = db;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (options.Redis) {
|
|
104
|
+
events.setMaxListeners(0);
|
|
105
|
+
const { Redis } = await import('ioredis');
|
|
106
|
+
if (options.Redis['host']) {
|
|
107
|
+
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
let flag = false;
|
|
111
|
+
for (const [key, option] of Object.entries(options.Redis)) {
|
|
112
|
+
const db = new Redis(option);
|
|
113
|
+
if (!flag) {
|
|
114
|
+
globalThis[_dao][DBType.Redis][_primaryDB] = db;
|
|
115
|
+
flag = true;
|
|
116
|
+
}
|
|
117
|
+
globalThis[_dao][DBType.Redis][key] = db;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const clients = Object.values(globalThis[_dao][DBType.Redis]) as any;
|
|
121
|
+
const Redlock = await import('redlock');
|
|
122
|
+
globalThis[_dao][DBType.RedisLock] = new Redlock.default(
|
|
123
|
+
clients,
|
|
124
|
+
{
|
|
125
|
+
// The expected clock drift; for more details see:
|
|
126
|
+
// http://redis.io/topics/distlock
|
|
127
|
+
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
128
|
+
|
|
129
|
+
// The max number of times Redlock will attempt to lock a resource
|
|
130
|
+
// before erroring.
|
|
131
|
+
retryCount: 10,
|
|
132
|
+
|
|
133
|
+
// the time in ms between attempts
|
|
134
|
+
retryDelay: 200, // time in ms
|
|
135
|
+
|
|
136
|
+
// the max time in ms randomly added to retries
|
|
137
|
+
// to improve performance under high contention
|
|
138
|
+
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
139
|
+
retryJitter: 200, // time in ms
|
|
140
|
+
|
|
141
|
+
// The minimum remaining time on a lock before an extension is automatically
|
|
142
|
+
// attempted with the `using` API.
|
|
143
|
+
automaticExtensionThreshold: 500, // time in ms
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
const { EventEmitter } = await import('events');
|
|
147
|
+
const event = new EventEmitter({ captureRejections: true });
|
|
148
|
+
event.on('error', error => {
|
|
149
|
+
logger.error('event-bus', error);
|
|
150
|
+
});
|
|
151
|
+
globalThis[_EventBus] = event;
|
|
152
|
+
}
|
|
153
|
+
if (options.Postgresql) {
|
|
154
|
+
const Pool = await import('pg-pool');
|
|
155
|
+
if (options.Postgresql['host']) {
|
|
156
|
+
globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
let flag = false;
|
|
160
|
+
for (const [key, option] of Object.entries(options.Postgresql)) {
|
|
161
|
+
const db = new Postgresql(new Pool.default(option));
|
|
162
|
+
if (!flag) {
|
|
163
|
+
globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
|
|
164
|
+
flag = true;
|
|
165
|
+
}
|
|
166
|
+
globalThis[_dao][DBType.Postgresql][key] = db;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|