baja-lite 1.7.4 → 1.7.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.
Files changed (4) hide show
  1. package/boot.js +4 -1
  2. package/package.json +12 -12
  3. package/sql.d.ts +5 -1
  4. package/sql.js +5 -8
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, _LoggerService, _path, _primaryDB, _sqlCache, ColumnMode, Mysql, Postgresql, PrinterLogger, SqlCache, Sqlite, SqliteRemote } from './sql.js';
3
+ import { _Context, _dao, _DataConvert, _defOption, _enum, _EventBus, _fs, _GlobalSqlOption, _LoggerService, _MysqlKeepAliveTime, _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) {
@@ -48,6 +48,9 @@ export const Boot = async function (options) {
48
48
  if (options.ctx) {
49
49
  globalThis[_Context] = options.ctx;
50
50
  }
51
+ if (options.MysqlKeepAlive) {
52
+ globalThis[_MysqlKeepAliveTime] = options.MysqlKeepAlive;
53
+ }
51
54
  if (options.Mysql) {
52
55
  const { createPool } = await import('mysql2/promise');
53
56
  if (options.Mysql['host']) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
@@ -37,7 +37,6 @@
37
37
  "dependencies": {
38
38
  "@msgpack/msgpack": "3.1.3",
39
39
  "@types/request-promise": "4.1.51",
40
- "axios": "1.13.6",
41
40
  "baja-lite-field": "1.5.0",
42
41
  "decimal.js": "10.6.0",
43
42
  "html-parse-stringify": "3.0.1",
@@ -55,17 +54,18 @@
55
54
  "devDependencies": {
56
55
  "@types/better-sqlite3": "7.6.13",
57
56
  "@types/mustache": "4.2.6",
58
- "@types/node": "25.3.2",
57
+ "@types/node": "25.5.0",
59
58
  "@types/shelljs": "0.10.0",
60
59
  "@types/sqlstring": "2.3.2",
61
- "@typescript-eslint/eslint-plugin": "8.56.1",
62
- "@typescript-eslint/parser": "8.56.1",
63
- "better-sqlite3": "12.6.2",
64
- "ioredis": "5.10.0",
65
- "mongodb": "7.1.0",
66
- "mysql2": "3.18.2",
67
- "pg": "8.19.0",
68
- "pg-pool": "3.12.0",
60
+ "@typescript-eslint/eslint-plugin": "8.57.2",
61
+ "@typescript-eslint/parser": "8.57.2",
62
+ "axios": "1.14.0",
63
+ "better-sqlite3": "12.8.0",
64
+ "ioredis": "5.10.1",
65
+ "mongodb": "7.1.1",
66
+ "mysql2": "3.20.0",
67
+ "pg": "8.20.0",
68
+ "pg-pool": "3.13.0",
69
69
  "redlock": "5.0.0-beta.2",
70
70
  "shelljs": "0.10.0",
71
71
  "typescript": "5.9.3"
@@ -77,4 +77,4 @@
77
77
  "access": "public"
78
78
  },
79
79
  "models": "./index.js"
80
- }
80
+ }
package/sql.d.ts CHANGED
@@ -21,6 +21,7 @@ declare const _sqliteRemoteName: unique symbol;
21
21
  declare const _SqlOption: unique symbol;
22
22
  export declare const _DataConvert: unique symbol;
23
23
  export declare const _Context: unique symbol;
24
+ export declare const _MysqlKeepAliveTime: 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;
@@ -301,6 +302,10 @@ export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
301
302
  ```
302
303
  */
303
304
  Mysql?: Record<string, Record<string, any>> | Record<string, any>;
305
+ /**
306
+ * MYSQL保持心跳的间隔,默认30秒
307
+ */
308
+ MysqlKeepAlive?: number;
304
309
  /**
305
310
  初始化postgresql链接 支持多数据源
306
311
  ## 单一数据源: 直接传入postgresql的连接配置
@@ -551,7 +556,6 @@ export declare class Mysql implements Dao {
551
556
  export declare class Postgresql implements Dao {
552
557
  [_daoDB]: any;
553
558
  constructor(pool: any);
554
- keepAlive(): Promise<void>;
555
559
  createConnection(sync: SyncMode.Sync): Connection | null;
556
560
  createConnection(sync: SyncMode.Async): Promise<Connection | null>;
557
561
  transaction<T = any>(sync: SyncMode.Sync, fn: (conn: Connection) => T, conn?: Connection | null): T | null;
package/sql.js CHANGED
@@ -71,6 +71,7 @@ const _sqliteRemoteName = Symbol('sqliteRemoteName');
71
71
  const _SqlOption = Symbol('SqlOption');
72
72
  export const _DataConvert = Symbol('DataConvert');
73
73
  export const _Context = Symbol('Context');
74
+ export const _MysqlKeepAliveTime = Symbol('MysqlKeepAliveTime');
74
75
  const _resultMap = Symbol('resultMap');
75
76
  const _resultMap_SQLID = Symbol('resultMap_SQLID');
76
77
  export const _enum = Symbol('_enum');
@@ -404,11 +405,12 @@ _b = _inTransaction;
404
405
  export class Mysql {
405
406
  constructor(pool) {
406
407
  this[_daoDB] = pool;
408
+ this.keepAlive();
407
409
  }
408
410
  async keepAlive() {
409
- const connection = await this[_daoDB].getConnection();
410
- connection.query('SELECT 1 FROM DUAL');
411
- setTimeout(async () => await this.keepAlive(), 60000);
411
+ const connection = await this.createConnection(SyncMode.Async);
412
+ await connection?.query(SyncMode.Async, 'SELECT 1 FROM DUAL');
413
+ setTimeout(() => this.keepAlive(), globalThis[_MysqlKeepAliveTime] ?? 30000);
412
414
  }
413
415
  createConnection(sync) {
414
416
  if (sync === SyncMode.Sync) {
@@ -704,11 +706,6 @@ export class Postgresql {
704
706
  constructor(pool) {
705
707
  this[_daoDB] = pool;
706
708
  }
707
- async keepAlive() {
708
- const connection = await this[_daoDB].connect();
709
- connection.query('SELECT 1');
710
- setTimeout(async () => await this.keepAlive(), 60000);
711
- }
712
709
  createConnection(sync) {
713
710
  if (sync === SyncMode.Sync) {
714
711
  globalThis[_LoggerService].error('Postgresql not suppouted sync mode');