baja-lite 1.0.25 → 1.0.26

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/cjs/sql.d.ts CHANGED
@@ -21,7 +21,7 @@ declare const _def: unique symbol;
21
21
  declare const _comment: unique symbol;
22
22
  export declare const _sqlCache: unique symbol;
23
23
  export declare const _dao: unique symbol;
24
- export declare const _primaryDB: unique symbol;
24
+ export declare const _primaryDB = "______primaryDB_______";
25
25
  declare const _dbType: unique symbol;
26
26
  declare const _formatDialect: unique symbol;
27
27
  declare const _sqlite_version: unique symbol;
@@ -485,11 +485,11 @@ export interface PageQuery<L> {
485
485
  }
486
486
  /** sqlite electron服务端需要支持的接口 */
487
487
  export interface SqliteRemoteInterface {
488
- execute(inData: Uint8Array): Uint8Array;
489
- pluck(inData: Uint8Array): Uint8Array;
490
- get(inData: Uint8Array): Uint8Array;
491
- raw(inData: Uint8Array): Uint8Array;
492
- query(inData: Uint8Array): Uint8Array;
488
+ execute(inData: Uint8Array): Promise<Uint8Array>;
489
+ pluck(inData: Uint8Array): Promise<Uint8Array>;
490
+ get(inData: Uint8Array): Promise<Uint8Array>;
491
+ raw(inData: Uint8Array): Promise<Uint8Array>;
492
+ query(inData: Uint8Array): Promise<Uint8Array>;
493
493
  initDB(dbName: string): void;
494
494
  export(dbName: string, exportPath: string): Promise<void>;
495
495
  restore(dbName: string, importPath: string): void;
package/cjs/sql.js CHANGED
@@ -109,7 +109,7 @@ const _def = Symbol('def');
109
109
  const _comment = Symbol('comment');
110
110
  exports._sqlCache = Symbol('sqlMap');
111
111
  exports._dao = Symbol('dao');
112
- exports._primaryDB = Symbol('primaryDB');
112
+ exports._primaryDB = '______primaryDB_______';
113
113
  const _dbType = Symbol('dbType');
114
114
  const _formatDialect = Symbol('FormatDialect');
115
115
  const _sqlite_version = Symbol('sqlite_version');
@@ -1543,12 +1543,14 @@ function P(skipConn = false) {
1543
1543
  const dbName = option?.dbName ?? this[_daoDBName] ?? exports._primaryDB;
1544
1544
  option.dao = globalThis[exports._dao][this[_dbType]][dbName];
1545
1545
  if (this[_dbType] === DBType.Sqlite) {
1546
- const db = new Sqlite(new globalThis[exports._GlobalSqlOption].BetterSqlite3(dbName, { fileMustExist: false }));
1547
- if (globalThis[exports._dao][this[_dbType]][exports._primaryDB] === undefined) {
1548
- globalThis[exports._dao][this[_dbType]][exports._primaryDB] = db;
1546
+ if (!option.dao) {
1547
+ const db = new Sqlite(new globalThis[exports._GlobalSqlOption].BetterSqlite3(dbName, { fileMustExist: false }));
1548
+ if (globalThis[exports._dao][this[_dbType]][exports._primaryDB] === undefined) {
1549
+ globalThis[exports._dao][this[_dbType]][exports._primaryDB] = db;
1550
+ }
1551
+ globalThis[exports._dao][this[_dbType]][dbName] = db;
1552
+ option.dao = db;
1549
1553
  }
1550
- globalThis[exports._dao][this[_dbType]][dbName] = db;
1551
- option.dao = db;
1552
1554
  error_1.Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!');
1553
1555
  // 连接共享
1554
1556
  if (skipConn === false && !option.conn) {
@@ -1581,13 +1583,15 @@ function P(skipConn = false) {
1581
1583
  }
1582
1584
  }
1583
1585
  else if (this[_dbType] === DBType.SqliteRemote) {
1584
- globalThis[exports._GlobalSqlOption].SqliteRemote.service.initDB(dbName);
1585
- const db = new SqliteRemote(globalThis[exports._GlobalSqlOption].SqliteRemote.service, dbName);
1586
- if (globalThis[exports._dao][this[_dbType]][exports._primaryDB] === undefined) {
1587
- globalThis[exports._dao][this[_dbType]][exports._primaryDB] = db;
1586
+ if (!option.dao) {
1587
+ globalThis[exports._GlobalSqlOption].SqliteRemote.service.initDB(dbName);
1588
+ const db = new SqliteRemote(globalThis[exports._GlobalSqlOption].SqliteRemote.service, dbName);
1589
+ if (globalThis[exports._dao][this[_dbType]][exports._primaryDB] === undefined) {
1590
+ globalThis[exports._dao][this[_dbType]][exports._primaryDB] = db;
1591
+ }
1592
+ globalThis[exports._dao][this[_dbType]][dbName] = db;
1593
+ option.dao = db;
1588
1594
  }
1589
- globalThis[exports._dao][this[_dbType]][dbName] = db;
1590
- option.dao = db;
1591
1595
  error_1.Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!');
1592
1596
  return new Promise(async (resolve, reject) => {
1593
1597
  // 连接共享
package/cjs/sqlite.d.ts CHANGED
@@ -20,11 +20,11 @@ export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface
20
20
  */
21
21
  abstract setMod(name: string): void;
22
22
  abstract trace: boolean;
23
- execute(inData: Uint8Array): Uint8Array;
24
- pluck(inData: Uint8Array): Uint8Array;
25
- get(inData: Uint8Array): Uint8Array;
26
- raw(inData: Uint8Array): Uint8Array;
27
- query(inData: Uint8Array): Uint8Array;
23
+ execute(inData: Uint8Array): Promise<Uint8Array>;
24
+ pluck(inData: Uint8Array): Promise<Uint8Array>;
25
+ get(inData: Uint8Array): Promise<Uint8Array>;
26
+ raw(inData: Uint8Array): Promise<Uint8Array>;
27
+ query(inData: Uint8Array): Promise<Uint8Array>;
28
28
  initDB(dbName: string): void;
29
29
  export(dbName: string, exportPath: string): Promise<void>;
30
30
  restore(dbName: string, importPath: string): void;
package/cjs/sqlite.js CHANGED
@@ -11,7 +11,7 @@ class SqliteRemoteClass {
11
11
  constructor() {
12
12
  this.dbList = {};
13
13
  }
14
- execute(inData) {
14
+ async execute(inData) {
15
15
  const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
16
16
  sql_1.logger.debug(sql, params ?? '');
17
17
  try {
@@ -38,7 +38,7 @@ class SqliteRemoteClass {
38
38
  throw error;
39
39
  }
40
40
  }
41
- pluck(inData) {
41
+ async pluck(inData) {
42
42
  const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
43
43
  sql_1.logger.debug(sql, params ?? '');
44
44
  try {
@@ -61,7 +61,7 @@ class SqliteRemoteClass {
61
61
  throw error;
62
62
  }
63
63
  }
64
- get(inData) {
64
+ async get(inData) {
65
65
  const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
66
66
  sql_1.logger.debug(sql, params ?? '');
67
67
  try {
@@ -79,7 +79,7 @@ class SqliteRemoteClass {
79
79
  throw error;
80
80
  }
81
81
  }
82
- raw(inData) {
82
+ async raw(inData) {
83
83
  const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
84
84
  sql_1.logger.debug(sql, params ?? '');
85
85
  try {
@@ -101,7 +101,7 @@ class SqliteRemoteClass {
101
101
  throw error;
102
102
  }
103
103
  }
104
- query(inData) {
104
+ async query(inData) {
105
105
  const [dbName, sql, params] = (0, msgpack_1.decode)(inData);
106
106
  sql_1.logger.debug(sql, params ?? '');
107
107
  try {
package/es/sql.d.ts CHANGED
@@ -21,7 +21,7 @@ declare const _def: unique symbol;
21
21
  declare const _comment: unique symbol;
22
22
  export declare const _sqlCache: unique symbol;
23
23
  export declare const _dao: unique symbol;
24
- export declare const _primaryDB: unique symbol;
24
+ export declare const _primaryDB = "______primaryDB_______";
25
25
  declare const _dbType: unique symbol;
26
26
  declare const _formatDialect: unique symbol;
27
27
  declare const _sqlite_version: unique symbol;
@@ -485,11 +485,11 @@ export interface PageQuery<L> {
485
485
  }
486
486
  /** sqlite electron服务端需要支持的接口 */
487
487
  export interface SqliteRemoteInterface {
488
- execute(inData: Uint8Array): Uint8Array;
489
- pluck(inData: Uint8Array): Uint8Array;
490
- get(inData: Uint8Array): Uint8Array;
491
- raw(inData: Uint8Array): Uint8Array;
492
- query(inData: Uint8Array): Uint8Array;
488
+ execute(inData: Uint8Array): Promise<Uint8Array>;
489
+ pluck(inData: Uint8Array): Promise<Uint8Array>;
490
+ get(inData: Uint8Array): Promise<Uint8Array>;
491
+ raw(inData: Uint8Array): Promise<Uint8Array>;
492
+ query(inData: Uint8Array): Promise<Uint8Array>;
493
493
  initDB(dbName: string): void;
494
494
  export(dbName: string, exportPath: string): Promise<void>;
495
495
  restore(dbName: string, importPath: string): void;
package/es/sql.js CHANGED
@@ -70,7 +70,7 @@ const _def = Symbol('def');
70
70
  const _comment = Symbol('comment');
71
71
  export const _sqlCache = Symbol('sqlMap');
72
72
  export const _dao = Symbol('dao');
73
- export const _primaryDB = Symbol('primaryDB');
73
+ export const _primaryDB = '______primaryDB_______';
74
74
  const _dbType = Symbol('dbType');
75
75
  const _formatDialect = Symbol('FormatDialect');
76
76
  const _sqlite_version = Symbol('sqlite_version');
@@ -1499,12 +1499,14 @@ function P(skipConn = false) {
1499
1499
  const dbName = option?.dbName ?? this[_daoDBName] ?? _primaryDB;
1500
1500
  option.dao = globalThis[_dao][this[_dbType]][dbName];
1501
1501
  if (this[_dbType] === DBType.Sqlite) {
1502
- const db = new Sqlite(new globalThis[_GlobalSqlOption].BetterSqlite3(dbName, { fileMustExist: false }));
1503
- if (globalThis[_dao][this[_dbType]][_primaryDB] === undefined) {
1504
- globalThis[_dao][this[_dbType]][_primaryDB] = db;
1502
+ if (!option.dao) {
1503
+ const db = new Sqlite(new globalThis[_GlobalSqlOption].BetterSqlite3(dbName, { fileMustExist: false }));
1504
+ if (globalThis[_dao][this[_dbType]][_primaryDB] === undefined) {
1505
+ globalThis[_dao][this[_dbType]][_primaryDB] = db;
1506
+ }
1507
+ globalThis[_dao][this[_dbType]][dbName] = db;
1508
+ option.dao = db;
1505
1509
  }
1506
- globalThis[_dao][this[_dbType]][dbName] = db;
1507
- option.dao = db;
1508
1510
  Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!');
1509
1511
  // 连接共享
1510
1512
  if (skipConn === false && !option.conn) {
@@ -1537,13 +1539,15 @@ function P(skipConn = false) {
1537
1539
  }
1538
1540
  }
1539
1541
  else if (this[_dbType] === DBType.SqliteRemote) {
1540
- globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
1541
- const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
1542
- if (globalThis[_dao][this[_dbType]][_primaryDB] === undefined) {
1543
- globalThis[_dao][this[_dbType]][_primaryDB] = db;
1542
+ if (!option.dao) {
1543
+ globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
1544
+ const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
1545
+ if (globalThis[_dao][this[_dbType]][_primaryDB] === undefined) {
1546
+ globalThis[_dao][this[_dbType]][_primaryDB] = db;
1547
+ }
1548
+ globalThis[_dao][this[_dbType]][dbName] = db;
1549
+ option.dao = db;
1544
1550
  }
1545
- globalThis[_dao][this[_dbType]][dbName] = db;
1546
- option.dao = db;
1547
1551
  Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!');
1548
1552
  return new Promise(async (resolve, reject) => {
1549
1553
  // 连接共享
package/es/sqlite.d.ts CHANGED
@@ -20,11 +20,11 @@ export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface
20
20
  */
21
21
  abstract setMod(name: string): void;
22
22
  abstract trace: boolean;
23
- execute(inData: Uint8Array): Uint8Array;
24
- pluck(inData: Uint8Array): Uint8Array;
25
- get(inData: Uint8Array): Uint8Array;
26
- raw(inData: Uint8Array): Uint8Array;
27
- query(inData: Uint8Array): Uint8Array;
23
+ execute(inData: Uint8Array): Promise<Uint8Array>;
24
+ pluck(inData: Uint8Array): Promise<Uint8Array>;
25
+ get(inData: Uint8Array): Promise<Uint8Array>;
26
+ raw(inData: Uint8Array): Promise<Uint8Array>;
27
+ query(inData: Uint8Array): Promise<Uint8Array>;
28
28
  initDB(dbName: string): void;
29
29
  export(dbName: string, exportPath: string): Promise<void>;
30
30
  restore(dbName: string, importPath: string): void;
package/es/sqlite.js CHANGED
@@ -5,7 +5,7 @@ export class SqliteRemoteClass {
5
5
  constructor() {
6
6
  this.dbList = {};
7
7
  }
8
- execute(inData) {
8
+ async execute(inData) {
9
9
  const [dbName, sql, params] = decode(inData);
10
10
  logger.debug(sql, params ?? '');
11
11
  try {
@@ -32,7 +32,7 @@ export class SqliteRemoteClass {
32
32
  throw error;
33
33
  }
34
34
  }
35
- pluck(inData) {
35
+ async pluck(inData) {
36
36
  const [dbName, sql, params] = decode(inData);
37
37
  logger.debug(sql, params ?? '');
38
38
  try {
@@ -55,7 +55,7 @@ export class SqliteRemoteClass {
55
55
  throw error;
56
56
  }
57
57
  }
58
- get(inData) {
58
+ async get(inData) {
59
59
  const [dbName, sql, params] = decode(inData);
60
60
  logger.debug(sql, params ?? '');
61
61
  try {
@@ -73,7 +73,7 @@ export class SqliteRemoteClass {
73
73
  throw error;
74
74
  }
75
75
  }
76
- raw(inData) {
76
+ async raw(inData) {
77
77
  const [dbName, sql, params] = decode(inData);
78
78
  logger.debug(sql, params ?? '');
79
79
  try {
@@ -95,7 +95,7 @@ export class SqliteRemoteClass {
95
95
  throw error;
96
96
  }
97
97
  }
98
- query(inData) {
98
+ async query(inData) {
99
99
  const [dbName, sql, params] = decode(inData);
100
100
  logger.debug(sql, params ?? '');
101
101
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
package/src/sql.ts CHANGED
@@ -61,7 +61,7 @@ const _def = Symbol('def');
61
61
  const _comment = Symbol('comment');
62
62
  export const _sqlCache = Symbol('sqlMap');
63
63
  export const _dao = Symbol('dao');
64
- export const _primaryDB = Symbol('primaryDB');
64
+ export const _primaryDB = '______primaryDB_______';
65
65
  const _dbType = Symbol('dbType');
66
66
  const _formatDialect = Symbol('FormatDialect');
67
67
  const _sqlite_version = Symbol('sqlite_version');
@@ -551,11 +551,11 @@ export interface PageQuery<L> {
551
551
  // #region 数据方言
552
552
  /** sqlite electron服务端需要支持的接口 */
553
553
  export interface SqliteRemoteInterface {
554
- execute(inData: Uint8Array):Uint8Array;
555
- pluck(inData: Uint8Array):Uint8Array;
556
- get(inData: Uint8Array): Uint8Array;
557
- raw(inData: Uint8Array): Uint8Array;
558
- query(inData: Uint8Array): Uint8Array;
554
+ execute(inData: Uint8Array): Promise<Uint8Array>;
555
+ pluck(inData: Uint8Array): Promise<Uint8Array>;
556
+ get(inData: Uint8Array): Promise<Uint8Array>;
557
+ raw(inData: Uint8Array): Promise<Uint8Array>;
558
+ query(inData: Uint8Array): Promise<Uint8Array>;
559
559
  initDB(dbName: string): void;
560
560
  export(dbName: string, exportPath: string): Promise<void>;
561
561
  restore(dbName: string, importPath: string): void;
@@ -1300,7 +1300,7 @@ export class SqliteRemote implements Dao {
1300
1300
  restore(sync: SyncMode.Async, importPath: string): Promise<void>;
1301
1301
  restore(sync: SyncMode, importPath: string): Promise<void> | void {
1302
1302
  if (sync === SyncMode.Async) {
1303
- return this[_daoDB]?.restore(this[_sqliteRemoteName], importPath, );
1303
+ return this[_daoDB]?.restore(this[_sqliteRemoteName], importPath,);
1304
1304
  };
1305
1305
  }
1306
1306
  }
@@ -1883,12 +1883,14 @@ function P<T extends object>(skipConn = false) {
1883
1883
  option!.dao = globalThis[_dao][this[_dbType]!][dbName] as Dao;
1884
1884
 
1885
1885
  if (this[_dbType] === DBType.Sqlite) {
1886
- const db = new Sqlite(new globalThis[_GlobalSqlOption].BetterSqlite3(dbName as any, { fileMustExist: false }));
1887
- if (globalThis[_dao][this[_dbType]!][_primaryDB] === undefined) {
1888
- globalThis[_dao][this[_dbType]!][_primaryDB] = db;
1886
+ if (!option!.dao) {
1887
+ const db = new Sqlite(new globalThis[_GlobalSqlOption].BetterSqlite3(dbName as any, { fileMustExist: false }));
1888
+ if (globalThis[_dao][this[_dbType]!][_primaryDB] === undefined) {
1889
+ globalThis[_dao][this[_dbType]!][_primaryDB] = db;
1890
+ }
1891
+ globalThis[_dao][this[_dbType]!][dbName] = db;
1892
+ option!.dao = db;
1889
1893
  }
1890
- globalThis[_dao][this[_dbType]!][dbName] = db;
1891
- option!.dao = db;
1892
1894
 
1893
1895
  Throw.if(option.sync === SyncMode.Async, 'sqlite can not Async!')
1894
1896
  // 连接共享
@@ -1917,13 +1919,15 @@ function P<T extends object>(skipConn = false) {
1917
1919
  }
1918
1920
  }
1919
1921
  } else if (this[_dbType] === DBType.SqliteRemote) {
1920
- globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
1921
- const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName as any);
1922
- if (globalThis[_dao][this[_dbType]!][_primaryDB] === undefined) {
1923
- globalThis[_dao][this[_dbType]!][_primaryDB] = db;
1922
+ if (!option!.dao) {
1923
+ globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
1924
+ const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName as any);
1925
+ if (globalThis[_dao][this[_dbType]!][_primaryDB] === undefined) {
1926
+ globalThis[_dao][this[_dbType]!][_primaryDB] = db;
1927
+ }
1928
+ globalThis[_dao][this[_dbType]!][dbName] = db;
1929
+ option!.dao = db;
1924
1930
  }
1925
- globalThis[_dao][this[_dbType]!][dbName] = db;
1926
- option!.dao = db;
1927
1931
 
1928
1932
  Throw.if(option.sync === SyncMode.Sync, 'SqliteRemote remote can not sync!')
1929
1933
  return new Promise(async (resolve, reject) => {
package/src/sqlite.ts CHANGED
@@ -22,7 +22,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
22
22
  */
23
23
  abstract setMod(name: string): void;
24
24
  abstract trace: boolean;
25
- execute(inData: Uint8Array): Uint8Array {
25
+ async execute(inData: Uint8Array): Promise<Uint8Array> {
26
26
  const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
27
27
  logger.debug(sql, params ?? '');
28
28
  try {
@@ -45,7 +45,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
45
45
  throw error;
46
46
  }
47
47
  }
48
- pluck(inData: Uint8Array): Uint8Array {
48
+ async pluck(inData: Uint8Array): Promise<Uint8Array> {
49
49
  const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
50
50
  logger.debug(sql, params ?? '');
51
51
  try {
@@ -64,7 +64,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
64
64
  throw error;
65
65
  }
66
66
  }
67
- get(inData: Uint8Array): Uint8Array {
67
+ async get(inData: Uint8Array): Promise<Uint8Array> {
68
68
  const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
69
69
  logger.debug(sql, params ?? '');
70
70
  try {
@@ -81,7 +81,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
81
81
  throw error;
82
82
  }
83
83
  }
84
- raw(inData: Uint8Array): Uint8Array {
84
+ async raw(inData: Uint8Array): Promise<Uint8Array> {
85
85
  const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
86
86
  logger.debug(sql, params ?? '');
87
87
  try {
@@ -99,7 +99,7 @@ export abstract class SqliteRemoteClass implements SqliteRemoteInterface {
99
99
  throw error;
100
100
  }
101
101
  }
102
- query(inData: Uint8Array): Uint8Array {
102
+ async query(inData: Uint8Array): Promise<Uint8Array> {
103
103
  const [dbName, sql, params] = decode(inData) as [dbName: string, sql?: string | undefined, params?: any];
104
104
  logger.debug(sql, params ?? '');
105
105
  try {