baja-lite 1.6.7 → 1.7.0
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/boot-remote.js +8 -2
- package/boot.js +9 -3
- package/package.json +1 -1
- package/sql.d.ts +48 -3
- package/sql.js +177 -145
- package/sqlite.js +18 -20
package/boot-remote.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DBType, _Hump, getEnums } from 'baja-lite-field';
|
|
2
|
-
import { ColumnMode, SqlCache, SqliteRemote, _Context, _DataConvert, _GlobalSqlOption, _dao, _defOption, _enum, _primaryDB, _sqlCache
|
|
2
|
+
import { ColumnMode, PrinterLogger, SqlCache, SqliteRemote, _Context, _DataConvert, _GlobalSqlOption, _LoggerService, _dao, _defOption, _enum, _primaryDB, _sqlCache } from './sql.js';
|
|
3
3
|
export const BootRomote = async function (options) {
|
|
4
4
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
5
5
|
if (options.skipEmptyString !== undefined) {
|
|
@@ -17,8 +17,14 @@ export const BootRomote = async function (options) {
|
|
|
17
17
|
if (options.SqliteRemote !== undefined) {
|
|
18
18
|
globalThis[_GlobalSqlOption].SqliteRemote = options.SqliteRemote;
|
|
19
19
|
}
|
|
20
|
+
if (options.logger) {
|
|
21
|
+
globalThis[_LoggerService] = options.logger;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
globalThis[_LoggerService] = new PrinterLogger();
|
|
25
|
+
}
|
|
26
|
+
globalThis[_LoggerService].setLogLevels(options.log ? (options.log instanceof Array ? options.log : [options.log]) : ['info']);
|
|
20
27
|
globalThis[_Hump] = options.columnMode === ColumnMode.HUMP;
|
|
21
|
-
logger.level = options.log ?? 'info';
|
|
22
28
|
globalThis[_sqlCache] = new SqlCache();
|
|
23
29
|
if (options.sqlMap) {
|
|
24
30
|
await globalThis[_sqlCache].init(options);
|
package/boot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _Hump, DBType, getEnums } from 'baja-lite-field';
|
|
2
2
|
import events from 'events';
|
|
3
|
-
import { _Context, _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode,
|
|
3
|
+
import { _Context, _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _LoggerService, _path, _primaryDB, _sqlCache, ColumnMode, Mysql, Postgresql, PrinterLogger, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
4
4
|
export const Boot = async function (options) {
|
|
5
5
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
6
6
|
if (options.skipEmptyString !== undefined) {
|
|
@@ -15,8 +15,14 @@ export const Boot = async function (options) {
|
|
|
15
15
|
if (options.maxDeal !== undefined) {
|
|
16
16
|
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
17
17
|
}
|
|
18
|
+
if (options.logger) {
|
|
19
|
+
globalThis[_LoggerService] = options.logger;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
globalThis[_LoggerService] = new PrinterLogger();
|
|
23
|
+
}
|
|
24
|
+
globalThis[_LoggerService].setLogLevels(options.log ? (options.log instanceof Array ? options.log : [options.log]) : ['info']);
|
|
18
25
|
globalThis[_Hump] = options.columnMode === ColumnMode.HUMP;
|
|
19
|
-
logger.level = options.log ?? 'info';
|
|
20
26
|
globalThis[_sqlCache] = new SqlCache();
|
|
21
27
|
if (options.sqlDir) {
|
|
22
28
|
globalThis[_path] = await import('path');
|
|
@@ -142,7 +148,7 @@ export const Boot = async function (options) {
|
|
|
142
148
|
const { EventEmitter } = await import('events');
|
|
143
149
|
const event = new EventEmitter({ captureRejections: true });
|
|
144
150
|
event.on('error', error => {
|
|
145
|
-
|
|
151
|
+
globalThis[_LoggerService].error('event-bus', error);
|
|
146
152
|
});
|
|
147
153
|
globalThis[_EventBus] = event;
|
|
148
154
|
}
|
package/package.json
CHANGED
package/sql.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ExtensionCodec } from "@msgpack/msgpack";
|
|
2
2
|
import { _columns, _columnsNoId, _def, _deleteState, _fields, _ids, _index, _logicIds, _stateFileName, AField, DBType, EnumMap, FieldOption } from 'baja-lite-field';
|
|
3
|
-
import pino from 'pino';
|
|
4
3
|
import { XML } from './convert-xml.js';
|
|
5
4
|
export declare const extensionCodec: ExtensionCodec<undefined>;
|
|
6
5
|
declare const _daoDBName: unique symbol;
|
|
@@ -25,9 +24,9 @@ export declare const _Context: unique symbol;
|
|
|
25
24
|
export declare const _enum: unique symbol;
|
|
26
25
|
export declare const _GlobalSqlOption: unique symbol;
|
|
27
26
|
export declare const _EventBus: unique symbol;
|
|
27
|
+
export declare const _LoggerService: unique symbol;
|
|
28
28
|
export declare const _path: unique symbol;
|
|
29
29
|
export declare const _fs: unique symbol;
|
|
30
|
-
export declare const logger: pino.Logger<never, boolean>;
|
|
31
30
|
export declare enum MapperIfUndefined {
|
|
32
31
|
Null = 0,
|
|
33
32
|
Skip = 1,
|
|
@@ -209,7 +208,7 @@ export interface GlobalSqlOptionForWeb {
|
|
|
209
208
|
service: SqliteRemoteInterface;
|
|
210
209
|
};
|
|
211
210
|
/** 日志等级 */
|
|
212
|
-
log?:
|
|
211
|
+
log?: LogLevel[] | LogLevel;
|
|
213
212
|
/**
|
|
214
213
|
作用与sqlDir类似,不同在于sqlMap`不需要`目录,而是直接指定一个sqlModel对象,对象的格式和sqlDir的文件内容一样。
|
|
215
214
|
** 适用于简单使用
|
|
@@ -260,6 +259,8 @@ export interface GlobalSqlOptionForWeb {
|
|
|
260
259
|
dataConvert?: Record<string, (data: any) => any>;
|
|
261
260
|
/** 公开上下文 */
|
|
262
261
|
ctx?: any;
|
|
262
|
+
/** 日志服务 */
|
|
263
|
+
logger?: LoggerService;
|
|
263
264
|
}
|
|
264
265
|
/**
|
|
265
266
|
# 全局行为配置文件
|
|
@@ -2148,4 +2149,48 @@ export declare function MethodCache<T = any>(config: {
|
|
|
2148
2149
|
/** 随着当前用户sesion的清空而一起清空 */
|
|
2149
2150
|
clearWithSession?: boolean;
|
|
2150
2151
|
}): (target: T, _propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
2152
|
+
export declare const LOG_LEVELS: ["verbose", "debug", "info", "warn", "error", "fatal"];
|
|
2153
|
+
export type LogLevel = (typeof LOG_LEVELS)[number];
|
|
2154
|
+
export interface LoggerService {
|
|
2155
|
+
/**
|
|
2156
|
+
* Write a 'log' level log.
|
|
2157
|
+
*/
|
|
2158
|
+
log(message: any, ...optionalParams: any[]): any;
|
|
2159
|
+
/**
|
|
2160
|
+
* Write an 'error' level log.
|
|
2161
|
+
*/
|
|
2162
|
+
error(message: any, ...optionalParams: any[]): any;
|
|
2163
|
+
/**
|
|
2164
|
+
* Write a 'warn' level log.
|
|
2165
|
+
*/
|
|
2166
|
+
warn(message: any, ...optionalParams: any[]): any;
|
|
2167
|
+
/**
|
|
2168
|
+
* Write a 'debug' level log.
|
|
2169
|
+
*/
|
|
2170
|
+
debug?(message: any, ...optionalParams: any[]): any;
|
|
2171
|
+
/**
|
|
2172
|
+
* Write a 'verbose' level log.
|
|
2173
|
+
*/
|
|
2174
|
+
verbose?(message: any, ...optionalParams: any[]): any;
|
|
2175
|
+
/**
|
|
2176
|
+
* Write a 'fatal' level log.
|
|
2177
|
+
*/
|
|
2178
|
+
fatal?(message: any, ...optionalParams: any[]): any;
|
|
2179
|
+
/**
|
|
2180
|
+
* Set log levels.
|
|
2181
|
+
* @param levels log levels
|
|
2182
|
+
*/
|
|
2183
|
+
setLogLevels(levels: LogLevel[]): any;
|
|
2184
|
+
}
|
|
2185
|
+
export declare class PrinterLogger implements LoggerService {
|
|
2186
|
+
private logger;
|
|
2187
|
+
constructor();
|
|
2188
|
+
log(message: any, ...optionalParams: any[]): void;
|
|
2189
|
+
fatal(message: any, ...optionalParams: any[]): void;
|
|
2190
|
+
error(message: any, ...optionalParams: any[]): void;
|
|
2191
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
2192
|
+
debug?(message: any, ...optionalParams: any[]): void;
|
|
2193
|
+
verbose?(message: any, ...optionalParams: any[]): void;
|
|
2194
|
+
setLogLevels(levels: LogLevel[]): void;
|
|
2195
|
+
}
|
|
2151
2196
|
export {};
|
package/sql.js
CHANGED
|
@@ -76,14 +76,15 @@ const _resultMap_SQLID = Symbol('resultMap_SQLID');
|
|
|
76
76
|
export const _enum = Symbol('_enum');
|
|
77
77
|
export const _GlobalSqlOption = Symbol('GlobalSqlOption');
|
|
78
78
|
export const _EventBus = Symbol('EventBus');
|
|
79
|
+
export const _LoggerService = Symbol('LoggerService');
|
|
79
80
|
export const _path = Symbol('path');
|
|
80
81
|
export const _fs = Symbol('fs');
|
|
81
|
-
export const logger = pino({
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
82
|
+
// export const logger = pino({
|
|
83
|
+
// name: 'sql',
|
|
84
|
+
// transport: {
|
|
85
|
+
// target: 'pino-pretty'
|
|
86
|
+
// }
|
|
87
|
+
// });
|
|
87
88
|
// export const logger =
|
|
88
89
|
// process.env['NODE_ENV'] !== 'production' ?
|
|
89
90
|
// pino({
|
|
@@ -220,30 +221,30 @@ class MysqlConnection {
|
|
|
220
221
|
this[_daoConnection] = conn;
|
|
221
222
|
}
|
|
222
223
|
execute(sync, sql, params) {
|
|
223
|
-
|
|
224
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
224
225
|
if (!sql) {
|
|
225
226
|
return { affectedRows: 0, insertId: 0n };
|
|
226
227
|
}
|
|
227
228
|
;
|
|
228
229
|
if (sync === SyncMode.Sync) {
|
|
229
|
-
|
|
230
|
+
globalThis[_LoggerService].warn('MYSQL not suppouted sync mode');
|
|
230
231
|
return { affectedRows: 0, insertId: 0n };
|
|
231
232
|
}
|
|
232
233
|
;
|
|
233
234
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
234
|
-
|
|
235
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
235
236
|
}
|
|
236
237
|
return new Promise(async (resolve, reject) => {
|
|
237
238
|
try {
|
|
238
239
|
const [_result] = await this[_daoConnection].execute(sql, params);
|
|
239
240
|
const result = _result;
|
|
240
241
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
241
|
-
|
|
242
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
242
243
|
}
|
|
243
244
|
resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
|
|
244
245
|
}
|
|
245
246
|
catch (error) {
|
|
246
|
-
|
|
247
|
+
globalThis[_LoggerService].error(`
|
|
247
248
|
error: ${error},
|
|
248
249
|
sql: ${sql},
|
|
249
250
|
params: ${params}
|
|
@@ -253,18 +254,18 @@ class MysqlConnection {
|
|
|
253
254
|
});
|
|
254
255
|
}
|
|
255
256
|
pluck(sync, sql, params) {
|
|
256
|
-
|
|
257
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
257
258
|
if (!sql) {
|
|
258
259
|
return null;
|
|
259
260
|
}
|
|
260
261
|
;
|
|
261
262
|
if (sync === SyncMode.Sync) {
|
|
262
|
-
|
|
263
|
+
globalThis[_LoggerService].warn('MYSQL not suppouted sync mode');
|
|
263
264
|
return null;
|
|
264
265
|
}
|
|
265
266
|
;
|
|
266
267
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
267
|
-
|
|
268
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
268
269
|
}
|
|
269
270
|
return new Promise(async (resolve, reject) => {
|
|
270
271
|
try {
|
|
@@ -279,7 +280,7 @@ class MysqlConnection {
|
|
|
279
280
|
resolve(null);
|
|
280
281
|
}
|
|
281
282
|
catch (error) {
|
|
282
|
-
|
|
283
|
+
globalThis[_LoggerService].error(`
|
|
283
284
|
error: ${error},
|
|
284
285
|
sql: ${sql},
|
|
285
286
|
params: ${params}
|
|
@@ -289,31 +290,31 @@ class MysqlConnection {
|
|
|
289
290
|
});
|
|
290
291
|
}
|
|
291
292
|
get(sync, sql, params) {
|
|
292
|
-
|
|
293
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
293
294
|
if (!sql) {
|
|
294
295
|
return null;
|
|
295
296
|
}
|
|
296
297
|
;
|
|
297
298
|
if (sync === SyncMode.Sync) {
|
|
298
|
-
|
|
299
|
+
globalThis[_LoggerService].warn('MYSQL not suppouted sync mode');
|
|
299
300
|
return null;
|
|
300
301
|
}
|
|
301
302
|
;
|
|
302
303
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
303
|
-
|
|
304
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
304
305
|
}
|
|
305
306
|
return new Promise(async (resolve, reject) => {
|
|
306
307
|
try {
|
|
307
308
|
const [result] = await this[_daoConnection].query(sql, params);
|
|
308
309
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
309
|
-
|
|
310
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
310
311
|
}
|
|
311
312
|
if (result && result[0])
|
|
312
313
|
resolve(result[0]);
|
|
313
314
|
resolve(null);
|
|
314
315
|
}
|
|
315
316
|
catch (error) {
|
|
316
|
-
|
|
317
|
+
globalThis[_LoggerService].error(`
|
|
317
318
|
error: ${error},
|
|
318
319
|
sql: ${sql},
|
|
319
320
|
params: ${params}
|
|
@@ -323,31 +324,31 @@ class MysqlConnection {
|
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
raw(sync, sql, params) {
|
|
326
|
-
|
|
327
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
327
328
|
if (!sql) {
|
|
328
329
|
return [];
|
|
329
330
|
}
|
|
330
331
|
;
|
|
331
332
|
if (sync === SyncMode.Sync) {
|
|
332
|
-
|
|
333
|
+
globalThis[_LoggerService].warn('MYSQL not suppouted sync mode');
|
|
333
334
|
return [];
|
|
334
335
|
}
|
|
335
336
|
;
|
|
336
337
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
337
|
-
|
|
338
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
338
339
|
}
|
|
339
340
|
return new Promise(async (resolve, reject) => {
|
|
340
341
|
try {
|
|
341
342
|
const [result] = await this[_daoConnection].query(sql, params);
|
|
342
343
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
343
|
-
|
|
344
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
344
345
|
}
|
|
345
346
|
if (result)
|
|
346
347
|
resolve(result.map((i) => Object.values(i)[0]));
|
|
347
348
|
resolve([]);
|
|
348
349
|
}
|
|
349
350
|
catch (error) {
|
|
350
|
-
|
|
351
|
+
globalThis[_LoggerService].error(`
|
|
351
352
|
error: ${error},
|
|
352
353
|
sql: ${sql},
|
|
353
354
|
params: ${params}
|
|
@@ -357,29 +358,29 @@ class MysqlConnection {
|
|
|
357
358
|
});
|
|
358
359
|
}
|
|
359
360
|
query(sync, sql, params) {
|
|
360
|
-
|
|
361
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
361
362
|
if (!sql) {
|
|
362
363
|
return [];
|
|
363
364
|
}
|
|
364
365
|
;
|
|
365
366
|
if (sync === SyncMode.Sync) {
|
|
366
|
-
|
|
367
|
+
globalThis[_LoggerService].warn('MYSQL not suppouted sync mode');
|
|
367
368
|
return [];
|
|
368
369
|
}
|
|
369
370
|
;
|
|
370
371
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
371
|
-
|
|
372
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
372
373
|
}
|
|
373
374
|
return new Promise(async (resolve, reject) => {
|
|
374
375
|
try {
|
|
375
376
|
const [result] = await this[_daoConnection].query(sql, params);
|
|
376
377
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
377
|
-
|
|
378
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
378
379
|
}
|
|
379
380
|
resolve(result);
|
|
380
381
|
}
|
|
381
382
|
catch (error) {
|
|
382
|
-
|
|
383
|
+
globalThis[_LoggerService].error(`
|
|
383
384
|
error: ${error},
|
|
384
385
|
sql: ${sql},
|
|
385
386
|
params: ${params}
|
|
@@ -411,14 +412,14 @@ export class Mysql {
|
|
|
411
412
|
}
|
|
412
413
|
createConnection(sync) {
|
|
413
414
|
if (sync === SyncMode.Sync) {
|
|
414
|
-
|
|
415
|
+
globalThis[_LoggerService].error('MYSQL not suppouted sync mode');
|
|
415
416
|
return null;
|
|
416
417
|
}
|
|
417
418
|
;
|
|
418
419
|
return new Promise(async (resolve, reject) => {
|
|
419
420
|
try {
|
|
420
421
|
const connection = await this[_daoDB].getConnection();
|
|
421
|
-
|
|
422
|
+
globalThis[_LoggerService].debug?.('create new connection!');
|
|
422
423
|
resolve(new MysqlConnection(connection));
|
|
423
424
|
}
|
|
424
425
|
catch (error) {
|
|
@@ -428,7 +429,7 @@ export class Mysql {
|
|
|
428
429
|
}
|
|
429
430
|
transaction(sync, fn, conn) {
|
|
430
431
|
if (sync === SyncMode.Sync) {
|
|
431
|
-
|
|
432
|
+
globalThis[_LoggerService].warn('MYSQL not suppouted sync mode');
|
|
432
433
|
return null;
|
|
433
434
|
}
|
|
434
435
|
;
|
|
@@ -441,27 +442,27 @@ export class Mysql {
|
|
|
441
442
|
}
|
|
442
443
|
if (conn?.[_inTransaction] !== true) {
|
|
443
444
|
needCommit = true;
|
|
444
|
-
|
|
445
|
+
globalThis[_LoggerService].debug?.('beginTransaction begin!');
|
|
445
446
|
await conn[_daoConnection].beginTransaction();
|
|
446
|
-
|
|
447
|
+
globalThis[_LoggerService].debug?.('beginTransaction end!');
|
|
447
448
|
}
|
|
448
449
|
conn[_inTransaction] = true;
|
|
449
450
|
try {
|
|
450
451
|
const result = await fn(conn);
|
|
451
452
|
if (needCommit) {
|
|
452
|
-
|
|
453
|
+
globalThis[_LoggerService].debug?.('commit begin!');
|
|
453
454
|
await conn[_daoConnection].commit();
|
|
454
455
|
conn[_inTransaction] = false;
|
|
455
|
-
|
|
456
|
+
globalThis[_LoggerService].debug?.('commit end!');
|
|
456
457
|
}
|
|
457
458
|
resolve(result);
|
|
458
459
|
}
|
|
459
460
|
catch (error) {
|
|
460
|
-
|
|
461
|
+
globalThis[_LoggerService].debug?.('rollback begin!');
|
|
461
462
|
await conn[_daoConnection].rollback();
|
|
462
|
-
|
|
463
|
+
globalThis[_LoggerService].debug?.('rollback end!');
|
|
463
464
|
conn[_inTransaction] = false;
|
|
464
|
-
|
|
465
|
+
globalThis[_LoggerService].error(error);
|
|
465
466
|
reject(error);
|
|
466
467
|
}
|
|
467
468
|
finally {
|
|
@@ -470,9 +471,9 @@ export class Mysql {
|
|
|
470
471
|
conn[_inTransaction] = false;
|
|
471
472
|
}
|
|
472
473
|
if (newConn) {
|
|
473
|
-
|
|
474
|
+
globalThis[_LoggerService].debug?.('release begin!');
|
|
474
475
|
conn[_daoConnection].release();
|
|
475
|
-
|
|
476
|
+
globalThis[_LoggerService].debug?.('release end!');
|
|
476
477
|
}
|
|
477
478
|
}
|
|
478
479
|
catch (error) {
|
|
@@ -499,18 +500,18 @@ class PostgresqlConnection {
|
|
|
499
500
|
this[_daoConnection] = conn;
|
|
500
501
|
}
|
|
501
502
|
execute(sync, sql, params) {
|
|
502
|
-
|
|
503
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
503
504
|
if (!sql) {
|
|
504
505
|
return { affectedRows: 0, insertId: 0n };
|
|
505
506
|
}
|
|
506
507
|
;
|
|
507
508
|
if (sync === SyncMode.Sync) {
|
|
508
|
-
|
|
509
|
+
globalThis[_LoggerService].warn('Postgresql not suppouted sync mode');
|
|
509
510
|
return { affectedRows: 0, insertId: 0n };
|
|
510
511
|
}
|
|
511
512
|
;
|
|
512
513
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
513
|
-
|
|
514
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
514
515
|
}
|
|
515
516
|
return new Promise(async (resolve, reject) => {
|
|
516
517
|
try {
|
|
@@ -521,12 +522,12 @@ class PostgresqlConnection {
|
|
|
521
522
|
});
|
|
522
523
|
const result = rowCount;
|
|
523
524
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
524
|
-
|
|
525
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
525
526
|
}
|
|
526
527
|
resolve({ affectedRows: result.affectedRows, insertId: result.insertId });
|
|
527
528
|
}
|
|
528
529
|
catch (error) {
|
|
529
|
-
|
|
530
|
+
globalThis[_LoggerService].error(`
|
|
530
531
|
error: ${error},
|
|
531
532
|
sql: ${sql},
|
|
532
533
|
params: ${params}
|
|
@@ -536,18 +537,18 @@ class PostgresqlConnection {
|
|
|
536
537
|
});
|
|
537
538
|
}
|
|
538
539
|
pluck(sync, sql, params) {
|
|
539
|
-
|
|
540
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
540
541
|
if (!sql) {
|
|
541
542
|
return null;
|
|
542
543
|
}
|
|
543
544
|
;
|
|
544
545
|
if (sync === SyncMode.Sync) {
|
|
545
|
-
|
|
546
|
+
globalThis[_LoggerService].warn('Postgresql not suppouted sync mode');
|
|
546
547
|
return null;
|
|
547
548
|
}
|
|
548
549
|
;
|
|
549
550
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
550
|
-
|
|
551
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
551
552
|
}
|
|
552
553
|
return new Promise(async (resolve, reject) => {
|
|
553
554
|
try {
|
|
@@ -566,7 +567,7 @@ class PostgresqlConnection {
|
|
|
566
567
|
resolve(null);
|
|
567
568
|
}
|
|
568
569
|
catch (error) {
|
|
569
|
-
|
|
570
|
+
globalThis[_LoggerService].error(`
|
|
570
571
|
error: ${error},
|
|
571
572
|
sql: ${sql},
|
|
572
573
|
params: ${params}
|
|
@@ -576,18 +577,18 @@ class PostgresqlConnection {
|
|
|
576
577
|
});
|
|
577
578
|
}
|
|
578
579
|
get(sync, sql, params) {
|
|
579
|
-
|
|
580
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
580
581
|
if (!sql) {
|
|
581
582
|
return null;
|
|
582
583
|
}
|
|
583
584
|
;
|
|
584
585
|
if (sync === SyncMode.Sync) {
|
|
585
|
-
|
|
586
|
+
globalThis[_LoggerService].warn('Postgresql not suppouted sync mode');
|
|
586
587
|
return null;
|
|
587
588
|
}
|
|
588
589
|
;
|
|
589
590
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
590
|
-
|
|
591
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
591
592
|
}
|
|
592
593
|
return new Promise(async (resolve, reject) => {
|
|
593
594
|
try {
|
|
@@ -597,14 +598,14 @@ class PostgresqlConnection {
|
|
|
597
598
|
values: params
|
|
598
599
|
});
|
|
599
600
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
600
|
-
|
|
601
|
+
globalThis[_LoggerService].verbose?.(rows);
|
|
601
602
|
}
|
|
602
603
|
if (rows && rows[0])
|
|
603
604
|
resolve(rows[0]);
|
|
604
605
|
resolve(null);
|
|
605
606
|
}
|
|
606
607
|
catch (error) {
|
|
607
|
-
|
|
608
|
+
globalThis[_LoggerService].error(`
|
|
608
609
|
error: ${error},
|
|
609
610
|
sql: ${sql},
|
|
610
611
|
params: ${params}
|
|
@@ -614,18 +615,18 @@ class PostgresqlConnection {
|
|
|
614
615
|
});
|
|
615
616
|
}
|
|
616
617
|
raw(sync, sql, params) {
|
|
617
|
-
|
|
618
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
618
619
|
if (!sql) {
|
|
619
620
|
return [];
|
|
620
621
|
}
|
|
621
622
|
;
|
|
622
623
|
if (sync === SyncMode.Sync) {
|
|
623
|
-
|
|
624
|
+
globalThis[_LoggerService].warn('Postgresql not suppouted sync mode');
|
|
624
625
|
return [];
|
|
625
626
|
}
|
|
626
627
|
;
|
|
627
628
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
628
|
-
|
|
629
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
629
630
|
}
|
|
630
631
|
return new Promise(async (resolve, reject) => {
|
|
631
632
|
try {
|
|
@@ -635,14 +636,14 @@ class PostgresqlConnection {
|
|
|
635
636
|
values: params
|
|
636
637
|
});
|
|
637
638
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
638
|
-
|
|
639
|
+
globalThis[_LoggerService].verbose?.(rows);
|
|
639
640
|
}
|
|
640
641
|
if (rows)
|
|
641
642
|
resolve(rows.map((i) => Object.values(i)[0]));
|
|
642
643
|
resolve([]);
|
|
643
644
|
}
|
|
644
645
|
catch (error) {
|
|
645
|
-
|
|
646
|
+
globalThis[_LoggerService].error(`
|
|
646
647
|
error: ${error},
|
|
647
648
|
sql: ${sql},
|
|
648
649
|
params: ${params}
|
|
@@ -652,18 +653,18 @@ class PostgresqlConnection {
|
|
|
652
653
|
});
|
|
653
654
|
}
|
|
654
655
|
query(sync, sql, params) {
|
|
655
|
-
|
|
656
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
656
657
|
if (!sql) {
|
|
657
658
|
return [];
|
|
658
659
|
}
|
|
659
660
|
;
|
|
660
661
|
if (sync === SyncMode.Sync) {
|
|
661
|
-
|
|
662
|
+
globalThis[_LoggerService].warn('Postgresql not suppouted sync mode');
|
|
662
663
|
return [];
|
|
663
664
|
}
|
|
664
665
|
;
|
|
665
666
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
666
|
-
|
|
667
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
667
668
|
}
|
|
668
669
|
return new Promise(async (resolve, reject) => {
|
|
669
670
|
try {
|
|
@@ -673,12 +674,12 @@ class PostgresqlConnection {
|
|
|
673
674
|
values: params
|
|
674
675
|
});
|
|
675
676
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
676
|
-
|
|
677
|
+
globalThis[_LoggerService].verbose?.(rows);
|
|
677
678
|
}
|
|
678
679
|
resolve(rows);
|
|
679
680
|
}
|
|
680
681
|
catch (error) {
|
|
681
|
-
|
|
682
|
+
globalThis[_LoggerService].error(`
|
|
682
683
|
error: ${error},
|
|
683
684
|
sql: ${sql},
|
|
684
685
|
params: ${params}
|
|
@@ -710,14 +711,14 @@ export class Postgresql {
|
|
|
710
711
|
}
|
|
711
712
|
createConnection(sync) {
|
|
712
713
|
if (sync === SyncMode.Sync) {
|
|
713
|
-
|
|
714
|
+
globalThis[_LoggerService].error('Postgresql not suppouted sync mode');
|
|
714
715
|
return null;
|
|
715
716
|
}
|
|
716
717
|
;
|
|
717
718
|
return new Promise(async (resolve, reject) => {
|
|
718
719
|
try {
|
|
719
720
|
const connection = await this[_daoDB].connect();
|
|
720
|
-
|
|
721
|
+
globalThis[_LoggerService].debug?.('create new connection!');
|
|
721
722
|
resolve(new PostgresqlConnection(connection));
|
|
722
723
|
}
|
|
723
724
|
catch (error) {
|
|
@@ -727,7 +728,7 @@ export class Postgresql {
|
|
|
727
728
|
}
|
|
728
729
|
transaction(sync, fn, conn) {
|
|
729
730
|
if (sync === SyncMode.Sync) {
|
|
730
|
-
|
|
731
|
+
globalThis[_LoggerService].warn('Postgresql not suppouted sync mode');
|
|
731
732
|
return null;
|
|
732
733
|
}
|
|
733
734
|
;
|
|
@@ -740,27 +741,27 @@ export class Postgresql {
|
|
|
740
741
|
}
|
|
741
742
|
if (conn?.[_inTransaction] !== true) {
|
|
742
743
|
needCommit = true;
|
|
743
|
-
|
|
744
|
+
globalThis[_LoggerService].debug?.('beginTransaction begin!');
|
|
744
745
|
await conn[_daoConnection].query('BEGIN');
|
|
745
|
-
|
|
746
|
+
globalThis[_LoggerService].debug?.('beginTransaction end!');
|
|
746
747
|
}
|
|
747
748
|
conn[_inTransaction] = true;
|
|
748
749
|
try {
|
|
749
750
|
const result = await fn(conn);
|
|
750
751
|
if (needCommit) {
|
|
751
|
-
|
|
752
|
+
globalThis[_LoggerService].debug?.('commit begin!');
|
|
752
753
|
await conn[_daoConnection].query('COMMIT');
|
|
753
754
|
conn[_inTransaction] = false;
|
|
754
|
-
|
|
755
|
+
globalThis[_LoggerService].debug?.('commit end!');
|
|
755
756
|
}
|
|
756
757
|
resolve(result);
|
|
757
758
|
}
|
|
758
759
|
catch (error) {
|
|
759
|
-
|
|
760
|
+
globalThis[_LoggerService].debug?.('rollback begin!');
|
|
760
761
|
await conn[_daoConnection].query('ROLLBACK');
|
|
761
|
-
|
|
762
|
+
globalThis[_LoggerService].debug?.('rollback end!');
|
|
762
763
|
conn[_inTransaction] = false;
|
|
763
|
-
|
|
764
|
+
globalThis[_LoggerService].error(error);
|
|
764
765
|
reject(error);
|
|
765
766
|
}
|
|
766
767
|
finally {
|
|
@@ -769,9 +770,9 @@ export class Postgresql {
|
|
|
769
770
|
conn[_inTransaction] = false;
|
|
770
771
|
}
|
|
771
772
|
if (newConn) {
|
|
772
|
-
|
|
773
|
+
globalThis[_LoggerService].debug?.('release begin!');
|
|
773
774
|
conn[_daoConnection].release();
|
|
774
|
-
|
|
775
|
+
globalThis[_LoggerService].debug?.('release end!');
|
|
775
776
|
}
|
|
776
777
|
}
|
|
777
778
|
catch (error) {
|
|
@@ -799,28 +800,28 @@ class SqliteConnection {
|
|
|
799
800
|
}
|
|
800
801
|
execute(sync, sql, params) {
|
|
801
802
|
try {
|
|
802
|
-
|
|
803
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
803
804
|
if (!sql) {
|
|
804
805
|
return { affectedRows: 0, insertId: 0n };
|
|
805
806
|
}
|
|
806
807
|
;
|
|
807
808
|
if (sync === SyncMode.Async) {
|
|
808
|
-
|
|
809
|
+
globalThis[_LoggerService].warn(`SQLITE not suppoted async mode`);
|
|
809
810
|
return { affectedRows: 0, insertId: 0n };
|
|
810
811
|
}
|
|
811
812
|
;
|
|
812
813
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
813
|
-
|
|
814
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
814
815
|
}
|
|
815
816
|
const result = this[_daoConnection].prepare(sql).run(params ?? {});
|
|
816
817
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
817
|
-
|
|
818
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
818
819
|
}
|
|
819
820
|
const { changes, lastInsertRowid } = result;
|
|
820
821
|
return { affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n };
|
|
821
822
|
}
|
|
822
823
|
catch (error) {
|
|
823
|
-
|
|
824
|
+
globalThis[_LoggerService].error(`
|
|
824
825
|
error: ${error},
|
|
825
826
|
sql: ${sql},
|
|
826
827
|
params: ${params}
|
|
@@ -830,23 +831,23 @@ class SqliteConnection {
|
|
|
830
831
|
}
|
|
831
832
|
pluck(sync, sql, params) {
|
|
832
833
|
try {
|
|
833
|
-
|
|
834
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
834
835
|
if (!sql) {
|
|
835
836
|
return null;
|
|
836
837
|
}
|
|
837
838
|
;
|
|
838
839
|
if (sync === SyncMode.Async) {
|
|
839
|
-
|
|
840
|
+
globalThis[_LoggerService].warn(`SQLITE not suppoted async mode`);
|
|
840
841
|
return null;
|
|
841
842
|
}
|
|
842
843
|
;
|
|
843
844
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
844
|
-
|
|
845
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
845
846
|
}
|
|
846
847
|
return this[_daoConnection].prepare(sql).pluck().get(params ?? {});
|
|
847
848
|
}
|
|
848
849
|
catch (error) {
|
|
849
|
-
|
|
850
|
+
globalThis[_LoggerService].error(`
|
|
850
851
|
error: ${error},
|
|
851
852
|
sql: ${sql},
|
|
852
853
|
params: ${params}
|
|
@@ -856,7 +857,7 @@ class SqliteConnection {
|
|
|
856
857
|
}
|
|
857
858
|
get(sync, sql, params) {
|
|
858
859
|
try {
|
|
859
|
-
|
|
860
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
860
861
|
if (!sql) {
|
|
861
862
|
return null;
|
|
862
863
|
}
|
|
@@ -866,12 +867,12 @@ class SqliteConnection {
|
|
|
866
867
|
}
|
|
867
868
|
;
|
|
868
869
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
869
|
-
|
|
870
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
870
871
|
}
|
|
871
872
|
return this[_daoConnection].prepare(sql).get(params ?? {});
|
|
872
873
|
}
|
|
873
874
|
catch (error) {
|
|
874
|
-
|
|
875
|
+
globalThis[_LoggerService].error(`
|
|
875
876
|
error: ${error},
|
|
876
877
|
sql: ${sql},
|
|
877
878
|
params: ${params}
|
|
@@ -881,23 +882,23 @@ class SqliteConnection {
|
|
|
881
882
|
}
|
|
882
883
|
raw(sync, sql, params) {
|
|
883
884
|
try {
|
|
884
|
-
|
|
885
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
885
886
|
if (!sql) {
|
|
886
887
|
return [];
|
|
887
888
|
}
|
|
888
889
|
;
|
|
889
890
|
if (sync === SyncMode.Async) {
|
|
890
|
-
|
|
891
|
+
globalThis[_LoggerService].warn(`SQLITE not suppoted async mode`);
|
|
891
892
|
return [];
|
|
892
893
|
}
|
|
893
894
|
;
|
|
894
895
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
895
|
-
|
|
896
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
896
897
|
}
|
|
897
898
|
return this[_daoConnection].prepare(sql).raw().all(params ?? {});
|
|
898
899
|
}
|
|
899
900
|
catch (error) {
|
|
900
|
-
|
|
901
|
+
globalThis[_LoggerService].error(`
|
|
901
902
|
error: ${error},
|
|
902
903
|
sql: ${sql},
|
|
903
904
|
params: ${params}
|
|
@@ -907,23 +908,23 @@ class SqliteConnection {
|
|
|
907
908
|
}
|
|
908
909
|
query(sync, sql, params) {
|
|
909
910
|
try {
|
|
910
|
-
|
|
911
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
911
912
|
if (!sql) {
|
|
912
913
|
return [];
|
|
913
914
|
}
|
|
914
915
|
;
|
|
915
916
|
if (sync === SyncMode.Async) {
|
|
916
|
-
|
|
917
|
+
globalThis[_LoggerService].warn(`SQLITE not suppoted async mode`);
|
|
917
918
|
return [];
|
|
918
919
|
}
|
|
919
920
|
;
|
|
920
921
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
921
|
-
|
|
922
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
922
923
|
}
|
|
923
924
|
return this[_daoConnection].prepare(sql).all(params ?? {});
|
|
924
925
|
}
|
|
925
926
|
catch (error) {
|
|
926
|
-
|
|
927
|
+
globalThis[_LoggerService].error(`
|
|
927
928
|
error: ${error},
|
|
928
929
|
sql: ${sql},
|
|
929
930
|
params: ${params}
|
|
@@ -974,7 +975,7 @@ export class Sqlite {
|
|
|
974
975
|
}
|
|
975
976
|
createConnection(sync) {
|
|
976
977
|
if (sync === SyncMode.Async) {
|
|
977
|
-
|
|
978
|
+
globalThis[_LoggerService].error(`SQLITE not suppoted async mode`);
|
|
978
979
|
return null;
|
|
979
980
|
}
|
|
980
981
|
;
|
|
@@ -982,7 +983,7 @@ export class Sqlite {
|
|
|
982
983
|
}
|
|
983
984
|
transaction(sync, fn, conn) {
|
|
984
985
|
if (sync === SyncMode.Async) {
|
|
985
|
-
|
|
986
|
+
globalThis[_LoggerService].warn(`SQLITE not suppoted async mode`);
|
|
986
987
|
return null;
|
|
987
988
|
}
|
|
988
989
|
;
|
|
@@ -1026,18 +1027,18 @@ export class SqliteRemoteConnection {
|
|
|
1026
1027
|
this[_sqliteRemoteName] = name;
|
|
1027
1028
|
}
|
|
1028
1029
|
execute(sync, sql, params) {
|
|
1029
|
-
|
|
1030
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
1030
1031
|
if (!sql) {
|
|
1031
1032
|
return { affectedRows: 0, insertId: 0n };
|
|
1032
1033
|
}
|
|
1033
1034
|
;
|
|
1034
1035
|
if (sync === SyncMode.Sync) {
|
|
1035
|
-
|
|
1036
|
+
globalThis[_LoggerService].warn('SqliteRemote not suppouted sync mode');
|
|
1036
1037
|
return { affectedRows: 0, insertId: 0n };
|
|
1037
1038
|
}
|
|
1038
1039
|
;
|
|
1039
1040
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
1040
|
-
|
|
1041
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
1041
1042
|
}
|
|
1042
1043
|
return new Promise(async (resolve, reject) => {
|
|
1043
1044
|
try {
|
|
@@ -1046,7 +1047,7 @@ export class SqliteRemoteConnection {
|
|
|
1046
1047
|
resolve({ affectedRows, insertId: insertId ? BigInt(insertId) : 0n });
|
|
1047
1048
|
}
|
|
1048
1049
|
catch (error) {
|
|
1049
|
-
|
|
1050
|
+
globalThis[_LoggerService].error(`
|
|
1050
1051
|
error: ${error},
|
|
1051
1052
|
sql: ${sql},
|
|
1052
1053
|
params: ${params}
|
|
@@ -1056,18 +1057,18 @@ export class SqliteRemoteConnection {
|
|
|
1056
1057
|
});
|
|
1057
1058
|
}
|
|
1058
1059
|
pluck(sync, sql, params) {
|
|
1059
|
-
|
|
1060
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
1060
1061
|
if (!sql) {
|
|
1061
1062
|
return null;
|
|
1062
1063
|
}
|
|
1063
1064
|
;
|
|
1064
1065
|
if (sync === SyncMode.Sync) {
|
|
1065
|
-
|
|
1066
|
+
globalThis[_LoggerService].warn('SqliteRemote not suppouted sync mode');
|
|
1066
1067
|
return null;
|
|
1067
1068
|
}
|
|
1068
1069
|
;
|
|
1069
1070
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
1070
|
-
|
|
1071
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
1071
1072
|
}
|
|
1072
1073
|
return new Promise(async (resolve, reject) => {
|
|
1073
1074
|
try {
|
|
@@ -1076,7 +1077,7 @@ export class SqliteRemoteConnection {
|
|
|
1076
1077
|
resolve(r);
|
|
1077
1078
|
}
|
|
1078
1079
|
catch (error) {
|
|
1079
|
-
|
|
1080
|
+
globalThis[_LoggerService].error(`
|
|
1080
1081
|
error: ${error},
|
|
1081
1082
|
sql: ${sql},
|
|
1082
1083
|
params: ${params}
|
|
@@ -1086,18 +1087,18 @@ export class SqliteRemoteConnection {
|
|
|
1086
1087
|
});
|
|
1087
1088
|
}
|
|
1088
1089
|
get(sync, sql, params) {
|
|
1089
|
-
|
|
1090
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
1090
1091
|
if (!sql) {
|
|
1091
1092
|
return null;
|
|
1092
1093
|
}
|
|
1093
1094
|
;
|
|
1094
1095
|
if (sync === SyncMode.Sync) {
|
|
1095
|
-
|
|
1096
|
+
globalThis[_LoggerService].warn('SqliteRemote not suppouted sync mode');
|
|
1096
1097
|
return null;
|
|
1097
1098
|
}
|
|
1098
1099
|
;
|
|
1099
1100
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
1100
|
-
|
|
1101
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
1101
1102
|
}
|
|
1102
1103
|
return new Promise(async (resolve, reject) => {
|
|
1103
1104
|
try {
|
|
@@ -1106,7 +1107,7 @@ export class SqliteRemoteConnection {
|
|
|
1106
1107
|
resolve(r);
|
|
1107
1108
|
}
|
|
1108
1109
|
catch (error) {
|
|
1109
|
-
|
|
1110
|
+
globalThis[_LoggerService].error(`
|
|
1110
1111
|
error: ${error},
|
|
1111
1112
|
sql: ${sql},
|
|
1112
1113
|
params: ${params}
|
|
@@ -1116,18 +1117,18 @@ export class SqliteRemoteConnection {
|
|
|
1116
1117
|
});
|
|
1117
1118
|
}
|
|
1118
1119
|
raw(sync, sql, params) {
|
|
1119
|
-
|
|
1120
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
1120
1121
|
if (!sql) {
|
|
1121
1122
|
return [];
|
|
1122
1123
|
}
|
|
1123
1124
|
;
|
|
1124
1125
|
if (sync === SyncMode.Sync) {
|
|
1125
|
-
|
|
1126
|
+
globalThis[_LoggerService].warn('SqliteRemote not suppouted sync mode');
|
|
1126
1127
|
return [];
|
|
1127
1128
|
}
|
|
1128
1129
|
;
|
|
1129
1130
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
1130
|
-
|
|
1131
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
1131
1132
|
}
|
|
1132
1133
|
return new Promise(async (resolve, reject) => {
|
|
1133
1134
|
try {
|
|
@@ -1136,7 +1137,7 @@ export class SqliteRemoteConnection {
|
|
|
1136
1137
|
resolve(r);
|
|
1137
1138
|
}
|
|
1138
1139
|
catch (error) {
|
|
1139
|
-
|
|
1140
|
+
globalThis[_LoggerService].error(`
|
|
1140
1141
|
error: ${error},
|
|
1141
1142
|
sql: ${sql},
|
|
1142
1143
|
params: ${params}
|
|
@@ -1146,18 +1147,18 @@ export class SqliteRemoteConnection {
|
|
|
1146
1147
|
});
|
|
1147
1148
|
}
|
|
1148
1149
|
query(sync, sql, params) {
|
|
1149
|
-
|
|
1150
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
1150
1151
|
if (!sql) {
|
|
1151
1152
|
return [];
|
|
1152
1153
|
}
|
|
1153
1154
|
;
|
|
1154
1155
|
if (sync === SyncMode.Sync) {
|
|
1155
|
-
|
|
1156
|
+
globalThis[_LoggerService].warn('SqliteRemote not suppouted sync mode');
|
|
1156
1157
|
return [];
|
|
1157
1158
|
}
|
|
1158
1159
|
;
|
|
1159
1160
|
if (globalThis[_GlobalSqlOption].log === 'trace') {
|
|
1160
|
-
|
|
1161
|
+
globalThis[_LoggerService].verbose?.(`${sql}\n,${JSON.stringify(params ?? '')}`);
|
|
1161
1162
|
}
|
|
1162
1163
|
return new Promise(async (resolve, reject) => {
|
|
1163
1164
|
try {
|
|
@@ -1166,7 +1167,7 @@ export class SqliteRemoteConnection {
|
|
|
1166
1167
|
resolve(r);
|
|
1167
1168
|
}
|
|
1168
1169
|
catch (error) {
|
|
1169
|
-
|
|
1170
|
+
globalThis[_LoggerService].error(`
|
|
1170
1171
|
error: ${error},
|
|
1171
1172
|
sql: ${sql},
|
|
1172
1173
|
params: ${params}
|
|
@@ -1186,7 +1187,7 @@ export class SqliteRemote {
|
|
|
1186
1187
|
}
|
|
1187
1188
|
createConnection(sync) {
|
|
1188
1189
|
if (sync === SyncMode.Sync) {
|
|
1189
|
-
|
|
1190
|
+
globalThis[_LoggerService].error('SQLITEREMOTE not suppouted sync mode');
|
|
1190
1191
|
return null;
|
|
1191
1192
|
}
|
|
1192
1193
|
;
|
|
@@ -1203,7 +1204,7 @@ export class SqliteRemote {
|
|
|
1203
1204
|
});
|
|
1204
1205
|
}
|
|
1205
1206
|
transaction(sync, fn, conn) {
|
|
1206
|
-
|
|
1207
|
+
globalThis[_LoggerService].warn(`SQLITEREMOTE not suppoted transaction`);
|
|
1207
1208
|
return null;
|
|
1208
1209
|
}
|
|
1209
1210
|
close(sync) {
|
|
@@ -1609,28 +1610,28 @@ export class SqlCache {
|
|
|
1609
1610
|
const name = globalThis[_path].basename(modeName, extname);
|
|
1610
1611
|
let ct = 0;
|
|
1611
1612
|
if (extname === '.mu') {
|
|
1612
|
-
|
|
1613
|
+
globalThis[_LoggerService].debug?.(`sql: ${file} start explain!`);
|
|
1613
1614
|
const parser = new MUParser(rootName || name, globalThis[_fs].readFileSync(file, { encoding: 'utf-8' }).toString());
|
|
1614
1615
|
let source = parser.next();
|
|
1615
1616
|
while (source != null) {
|
|
1616
1617
|
ct++;
|
|
1617
1618
|
this.sqlMap[source[0]] = source[1];
|
|
1618
|
-
|
|
1619
|
+
globalThis[_LoggerService].debug?.(`sql: ${source[0]} found!`);
|
|
1619
1620
|
source = parser.next();
|
|
1620
1621
|
}
|
|
1621
|
-
|
|
1622
|
+
globalThis[_LoggerService].debug?.(`sql: ${file} explain over[${ct}]!`);
|
|
1622
1623
|
}
|
|
1623
1624
|
else if (jsMode && extname === '.js') {
|
|
1624
|
-
|
|
1625
|
+
globalThis[_LoggerService].debug?.(`sql: ${file} start explain!`);
|
|
1625
1626
|
const obj = (await import(globalThis[_path].join(sqlDir, modeName))).default;
|
|
1626
1627
|
for (const [key, fn] of Object.entries(obj)) {
|
|
1627
1628
|
ct++;
|
|
1628
1629
|
this.sqlMap[`${rootName || name}.${String(key)}`] = fn;
|
|
1629
1630
|
}
|
|
1630
|
-
|
|
1631
|
+
globalThis[_LoggerService].debug?.(`sql: ${file} explain over[${ct}]!`);
|
|
1631
1632
|
}
|
|
1632
1633
|
else if (extname === '.xml') {
|
|
1633
|
-
|
|
1634
|
+
globalThis[_LoggerService].debug?.(`sql: ${file} start explain!`);
|
|
1634
1635
|
const root = HTML.parse(replaceCdata(globalThis[_fs].readFileSync(file, { encoding: 'utf-8' }).toString()))[0];
|
|
1635
1636
|
if (root) {
|
|
1636
1637
|
const mappers = root.children;
|
|
@@ -1647,15 +1648,15 @@ export class SqlCache {
|
|
|
1647
1648
|
const keys = [];
|
|
1648
1649
|
this.readResultMap(am.children, keys, []);
|
|
1649
1650
|
globalThis[_resultMap][`${rootName || name}.${am.id}`] = keys;
|
|
1650
|
-
|
|
1651
|
+
globalThis[_LoggerService].debug?.(`sql_resultMap: ${`${rootName || name}.${am.id}`} found!`);
|
|
1651
1652
|
}
|
|
1652
1653
|
else {
|
|
1653
1654
|
this.sqlMap[`${rootName || name}.${am.id}`] = am.children;
|
|
1654
1655
|
if (am.attrs['resultMap']) {
|
|
1655
1656
|
globalThis[_resultMap_SQLID][`${rootName || name}.${am.id}`] = am.attrs['resultMap'];
|
|
1656
|
-
|
|
1657
|
+
globalThis[_LoggerService].debug?.(`sql: autoMapper: ${rootName || name}.${am.id}-${am.attrs['resultMap']}`);
|
|
1657
1658
|
}
|
|
1658
|
-
|
|
1659
|
+
globalThis[_LoggerService].debug?.(`sql: ${rootName || name}.${am.id} found!`);
|
|
1659
1660
|
ct++;
|
|
1660
1661
|
}
|
|
1661
1662
|
}
|
|
@@ -1663,7 +1664,7 @@ export class SqlCache {
|
|
|
1663
1664
|
}
|
|
1664
1665
|
}
|
|
1665
1666
|
}
|
|
1666
|
-
|
|
1667
|
+
globalThis[_LoggerService].debug?.(`sql: ${file} explain over[${ct}]!`);
|
|
1667
1668
|
}
|
|
1668
1669
|
}
|
|
1669
1670
|
}
|
|
@@ -1818,7 +1819,7 @@ function P(skipConn = false) {
|
|
|
1818
1819
|
}
|
|
1819
1820
|
try {
|
|
1820
1821
|
const result = fn.call(this, ...args);
|
|
1821
|
-
|
|
1822
|
+
globalThis[_LoggerService].log(`${propertyKey}:${option.sqlId ?? option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1822
1823
|
return result;
|
|
1823
1824
|
}
|
|
1824
1825
|
catch (error) {
|
|
@@ -1856,7 +1857,7 @@ function P(skipConn = false) {
|
|
|
1856
1857
|
}
|
|
1857
1858
|
try {
|
|
1858
1859
|
const result = await fn.call(this, ...args);
|
|
1859
|
-
|
|
1860
|
+
globalThis[_LoggerService].log(`${propertyKey}:${option.sqlId ?? option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1860
1861
|
resolve(result);
|
|
1861
1862
|
}
|
|
1862
1863
|
catch (error) {
|
|
@@ -1886,7 +1887,7 @@ function P(skipConn = false) {
|
|
|
1886
1887
|
needRealseConn = false;
|
|
1887
1888
|
}
|
|
1888
1889
|
const result = await fn.call(this, ...args);
|
|
1889
|
-
|
|
1890
|
+
globalThis[_LoggerService].log(`${propertyKey}:${option.sqlId ?? option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1890
1891
|
resolve(result);
|
|
1891
1892
|
}
|
|
1892
1893
|
catch (error) {
|
|
@@ -1916,7 +1917,7 @@ function P(skipConn = false) {
|
|
|
1916
1917
|
needRealseConn = false;
|
|
1917
1918
|
}
|
|
1918
1919
|
const result = await fn.call(this, ...args);
|
|
1919
|
-
|
|
1920
|
+
globalThis[_LoggerService].log(`${propertyKey}:${option.sqlId ?? option.tableName}:use ${+new Date() - startTime}ms`);
|
|
1920
1921
|
resolve(result);
|
|
1921
1922
|
}
|
|
1922
1923
|
catch (error) {
|
|
@@ -5105,24 +5106,24 @@ export async function excuteWithLock(config, fn__) {
|
|
|
5105
5106
|
const lock = await GetRedisLock(key, config.lockMaxActive);
|
|
5106
5107
|
if (lock === false) {
|
|
5107
5108
|
if (config.lockWait !== false && ((config.lockMaxWaitTime ?? 0) === 0 || (wait_time + (config.lockRetryInterval ?? 100)) <= (config.lockMaxWaitTime ?? 0))) {
|
|
5108
|
-
|
|
5109
|
+
globalThis[_LoggerService].debug?.(`get lock ${key} fail, retry after ${config.lockRetryInterval ?? 100}ms...`);
|
|
5109
5110
|
await sleep(config.lockRetryInterval ?? 100);
|
|
5110
5111
|
wait_time += (config.lockRetryInterval ?? 100);
|
|
5111
5112
|
return await fn();
|
|
5112
5113
|
}
|
|
5113
5114
|
else {
|
|
5114
|
-
|
|
5115
|
+
globalThis[_LoggerService].debug?.(`get lock ${key} fail`);
|
|
5115
5116
|
throw new Error(config.errorMessage || `get lock fail: ${key}`);
|
|
5116
5117
|
}
|
|
5117
5118
|
}
|
|
5118
5119
|
else {
|
|
5119
|
-
|
|
5120
|
+
globalThis[_LoggerService].debug?.(`get lock ${key} ok!`);
|
|
5120
5121
|
await db.pexpire(key, config.lockMaxTime ?? 60000);
|
|
5121
5122
|
try {
|
|
5122
5123
|
return await fn__();
|
|
5123
5124
|
}
|
|
5124
5125
|
finally {
|
|
5125
|
-
|
|
5126
|
+
globalThis[_LoggerService].debug?.(`unlock ${key} ok!`);
|
|
5126
5127
|
await db.decr(key);
|
|
5127
5128
|
}
|
|
5128
5129
|
}
|
|
@@ -5204,7 +5205,7 @@ async function clearParent(clearKey) {
|
|
|
5204
5205
|
const keys = await db.smembers(`[cache-parent]${clearKey}`);
|
|
5205
5206
|
if (keys) {
|
|
5206
5207
|
for (const key of keys) {
|
|
5207
|
-
|
|
5208
|
+
globalThis[_LoggerService].debug?.(`cache ${key} cleared!`);
|
|
5208
5209
|
await clearChild(key);
|
|
5209
5210
|
}
|
|
5210
5211
|
}
|
|
@@ -5217,11 +5218,11 @@ export async function excuteWithCache(config, fn) {
|
|
|
5217
5218
|
const db = getRedisDB();
|
|
5218
5219
|
const cache = await db.get(`[cache]${config.key}`);
|
|
5219
5220
|
if (cache) {
|
|
5220
|
-
|
|
5221
|
+
globalThis[_LoggerService].debug?.(`cache ${config.key} hit!`);
|
|
5221
5222
|
return JSON.parse(cache);
|
|
5222
5223
|
}
|
|
5223
5224
|
else {
|
|
5224
|
-
|
|
5225
|
+
globalThis[_LoggerService].debug?.(`cache ${config.key} miss!`);
|
|
5225
5226
|
const result = await fn();
|
|
5226
5227
|
await setMethodCache({
|
|
5227
5228
|
key: config.key,
|
|
@@ -5241,11 +5242,11 @@ export function MethodCache(config) {
|
|
|
5241
5242
|
const db = getRedisDB();
|
|
5242
5243
|
const cache = await db.get(`[cache]${key}`);
|
|
5243
5244
|
if (cache) {
|
|
5244
|
-
|
|
5245
|
+
globalThis[_LoggerService].debug?.(`cache ${key} hit!`);
|
|
5245
5246
|
return JSON.parse(cache);
|
|
5246
5247
|
}
|
|
5247
5248
|
else {
|
|
5248
|
-
|
|
5249
|
+
globalThis[_LoggerService].debug?.(`cache ${key} miss!`);
|
|
5249
5250
|
const result = await fn.call(this, ...args);
|
|
5250
5251
|
const clearKey = config.clearKey ? typeof config.clearKey === 'function' ? config.clearKey.call(this, ...args) : config.clearKey : undefined;
|
|
5251
5252
|
await setMethodCache({
|
|
@@ -5370,3 +5371,34 @@ class MUParser {
|
|
|
5370
5371
|
}
|
|
5371
5372
|
}
|
|
5372
5373
|
MUParser.END = 1;
|
|
5374
|
+
export class PrinterLogger {
|
|
5375
|
+
constructor() {
|
|
5376
|
+
this.logger = pino({
|
|
5377
|
+
name: 'app',
|
|
5378
|
+
transport: {
|
|
5379
|
+
target: 'pino-pretty',
|
|
5380
|
+
},
|
|
5381
|
+
});
|
|
5382
|
+
}
|
|
5383
|
+
log(message, ...optionalParams) {
|
|
5384
|
+
this.logger.info(message, ...optionalParams);
|
|
5385
|
+
}
|
|
5386
|
+
fatal(message, ...optionalParams) {
|
|
5387
|
+
this.logger.fatal(message, ...optionalParams);
|
|
5388
|
+
}
|
|
5389
|
+
error(message, ...optionalParams) {
|
|
5390
|
+
this.logger.error(message, ...optionalParams);
|
|
5391
|
+
}
|
|
5392
|
+
warn(message, ...optionalParams) {
|
|
5393
|
+
this.logger.warn(message, ...optionalParams);
|
|
5394
|
+
}
|
|
5395
|
+
debug(message, ...optionalParams) {
|
|
5396
|
+
this.logger.debug(message, ...optionalParams);
|
|
5397
|
+
}
|
|
5398
|
+
verbose(message, ...optionalParams) {
|
|
5399
|
+
this.logger.trace(message, ...optionalParams);
|
|
5400
|
+
}
|
|
5401
|
+
setLogLevels(levels) {
|
|
5402
|
+
this.logger.level = levels.join(',');
|
|
5403
|
+
}
|
|
5404
|
+
}
|
package/sqlite.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { decode, encode } from "@msgpack/msgpack";
|
|
2
2
|
import Sqlstring from 'sqlstring';
|
|
3
3
|
import { snowflake } from './snowflake.js';
|
|
4
|
-
import {
|
|
4
|
+
import { _LoggerService, extensionCodec } from './sql.js';
|
|
5
5
|
export class SqliteRemoteClass {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.dbList = {};
|
|
8
8
|
}
|
|
9
9
|
async execute(inData) {
|
|
10
10
|
const [dbName, sql, params] = decode(inData);
|
|
11
|
-
|
|
11
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
12
12
|
try {
|
|
13
13
|
if (!sql) {
|
|
14
14
|
return encode({ affectedRows: 0, insertId: 0n }, { extensionCodec });
|
|
15
15
|
}
|
|
16
16
|
;
|
|
17
17
|
if (this.trace) {
|
|
18
|
-
|
|
18
|
+
globalThis[_LoggerService].verbose?.(Sqlstring.format(sql, params));
|
|
19
19
|
}
|
|
20
20
|
const result = this.dbList[dbName].prepare(sql).run(params ?? {});
|
|
21
21
|
if (this.trace) {
|
|
22
|
-
|
|
22
|
+
globalThis[_LoggerService].verbose?.(result);
|
|
23
23
|
}
|
|
24
24
|
const { changes, lastInsertRowid } = result;
|
|
25
25
|
return encode({ affectedRows: changes, insertId: lastInsertRowid ? BigInt(lastInsertRowid) : 0n }, { extensionCodec });
|
|
26
26
|
}
|
|
27
27
|
catch (error) {
|
|
28
|
-
|
|
28
|
+
globalThis[_LoggerService].error(`
|
|
29
29
|
error: ${error},
|
|
30
30
|
sql: ${sql},
|
|
31
31
|
params: ${params}
|
|
@@ -35,20 +35,18 @@ export class SqliteRemoteClass {
|
|
|
35
35
|
}
|
|
36
36
|
async pluck(inData) {
|
|
37
37
|
const [dbName, sql, params] = decode(inData);
|
|
38
|
-
|
|
38
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
39
39
|
try {
|
|
40
|
-
|
|
40
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
41
41
|
if (!sql) {
|
|
42
42
|
return encode(null);
|
|
43
43
|
}
|
|
44
44
|
;
|
|
45
|
-
|
|
46
|
-
logger.trace(Sqlstring.format(sql, params));
|
|
47
|
-
}
|
|
45
|
+
globalThis[_LoggerService].verbose?.(Sqlstring.format(sql, params));
|
|
48
46
|
return encode(this.dbList[dbName].prepare(sql).pluck().get(params ?? {}), { extensionCodec });
|
|
49
47
|
}
|
|
50
48
|
catch (error) {
|
|
51
|
-
|
|
49
|
+
globalThis[_LoggerService].error(`
|
|
52
50
|
error: ${error},
|
|
53
51
|
sql: ${sql},
|
|
54
52
|
params: ${params}
|
|
@@ -58,15 +56,15 @@ export class SqliteRemoteClass {
|
|
|
58
56
|
}
|
|
59
57
|
async get(inData) {
|
|
60
58
|
const [dbName, sql, params] = decode(inData);
|
|
61
|
-
|
|
59
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
62
60
|
try {
|
|
63
61
|
if (this.trace) {
|
|
64
|
-
|
|
62
|
+
globalThis[_LoggerService].verbose?.(Sqlstring.format(sql, params));
|
|
65
63
|
}
|
|
66
64
|
return encode(this.dbList[dbName].prepare(sql).get(params ?? {}), { extensionCodec });
|
|
67
65
|
}
|
|
68
66
|
catch (error) {
|
|
69
|
-
|
|
67
|
+
globalThis[_LoggerService].error(`
|
|
70
68
|
error: ${error},
|
|
71
69
|
sql: ${sql},
|
|
72
70
|
params: ${params}
|
|
@@ -76,19 +74,19 @@ export class SqliteRemoteClass {
|
|
|
76
74
|
}
|
|
77
75
|
async raw(inData) {
|
|
78
76
|
const [dbName, sql, params] = decode(inData);
|
|
79
|
-
|
|
77
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
80
78
|
try {
|
|
81
79
|
if (!sql) {
|
|
82
80
|
return encode([]);
|
|
83
81
|
}
|
|
84
82
|
;
|
|
85
83
|
if (this.trace) {
|
|
86
|
-
|
|
84
|
+
globalThis[_LoggerService].verbose?.(Sqlstring.format(sql, params));
|
|
87
85
|
}
|
|
88
86
|
return encode(this.dbList[dbName].prepare(sql).raw().all(params ?? {}), { extensionCodec });
|
|
89
87
|
}
|
|
90
88
|
catch (error) {
|
|
91
|
-
|
|
89
|
+
globalThis[_LoggerService].error(`
|
|
92
90
|
error: ${error},
|
|
93
91
|
sql: ${sql},
|
|
94
92
|
params: ${params}
|
|
@@ -98,19 +96,19 @@ export class SqliteRemoteClass {
|
|
|
98
96
|
}
|
|
99
97
|
async query(inData) {
|
|
100
98
|
const [dbName, sql, params] = decode(inData);
|
|
101
|
-
|
|
99
|
+
globalThis[_LoggerService].debug?.(sql, params ?? '');
|
|
102
100
|
try {
|
|
103
101
|
if (!sql) {
|
|
104
102
|
encode([]);
|
|
105
103
|
}
|
|
106
104
|
;
|
|
107
105
|
if (this.trace) {
|
|
108
|
-
|
|
106
|
+
globalThis[_LoggerService].verbose?.(Sqlstring.format(sql, params));
|
|
109
107
|
}
|
|
110
108
|
return encode(this.dbList[dbName].prepare(sql).all(params ?? {}), { extensionCodec });
|
|
111
109
|
}
|
|
112
110
|
catch (error) {
|
|
113
|
-
|
|
111
|
+
globalThis[_LoggerService].error(`
|
|
114
112
|
error: ${error},
|
|
115
113
|
sql: ${sql},
|
|
116
114
|
params: ${params}
|