baja-lite 1.0.16 → 1.0.20

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.
@@ -1,2 +1,3 @@
1
1
  import { GlobalSqlOptionForWeb } from './sql';
2
2
  export declare const BootRomote: (options: GlobalSqlOptionForWeb) => Promise<void>;
3
+ export declare const AppendRomote: (dbName: string) => Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BootRomote = void 0;
3
+ exports.AppendRomote = exports.BootRomote = void 0;
4
4
  const enum_1 = require("./enum");
5
5
  const sql_1 = require("./sql");
6
6
  const BootRomote = async function (options) {
@@ -17,7 +17,7 @@ const BootRomote = async function (options) {
17
17
  if (options.enums) {
18
18
  globalThis[sql_1._enums] = (0, enum_1.getEnums)(options.enums);
19
19
  }
20
- if (options.SqliteRemote) {
20
+ if (options.SqliteRemote && options.SqliteRemote.db) {
21
21
  if (typeof options.SqliteRemote.db === 'string') {
22
22
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
23
23
  globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = new sql_1.SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
@@ -37,3 +37,14 @@ const BootRomote = async function (options) {
37
37
  }
38
38
  };
39
39
  exports.BootRomote = BootRomote;
40
+ const AppendRomote = async function (dbName) {
41
+ if (!globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][dbName]) {
42
+ await globalThis[sql_1._GlobalSqlOption].SqliteRemote.service.initDB(dbName);
43
+ const db = new sql_1.SqliteRemote(globalThis[sql_1._GlobalSqlOption].SqliteRemote.service, dbName);
44
+ if (globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] === undefined) {
45
+ globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = db;
46
+ }
47
+ globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][dbName] = db;
48
+ }
49
+ };
50
+ exports.AppendRomote = AppendRomote;
package/cjs/boot.js CHANGED
@@ -92,7 +92,7 @@ const Boot = async function (options) {
92
92
  }
93
93
  }
94
94
  }
95
- if (options.SqliteRemote) {
95
+ if (options.SqliteRemote && options.SqliteRemote.db) {
96
96
  if (typeof options.SqliteRemote.db === 'string') {
97
97
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
98
98
  globalThis[sql_1._dao][sql_1.DBType.SqliteRemote][sql_1._primaryDB] = new sql_1.SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
package/cjs/sql.d.ts CHANGED
@@ -259,7 +259,7 @@ export interface GlobalSqlOptionForWeb {
259
259
  ```
260
260
  不支持 `SqliteMemory`
261
261
  */
262
- db: Record<string, string> | string;
262
+ db?: Record<string, string> | string;
263
263
  /** 远程SQLITE接口实现,适用于Electron, 采用Ipc 的handel机制实现 */
264
264
  service: SqliteRemoteInterface;
265
265
  };
@@ -1684,9 +1684,15 @@ declare class StreamQuery<T extends object> {
1684
1684
  }): PageQuery<L> | Promise<PageQuery<L>>;
1685
1685
  excuteUpdate(option?: MethodOption & {
1686
1686
  sync?: SyncMode.Async;
1687
+ skipUndefined?: boolean;
1688
+ skipNull?: boolean;
1689
+ skipEmptyString?: boolean;
1687
1690
  }): Promise<number>;
1688
1691
  excuteUpdate(option: MethodOption & {
1689
1692
  sync: SyncMode.Sync;
1693
+ skipUndefined?: boolean;
1694
+ skipNull?: boolean;
1695
+ skipEmptyString?: boolean;
1690
1696
  }): number;
1691
1697
  excuteDelete(option?: MethodOption & {
1692
1698
  sync?: SyncMode.Async;
package/cjs/sql.js CHANGED
@@ -1136,7 +1136,7 @@ class Build {
1136
1136
  datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b, c) => b.toUpperCase())}`;
1137
1137
  }
1138
1138
  }
1139
- return datas.join(',');
1139
+ return ` ${datas.join(',')} `;
1140
1140
  };
1141
1141
  }
1142
1142
  /**
@@ -1950,9 +1950,6 @@ const Field = (config) => {
1950
1950
  if (hasDef) {
1951
1951
  __def[propertyName] = field.def;
1952
1952
  }
1953
- if (field.comment) {
1954
- __def[propertyName] = field.comment;
1955
- }
1956
1953
  Reflect.defineMetadata(_fields, __fields, object);
1957
1954
  Reflect.defineMetadata(_columns, __columns, object);
1958
1955
  Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
@@ -2785,26 +2782,20 @@ class SqlService {
2785
2782
  const params = [];
2786
2783
  const sql = (0, sql_formatter_1.formatDialect)(option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
2787
2784
  let V = (0, lodash_get_1.default)(_params, key);
2788
- if (V) {
2789
- if (V !== undefined) {
2790
- params.push(V);
2791
- }
2785
+ if (V !== undefined) {
2786
+ params.push(V);
2792
2787
  return '?';
2793
2788
  }
2794
2789
  const _key = (0, object_1.C2P)(key);
2795
2790
  V = (0, lodash_get_1.default)(_params, _key);
2796
- if (V) {
2797
- if (V !== undefined) {
2798
- params.push(V);
2799
- }
2791
+ if (V !== undefined) {
2792
+ params.push(V);
2800
2793
  return '?';
2801
2794
  }
2802
2795
  const __key = (0, object_1.P2C)(key);
2803
2796
  V = (0, lodash_get_1.default)(_params, __key);
2804
- if (V) {
2805
- if (V !== undefined) {
2806
- params.push(V);
2807
- }
2797
+ if (V !== undefined) {
2798
+ params.push(V);
2808
2799
  return '?';
2809
2800
  }
2810
2801
  return txt;
@@ -2832,26 +2823,20 @@ class SqlService {
2832
2823
  const params = [];
2833
2824
  const sql = (0, sql_formatter_1.formatDialect)(option.sql?.replace(/\:(\w+)/g, (txt, key) => {
2834
2825
  let V = (0, lodash_get_1.default)(_params, key);
2835
- if (V) {
2836
- if (V !== undefined) {
2837
- params.push(V);
2838
- }
2826
+ if (V !== undefined) {
2827
+ params.push(V);
2839
2828
  return '?';
2840
2829
  }
2841
2830
  const _key = (0, object_1.C2P)(key);
2842
2831
  V = (0, lodash_get_1.default)(_params, _key);
2843
- if (V) {
2844
- if (V !== undefined) {
2845
- params.push(V);
2846
- }
2832
+ if (V !== undefined) {
2833
+ params.push(V);
2847
2834
  return '?';
2848
2835
  }
2849
2836
  const __key = (0, object_1.P2C)(key);
2850
2837
  V = (0, lodash_get_1.default)(_params, __key);
2851
- if (V) {
2852
- if (V !== undefined) {
2853
- params.push(V);
2854
- }
2838
+ if (V !== undefined) {
2839
+ params.push(V);
2855
2840
  return '?';
2856
2841
  }
2857
2842
  return txt;
@@ -3525,11 +3510,11 @@ class StreamQuery {
3525
3510
  return this;
3526
3511
  }
3527
3512
  groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3528
- groupBy2(...keys) { this._groups.push(...keys); return this; }
3513
+ groupBy2(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3529
3514
  asc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3530
- asc2(...keys) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
3515
+ asc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3531
3516
  desc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`)); return this; }
3532
- desc2(...keys) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
3517
+ desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3533
3518
  limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
3534
3519
  page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
3535
3520
  table(_table) { this._table = _table; return this; }
@@ -3551,9 +3536,16 @@ class StreamQuery {
3551
3536
  }
3552
3537
  select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
3553
3538
  select2(sql, param) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
3554
- update(key, value) { this._updates ?? (this._updates = {}); this._updates[key] = value; return this; }
3539
+ update(key, value) { this._updates ?? (this._updates = {}); this._updates[this[_fields][String(key)]?.C2()] = value; return this; }
3555
3540
  update2(sql, param) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
3556
- updateT(t) { this._updates ?? (this._updates = {}); Object.assign(this._updates, t); return this; }
3541
+ updateT(t) {
3542
+ this._updates ?? (this._updates = {});
3543
+ for (const [key, value] of Object.entries(t)) {
3544
+ this._updates[this[_fields][String(key)]?.C2()] = value;
3545
+ }
3546
+ Object.assign(this._updates, t);
3547
+ return this;
3548
+ }
3557
3549
  replace(key, valueToFind, valueToReplace) {
3558
3550
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
3559
3551
  this._updateColumns.push(` ${this[_fields][String(key)]?.C2()} = REPLACE(${this[_fields][String(key)]?.C2()}, :${pkey1}, :${pkey2}) `);
@@ -3708,10 +3700,10 @@ class StreamQuery {
3708
3700
  ${where}
3709
3701
  `;
3710
3702
  if (option.sync === SyncMode.Async) {
3711
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3703
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3712
3704
  }
3713
3705
  else {
3714
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3706
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3715
3707
  }
3716
3708
  }
3717
3709
  else {
@@ -3727,10 +3719,10 @@ class StreamQuery {
3727
3719
  ${where}
3728
3720
  `;
3729
3721
  if (option.sync === SyncMode.Async) {
3730
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3722
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3731
3723
  }
3732
3724
  else {
3733
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3725
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3734
3726
  }
3735
3727
  }
3736
3728
  _where() {
@@ -1,2 +1,3 @@
1
1
  import { GlobalSqlOptionForWeb } from './sql';
2
2
  export declare const BootRomote: (options: GlobalSqlOptionForWeb) => Promise<void>;
3
+ export declare const AppendRomote: (dbName: string) => Promise<void>;
package/es/boot-remote.js CHANGED
@@ -14,7 +14,7 @@ export const BootRomote = async function (options) {
14
14
  if (options.enums) {
15
15
  globalThis[_enums] = getEnums(options.enums);
16
16
  }
17
- if (options.SqliteRemote) {
17
+ if (options.SqliteRemote && options.SqliteRemote.db) {
18
18
  if (typeof options.SqliteRemote.db === 'string') {
19
19
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
20
20
  globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
@@ -33,3 +33,13 @@ export const BootRomote = async function (options) {
33
33
  }
34
34
  }
35
35
  };
36
+ export const AppendRomote = async function (dbName) {
37
+ if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
38
+ await globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
39
+ const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
40
+ if (globalThis[_dao][DBType.SqliteRemote][_primaryDB] === undefined) {
41
+ globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
42
+ }
43
+ globalThis[_dao][DBType.SqliteRemote][dbName] = db;
44
+ }
45
+ };
package/es/boot.js CHANGED
@@ -66,7 +66,7 @@ export const Boot = async function (options) {
66
66
  }
67
67
  }
68
68
  }
69
- if (options.SqliteRemote) {
69
+ if (options.SqliteRemote && options.SqliteRemote.db) {
70
70
  if (typeof options.SqliteRemote.db === 'string') {
71
71
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
72
72
  globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
package/es/sql.d.ts CHANGED
@@ -259,7 +259,7 @@ export interface GlobalSqlOptionForWeb {
259
259
  ```
260
260
  不支持 `SqliteMemory`
261
261
  */
262
- db: Record<string, string> | string;
262
+ db?: Record<string, string> | string;
263
263
  /** 远程SQLITE接口实现,适用于Electron, 采用Ipc 的handel机制实现 */
264
264
  service: SqliteRemoteInterface;
265
265
  };
@@ -1684,9 +1684,15 @@ declare class StreamQuery<T extends object> {
1684
1684
  }): PageQuery<L> | Promise<PageQuery<L>>;
1685
1685
  excuteUpdate(option?: MethodOption & {
1686
1686
  sync?: SyncMode.Async;
1687
+ skipUndefined?: boolean;
1688
+ skipNull?: boolean;
1689
+ skipEmptyString?: boolean;
1687
1690
  }): Promise<number>;
1688
1691
  excuteUpdate(option: MethodOption & {
1689
1692
  sync: SyncMode.Sync;
1693
+ skipUndefined?: boolean;
1694
+ skipNull?: boolean;
1695
+ skipEmptyString?: boolean;
1690
1696
  }): number;
1691
1697
  excuteDelete(option?: MethodOption & {
1692
1698
  sync?: SyncMode.Async;
package/es/sql.js CHANGED
@@ -1093,7 +1093,7 @@ class Build {
1093
1093
  datas[i] = `${datas[i]} ${datas[i].replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b, c) => b.toUpperCase())}`;
1094
1094
  }
1095
1095
  }
1096
- return datas.join(',');
1096
+ return ` ${datas.join(',')} `;
1097
1097
  };
1098
1098
  }
1099
1099
  /**
@@ -1906,9 +1906,6 @@ export const Field = (config) => {
1906
1906
  if (hasDef) {
1907
1907
  __def[propertyName] = field.def;
1908
1908
  }
1909
- if (field.comment) {
1910
- __def[propertyName] = field.comment;
1911
- }
1912
1909
  Reflect.defineMetadata(_fields, __fields, object);
1913
1910
  Reflect.defineMetadata(_columns, __columns, object);
1914
1911
  Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
@@ -2739,26 +2736,20 @@ export class SqlService {
2739
2736
  const params = [];
2740
2737
  const sql = formatDialect(option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
2741
2738
  let V = LGet(_params, key);
2742
- if (V) {
2743
- if (V !== undefined) {
2744
- params.push(V);
2745
- }
2739
+ if (V !== undefined) {
2740
+ params.push(V);
2746
2741
  return '?';
2747
2742
  }
2748
2743
  const _key = C2P(key);
2749
2744
  V = LGet(_params, _key);
2750
- if (V) {
2751
- if (V !== undefined) {
2752
- params.push(V);
2753
- }
2745
+ if (V !== undefined) {
2746
+ params.push(V);
2754
2747
  return '?';
2755
2748
  }
2756
2749
  const __key = P2C(key);
2757
2750
  V = LGet(_params, __key);
2758
- if (V) {
2759
- if (V !== undefined) {
2760
- params.push(V);
2761
- }
2751
+ if (V !== undefined) {
2752
+ params.push(V);
2762
2753
  return '?';
2763
2754
  }
2764
2755
  return txt;
@@ -2786,26 +2777,20 @@ export class SqlService {
2786
2777
  const params = [];
2787
2778
  const sql = formatDialect(option.sql?.replace(/\:(\w+)/g, (txt, key) => {
2788
2779
  let V = LGet(_params, key);
2789
- if (V) {
2790
- if (V !== undefined) {
2791
- params.push(V);
2792
- }
2780
+ if (V !== undefined) {
2781
+ params.push(V);
2793
2782
  return '?';
2794
2783
  }
2795
2784
  const _key = C2P(key);
2796
2785
  V = LGet(_params, _key);
2797
- if (V) {
2798
- if (V !== undefined) {
2799
- params.push(V);
2800
- }
2786
+ if (V !== undefined) {
2787
+ params.push(V);
2801
2788
  return '?';
2802
2789
  }
2803
2790
  const __key = P2C(key);
2804
2791
  V = LGet(_params, __key);
2805
- if (V) {
2806
- if (V !== undefined) {
2807
- params.push(V);
2808
- }
2792
+ if (V !== undefined) {
2793
+ params.push(V);
2809
2794
  return '?';
2810
2795
  }
2811
2796
  return txt;
@@ -3478,11 +3463,11 @@ class StreamQuery {
3478
3463
  return this;
3479
3464
  }
3480
3465
  groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3481
- groupBy2(...keys) { this._groups.push(...keys); return this; }
3466
+ groupBy2(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3482
3467
  asc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3483
- asc2(...keys) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
3468
+ asc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3484
3469
  desc(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} DESC`)); return this; }
3485
- desc2(...keys) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
3470
+ desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3486
3471
  limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
3487
3472
  page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
3488
3473
  table(_table) { this._table = _table; return this; }
@@ -3504,9 +3489,16 @@ class StreamQuery {
3504
3489
  }
3505
3490
  select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
3506
3491
  select2(sql, param) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
3507
- update(key, value) { this._updates ?? (this._updates = {}); this._updates[key] = value; return this; }
3492
+ update(key, value) { this._updates ?? (this._updates = {}); this._updates[this[_fields][String(key)]?.C2()] = value; return this; }
3508
3493
  update2(sql, param) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
3509
- updateT(t) { this._updates ?? (this._updates = {}); Object.assign(this._updates, t); return this; }
3494
+ updateT(t) {
3495
+ this._updates ?? (this._updates = {});
3496
+ for (const [key, value] of Object.entries(t)) {
3497
+ this._updates[this[_fields][String(key)]?.C2()] = value;
3498
+ }
3499
+ Object.assign(this._updates, t);
3500
+ return this;
3501
+ }
3510
3502
  replace(key, valueToFind, valueToReplace) {
3511
3503
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
3512
3504
  this._updateColumns.push(` ${this[_fields][String(key)]?.C2()} = REPLACE(${this[_fields][String(key)]?.C2()}, :${pkey1}, :${pkey2}) `);
@@ -3661,10 +3653,10 @@ class StreamQuery {
3661
3653
  ${where}
3662
3654
  `;
3663
3655
  if (option.sync === SyncMode.Async) {
3664
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3656
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3665
3657
  }
3666
3658
  else {
3667
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3659
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3668
3660
  }
3669
3661
  }
3670
3662
  else {
@@ -3680,10 +3672,10 @@ class StreamQuery {
3680
3672
  ${where}
3681
3673
  `;
3682
3674
  if (option.sync === SyncMode.Async) {
3683
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3675
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3684
3676
  }
3685
3677
  else {
3686
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3678
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3687
3679
  }
3688
3680
  }
3689
3681
  _where() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.0.16",
3
+ "version": "1.0.20",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
@@ -41,17 +41,17 @@
41
41
  "pino": "9.3.2",
42
42
  "pino-pretty": "11.2.2",
43
43
  "reflect-metadata": "0.2.2",
44
- "sql-formatter": "15.3.2",
44
+ "sql-formatter": "15.4.0",
45
45
  "sqlstring": "2.3.3",
46
46
  "tslib": "2.6.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/better-sqlite3": "7.6.11",
50
50
  "@types/mustache": "4.2.5",
51
- "@types/node": "22.0.3",
51
+ "@types/node": "20.14.14",
52
52
  "@types/sqlstring": "2.3.2",
53
- "@typescript-eslint/eslint-plugin": "8.0.0",
54
- "@typescript-eslint/parser": "8.0.0",
53
+ "@typescript-eslint/eslint-plugin": "8.1.0",
54
+ "@typescript-eslint/parser": "8.1.0",
55
55
  "better-sqlite3": "11.1.2",
56
56
  "ioredis": "5.4.1",
57
57
  "mongodb": "6.8.0",
@@ -15,7 +15,7 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
15
15
  if (options.enums) {
16
16
  globalThis[_enums] = getEnums(options.enums);
17
17
  }
18
- if (options.SqliteRemote) {
18
+ if (options.SqliteRemote && options.SqliteRemote.db) {
19
19
  if (typeof options.SqliteRemote.db === 'string') {
20
20
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
21
21
  globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
@@ -33,3 +33,14 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
33
33
  }
34
34
  }
35
35
  }
36
+
37
+ export const AppendRomote = async function (dbName: string) {
38
+ if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
39
+ await globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
40
+ const db = new SqliteRemote(globalThis[_GlobalSqlOption].SqliteRemote.service, dbName);
41
+ if (globalThis[_dao][DBType.SqliteRemote][_primaryDB] === undefined) {
42
+ globalThis[_dao][DBType.SqliteRemote][_primaryDB] = db;
43
+ }
44
+ globalThis[_dao][DBType.SqliteRemote][dbName] = db;
45
+ }
46
+ }
package/src/boot.ts CHANGED
@@ -65,7 +65,7 @@ export const Boot = async function (options: GlobalSqlOption) {
65
65
  }
66
66
  }
67
67
  }
68
- if (options.SqliteRemote) {
68
+ if (options.SqliteRemote && options.SqliteRemote.db) {
69
69
  if (typeof options.SqliteRemote.db === 'string') {
70
70
  await options.SqliteRemote.service.initDB(options.SqliteRemote.db);
71
71
  globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
@@ -130,4 +130,4 @@ export const Boot = async function (options: GlobalSqlOption) {
130
130
  });
131
131
  globalThis[_EventBus] = event;
132
132
  }
133
- }
133
+ }
package/src/sql.ts CHANGED
@@ -319,7 +319,7 @@ export interface GlobalSqlOptionForWeb {
319
319
  ```
320
320
  不支持 `SqliteMemory`
321
321
  */
322
- db: Record<string, string> | string,
322
+ db?: Record<string, string> | string,
323
323
  /** 远程SQLITE接口实现,适用于Electron, 采用Ipc 的handel机制实现 */
324
324
  service: SqliteRemoteInterface
325
325
  },
@@ -1470,7 +1470,7 @@ class Build {
1470
1470
  datas[i] = `${datas[i]} ${datas[i]!.replace(/[a-zA-Z0-9]+\./, '').replace(/_([a-z])/g, (a, b, c) => b.toUpperCase())}`;
1471
1471
  }
1472
1472
  }
1473
- return datas.join(',');
1473
+ return ` ${datas.join(',')} `;
1474
1474
  };
1475
1475
  }
1476
1476
  /**
@@ -2269,9 +2269,6 @@ export const Field = (config: FieldOption) => {
2269
2269
  if (hasDef) {
2270
2270
  __def[propertyName] = field.def;
2271
2271
  }
2272
- if (field.comment) {
2273
- __def[propertyName] = field.comment;
2274
- }
2275
2272
  Reflect.defineMetadata(_fields, __fields, object);
2276
2273
  Reflect.defineMetadata(_columns, __columns, object);
2277
2274
  Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
@@ -3268,26 +3265,20 @@ export class SqlService<T extends object> {
3268
3265
  const params: any[] = [];
3269
3266
  const sql = formatDialect(option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
3270
3267
  let V = LGet(_params, key);
3271
- if (V) {
3272
- if (V !== undefined) {
3273
- params.push(V);
3274
- }
3268
+ if (V !== undefined) {
3269
+ params.push(V);
3275
3270
  return '?';
3276
3271
  }
3277
3272
  const _key = C2P(key);
3278
3273
  V = LGet(_params, _key);
3279
- if (V) {
3280
- if (V !== undefined) {
3281
- params.push(V);
3282
- }
3274
+ if (V !== undefined) {
3275
+ params.push(V);
3283
3276
  return '?';
3284
3277
  }
3285
3278
  const __key = P2C(key);
3286
3279
  V = LGet(_params, __key);
3287
- if (V) {
3288
- if (V !== undefined) {
3289
- params.push(V);
3290
- }
3280
+ if (V !== undefined) {
3281
+ params.push(V);
3291
3282
  return '?';
3292
3283
  }
3293
3284
  return txt;
@@ -3332,26 +3323,20 @@ export class SqlService<T extends object> {
3332
3323
  const params: any[] = [];
3333
3324
  const sql = formatDialect(option.sql?.replace(/\:(\w+)/g, (txt, key) => {
3334
3325
  let V = LGet(_params, key);
3335
- if (V) {
3336
- if (V !== undefined) {
3337
- params.push(V);
3338
- }
3326
+ if (V !== undefined) {
3327
+ params.push(V);
3339
3328
  return '?';
3340
3329
  }
3341
3330
  const _key = C2P(key);
3342
3331
  V = LGet(_params, _key);
3343
- if (V) {
3344
- if (V !== undefined) {
3345
- params.push(V);
3346
- }
3332
+ if (V !== undefined) {
3333
+ params.push(V);
3347
3334
  return '?';
3348
3335
  }
3349
3336
  const __key = P2C(key);
3350
3337
  V = LGet(_params, __key);
3351
- if (V) {
3352
- if (V !== undefined) {
3353
- params.push(V);
3354
- }
3338
+ if (V !== undefined) {
3339
+ params.push(V);
3355
3340
  return '?';
3356
3341
  }
3357
3342
  return txt;
@@ -4059,15 +4044,15 @@ class StreamQuery<T extends object> {
4059
4044
  @IF_PROCEED<T>()
4060
4045
  groupBy(...keys: (keyof T)[]) { this._groups.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()}`)); return this; }
4061
4046
  @IF_PROCEED<T>()
4062
- groupBy2(...keys: string[]) { this._groups.push(...keys); return this; }
4047
+ groupBy2(...keys: string[]) { this._groups.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()}`)); return this; }
4063
4048
  @IF_PROCEED<T>()
4064
4049
  asc(...keys: (keyof T)[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} ASC`)); return this; }
4065
4050
  @IF_PROCEED<T>()
4066
- asc2(...keys: string[]) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
4051
+ asc2(...keys: string[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} ASC`)); return this; }
4067
4052
  @IF_PROCEED<T>()
4068
4053
  desc(...keys: (keyof T)[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} DESC`)); return this; }
4069
4054
  @IF_PROCEED<T>()
4070
- desc2(...keys: string[]) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
4055
+ desc2(...keys: string[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} ASC`)); return this; }
4071
4056
  @IF_PROCEED<T>()
4072
4057
  limit(startRow: number, pageSize: number) { this._startRow = startRow; this._pageSize = pageSize; return this; }
4073
4058
  @IF_PROCEED<T>()
@@ -4103,11 +4088,18 @@ class StreamQuery<T extends object> {
4103
4088
  @IF_PROCEED<T>()
4104
4089
  select2(sql: string, param?: Record<string, any>) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
4105
4090
  @IF_PROCEED<T>()
4106
- update(key: keyof T, value: T[keyof T]) { this._updates ??= {}; this._updates[key] = value; return this; }
4091
+ update(key: keyof T, value: T[keyof T]) { this._updates ??= {}; this._updates[this[_fields]![String(key)]?.C2()!] = value; return this; }
4107
4092
  @IF_PROCEED<T>()
4108
4093
  update2(sql: string, param?: Record<string, any>) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
4109
4094
  @IF_PROCEED<T>()
4110
- updateT(t: Partial<T>) { this._updates ??= {}; Object.assign(this._updates, t); return this; }
4095
+ updateT(t: Partial<T>) {
4096
+ this._updates ??= {};
4097
+ for (const [key, value] of Object.entries(t)) {
4098
+ this._updates[this[_fields]![String(key)]?.C2()!] = value;
4099
+ }
4100
+ Object.assign(this._updates, t);
4101
+ return this;
4102
+ }
4111
4103
  @IF_PROCEED<T>()
4112
4104
  replace(key: keyof T, valueToFind: T[keyof T], valueToReplace: T[keyof T]) {
4113
4105
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
@@ -4252,10 +4244,10 @@ class StreamQuery<T extends object> {
4252
4244
  });
4253
4245
  }
4254
4246
  }
4255
- excuteUpdate(option?: MethodOption & { sync?: SyncMode.Async }): Promise<number>;
4256
- excuteUpdate(option: MethodOption & { sync: SyncMode.Sync }): number;
4247
+ excuteUpdate(option?: MethodOption & { sync?: SyncMode.Async; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; }): Promise<number>;
4248
+ excuteUpdate(option: MethodOption & { sync: SyncMode.Sync; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; }): number;
4257
4249
  @IF_EXEC<T>(0)
4258
- excuteUpdate(option?: MethodOption & { sync?: SyncMode }): number | Promise<number> {
4250
+ excuteUpdate(option?: MethodOption & { sync?: SyncMode; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; }): number | Promise<number> {
4259
4251
  option ??= {};
4260
4252
  option.sync ??= SyncMode.Async;
4261
4253
  const { where, params } = this._where();
@@ -4273,9 +4265,9 @@ class StreamQuery<T extends object> {
4273
4265
  ${where}
4274
4266
  `;
4275
4267
  if (option.sync === SyncMode.Async) {
4276
- return this._service.excute({ sync: SyncMode.Async, sql, params });
4268
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
4277
4269
  } else {
4278
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
4270
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
4279
4271
  }
4280
4272
  } else {
4281
4273
  return 0;
@@ -4293,9 +4285,9 @@ class StreamQuery<T extends object> {
4293
4285
  ${where}
4294
4286
  `;
4295
4287
  if (option.sync === SyncMode.Async) {
4296
- return this._service.excute({ sync: SyncMode.Async, sql, params });
4288
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
4297
4289
  } else {
4298
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
4290
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
4299
4291
  }
4300
4292
  }
4301
4293
  private _where() {