baja-lite 1.6.5 → 1.6.6
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 +4 -1
- package/boot.js +4 -1
- package/package.json +13 -13
- package/sql.d.ts +3 -0
- package/sql.js +7 -6
package/boot-remote.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
import { ColumnMode, SqlCache, SqliteRemote, _Context, _DataConvert, _GlobalSqlOption, _dao, _defOption, _enum, _primaryDB, _sqlCache, logger } from './sql.js';
|
|
3
3
|
export const BootRomote = async function (options) {
|
|
4
4
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption);
|
|
5
5
|
if (options.skipEmptyString !== undefined) {
|
|
@@ -32,6 +32,9 @@ export const BootRomote = async function (options) {
|
|
|
32
32
|
if (options.dataConvert) {
|
|
33
33
|
globalThis[_DataConvert] = options.dataConvert;
|
|
34
34
|
}
|
|
35
|
+
if (options.ctx) {
|
|
36
|
+
globalThis[_Context] = options.ctx;
|
|
37
|
+
}
|
|
35
38
|
if (options.SqliteRemote && options.SqliteRemote.db) {
|
|
36
39
|
if (typeof options.SqliteRemote.db === 'string') {
|
|
37
40
|
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
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 { _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, logger, Mysql, Postgresql, SqlCache, Sqlite, SqliteRemote } from './sql.js';
|
|
3
|
+
import { _Context, _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _path, _primaryDB, _sqlCache, ColumnMode, logger, Mysql, Postgresql, 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) {
|
|
@@ -39,6 +39,9 @@ export const Boot = async function (options) {
|
|
|
39
39
|
if (options.dataConvert) {
|
|
40
40
|
globalThis[_DataConvert] = options.dataConvert;
|
|
41
41
|
}
|
|
42
|
+
if (options.ctx) {
|
|
43
|
+
globalThis[_Context] = options.ctx;
|
|
44
|
+
}
|
|
42
45
|
if (options.Mysql) {
|
|
43
46
|
const { createPool } = await import('mysql2/promise');
|
|
44
47
|
if (options.Mysql['host']) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baja-lite",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.6",
|
|
4
4
|
"description": "some util for self",
|
|
5
5
|
"homepage": "https://github.com/void-soul/baja-lite",
|
|
6
6
|
"repository": {
|
|
@@ -37,38 +37,38 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@msgpack/msgpack": "3.1.2",
|
|
39
39
|
"@types/request-promise": "4.1.51",
|
|
40
|
-
"axios": "1.
|
|
40
|
+
"axios": "1.13.2",
|
|
41
41
|
"baja-lite-field": "1.4.20",
|
|
42
42
|
"decimal.js": "10.6.0",
|
|
43
43
|
"html-parse-stringify": "3.0.1",
|
|
44
44
|
"iterare": "1.2.1",
|
|
45
45
|
"mustache": "4.2.0",
|
|
46
|
-
"pino": "
|
|
47
|
-
"pino-pretty": "13.1.
|
|
46
|
+
"pino": "10.1.0",
|
|
47
|
+
"pino-pretty": "13.1.2",
|
|
48
48
|
"reflect-metadata": "0.2.2",
|
|
49
49
|
"request": "2.88.2",
|
|
50
50
|
"request-promise": "4.2.6",
|
|
51
|
-
"sql-formatter": "15.6.
|
|
51
|
+
"sql-formatter": "15.6.10",
|
|
52
52
|
"sqlstring": "2.3.3",
|
|
53
53
|
"tslib": "2.8.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/better-sqlite3": "7.6.13",
|
|
57
57
|
"@types/mustache": "4.2.6",
|
|
58
|
-
"@types/node": "24.
|
|
58
|
+
"@types/node": "24.10.1",
|
|
59
59
|
"@types/shelljs": "0.8.17",
|
|
60
60
|
"@types/sqlstring": "2.3.2",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
62
|
-
"@typescript-eslint/parser": "8.
|
|
63
|
-
"better-sqlite3": "12.
|
|
64
|
-
"ioredis": "5.
|
|
65
|
-
"mongodb": "
|
|
66
|
-
"mysql2": "3.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "8.48.0",
|
|
62
|
+
"@typescript-eslint/parser": "8.48.0",
|
|
63
|
+
"better-sqlite3": "12.5.0",
|
|
64
|
+
"ioredis": "5.8.2",
|
|
65
|
+
"mongodb": "7.0.0",
|
|
66
|
+
"mysql2": "3.15.3",
|
|
67
67
|
"pg": "8.16.3",
|
|
68
68
|
"pg-pool": "3.10.1",
|
|
69
69
|
"redlock": "5.0.0-beta.2",
|
|
70
70
|
"shelljs": "0.10.0",
|
|
71
|
-
"typescript": "5.9.
|
|
71
|
+
"typescript": "5.9.3"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
74
|
"node": ">=20"
|
package/sql.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare const _daoDB: unique symbol;
|
|
|
21
21
|
declare const _sqliteRemoteName: unique symbol;
|
|
22
22
|
declare const _SqlOption: unique symbol;
|
|
23
23
|
export declare const _DataConvert: unique symbol;
|
|
24
|
+
export declare const _Context: unique symbol;
|
|
24
25
|
export declare const _enum: unique symbol;
|
|
25
26
|
export declare const _GlobalSqlOption: unique symbol;
|
|
26
27
|
export declare const _EventBus: unique symbol;
|
|
@@ -257,6 +258,8 @@ export interface GlobalSqlOptionForWeb {
|
|
|
257
258
|
* ```
|
|
258
259
|
*/
|
|
259
260
|
dataConvert?: Record<string, (data: any) => any>;
|
|
261
|
+
/** 公开上下文 */
|
|
262
|
+
ctx?: any;
|
|
260
263
|
}
|
|
261
264
|
/**
|
|
262
265
|
# 全局行为配置文件
|
package/sql.js
CHANGED
|
@@ -70,6 +70,7 @@ const _daoDB = Symbol('daoDB');
|
|
|
70
70
|
const _sqliteRemoteName = Symbol('sqliteRemoteName');
|
|
71
71
|
const _SqlOption = Symbol('SqlOption');
|
|
72
72
|
export const _DataConvert = Symbol('DataConvert');
|
|
73
|
+
export const _Context = Symbol('Context');
|
|
73
74
|
const _resultMap = Symbol('resultMap');
|
|
74
75
|
const _resultMap_SQLID = Symbol('resultMap_SQLID');
|
|
75
76
|
export const _enum = Symbol('_enum');
|
|
@@ -2858,8 +2859,8 @@ export class SqlService {
|
|
|
2858
2859
|
if (option.sqlId && globalThis[_resultMap_SQLID][option.sqlId] && !option.mapper) {
|
|
2859
2860
|
option.mapper = globalThis[_resultMap_SQLID][option.sqlId];
|
|
2860
2861
|
}
|
|
2861
|
-
const _params = Object.assign({}, option.
|
|
2862
|
-
option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: option.isCount, ..._params }));
|
|
2862
|
+
const _params = Object.assign({}, option.params);
|
|
2863
|
+
option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: Object.assign({}, option.context, globalThis[_Context]), isCount: option.isCount, ..._params }));
|
|
2863
2864
|
const { sql, params } = this._generSql(option.dbType, option.sql, _params);
|
|
2864
2865
|
if (option.sync === SyncMode.Sync) {
|
|
2865
2866
|
const result = option.conn.query(SyncMode.Sync, sql, params);
|
|
@@ -2883,8 +2884,8 @@ export class SqlService {
|
|
|
2883
2884
|
if (option.sqlId && globalThis[_resultMap_SQLID][option.sqlId] && !option.mapper) {
|
|
2884
2885
|
option.mapper = globalThis[_resultMap_SQLID][option.sqlId];
|
|
2885
2886
|
}
|
|
2886
|
-
const _params = Object.assign({}, option.
|
|
2887
|
-
option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, ..._params }));
|
|
2887
|
+
const _params = Object.assign({}, option.params);
|
|
2888
|
+
option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: Object.assign({}, option.context, globalThis[_Context]), isCount: false, ..._params }));
|
|
2888
2889
|
const { sql, params } = this._generSql(option.dbType, option.sql, _params);
|
|
2889
2890
|
if (option.sync === SyncMode.Sync) {
|
|
2890
2891
|
const result = option.conn.query(SyncMode.Sync, sql, params);
|
|
@@ -2904,8 +2905,8 @@ export class SqlService {
|
|
|
2904
2905
|
}
|
|
2905
2906
|
excute(option) {
|
|
2906
2907
|
Throw.if(!option.sqlId && !option.sql, 'not found sql!');
|
|
2907
|
-
const _params = Object.assign({}, option.
|
|
2908
|
-
option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, ..._params }));
|
|
2908
|
+
const _params = Object.assign({}, option.params);
|
|
2909
|
+
option.sql ?? (option.sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: Object.assign({}, option.context, globalThis[_Context]), ..._params }));
|
|
2909
2910
|
const { sql, params } = this._generSql(option.dbType, option.sql, _params);
|
|
2910
2911
|
if (option.sync === SyncMode.Sync) {
|
|
2911
2912
|
const result = option.conn.execute(SyncMode.Sync, sql, params);
|