baja-lite 1.7.5 → 1.7.7

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 +3 -3
  3. package/sql.d.ts +5 -1
  4. package/sql.js +5 -9
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.5",
3
+ "version": "1.7.7",
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",
@@ -60,6 +59,7 @@
60
59
  "@types/sqlstring": "2.3.2",
61
60
  "@typescript-eslint/eslint-plugin": "8.57.2",
62
61
  "@typescript-eslint/parser": "8.57.2",
62
+ "axios": "1.14.0",
63
63
  "better-sqlite3": "12.8.0",
64
64
  "ioredis": "5.10.1",
65
65
  "mongodb": "7.1.1",
@@ -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');
@@ -407,9 +408,10 @@ export class Mysql {
407
408
  this.keepAlive();
408
409
  }
409
410
  async keepAlive() {
410
- const connection = await this[_daoDB].getConnection();
411
- connection.query('SELECT 1 FROM DUAL');
412
- setTimeout(async () => await this.keepAlive(), 60000);
411
+ const connection = await this.createConnection(SyncMode.Async);
412
+ const data = await connection?.query(SyncMode.Async, 'SELECT 1 FROM DUAL');
413
+ globalThis[_LoggerService].debug?.('keepAlive->', data?.[0]?.[1]);
414
+ setTimeout(() => this.keepAlive(), globalThis[_MysqlKeepAliveTime] ?? 30000);
413
415
  }
414
416
  createConnection(sync) {
415
417
  if (sync === SyncMode.Sync) {
@@ -704,12 +706,6 @@ _c = _inTransaction;
704
706
  export class Postgresql {
705
707
  constructor(pool) {
706
708
  this[_daoDB] = pool;
707
- this.keepAlive();
708
- }
709
- async keepAlive() {
710
- const connection = await this[_daoDB].connect();
711
- connection.query('SELECT 1');
712
- setTimeout(async () => await this.keepAlive(), 60000);
713
709
  }
714
710
  createConnection(sync) {
715
711
  if (sync === SyncMode.Sync) {