baja-lite 1.0.16 → 1.0.21

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
@@ -1,6 +1,6 @@
1
1
  import { XML } from './convert-xml';
2
2
  import { ArrayList } from './list';
3
- import { EnumMap } from 'enum';
3
+ import { EnumMap } from './enum';
4
4
  import { ExtensionCodec } from "@msgpack/msgpack";
5
5
  export declare const extensionCodec: ExtensionCodec<undefined>;
6
6
  declare const _daoDBName: unique symbol;
@@ -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
  /**
@@ -1675,15 +1675,9 @@ const FieldFilter = (K, V, def, uuidColumn, option) => {
1675
1675
  // 只有在非插入或者非UUID时,进行空置检查
1676
1676
  if (option?.insert === true && uuidColumn === true) {
1677
1677
  ret = 1;
1678
- if (V === undefined) {
1678
+ if (V === undefined || (0, string_1.emptyString)(`${V ?? ''}`)) {
1679
1679
  V = null;
1680
1680
  }
1681
- else if ((0, string_1.emptyString)(`${V ?? ''}`)) {
1682
- V = '';
1683
- }
1684
- else {
1685
- ret = 1;
1686
- }
1687
1681
  }
1688
1682
  else {
1689
1683
  if (V === null) {
@@ -1950,9 +1944,6 @@ const Field = (config) => {
1950
1944
  if (hasDef) {
1951
1945
  __def[propertyName] = field.def;
1952
1946
  }
1953
- if (field.comment) {
1954
- __def[propertyName] = field.comment;
1955
- }
1956
1947
  Reflect.defineMetadata(_fields, __fields, object);
1957
1948
  Reflect.defineMetadata(_columns, __columns, object);
1958
1949
  Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
@@ -2785,26 +2776,20 @@ class SqlService {
2785
2776
  const params = [];
2786
2777
  const sql = (0, sql_formatter_1.formatDialect)(option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
2787
2778
  let V = (0, lodash_get_1.default)(_params, key);
2788
- if (V) {
2789
- if (V !== undefined) {
2790
- params.push(V);
2791
- }
2779
+ if (V !== undefined) {
2780
+ params.push(V);
2792
2781
  return '?';
2793
2782
  }
2794
2783
  const _key = (0, object_1.C2P)(key);
2795
2784
  V = (0, lodash_get_1.default)(_params, _key);
2796
- if (V) {
2797
- if (V !== undefined) {
2798
- params.push(V);
2799
- }
2785
+ if (V !== undefined) {
2786
+ params.push(V);
2800
2787
  return '?';
2801
2788
  }
2802
2789
  const __key = (0, object_1.P2C)(key);
2803
2790
  V = (0, lodash_get_1.default)(_params, __key);
2804
- if (V) {
2805
- if (V !== undefined) {
2806
- params.push(V);
2807
- }
2791
+ if (V !== undefined) {
2792
+ params.push(V);
2808
2793
  return '?';
2809
2794
  }
2810
2795
  return txt;
@@ -2832,26 +2817,20 @@ class SqlService {
2832
2817
  const params = [];
2833
2818
  const sql = (0, sql_formatter_1.formatDialect)(option.sql?.replace(/\:(\w+)/g, (txt, key) => {
2834
2819
  let V = (0, lodash_get_1.default)(_params, key);
2835
- if (V) {
2836
- if (V !== undefined) {
2837
- params.push(V);
2838
- }
2820
+ if (V !== undefined) {
2821
+ params.push(V);
2839
2822
  return '?';
2840
2823
  }
2841
2824
  const _key = (0, object_1.C2P)(key);
2842
2825
  V = (0, lodash_get_1.default)(_params, _key);
2843
- if (V) {
2844
- if (V !== undefined) {
2845
- params.push(V);
2846
- }
2826
+ if (V !== undefined) {
2827
+ params.push(V);
2847
2828
  return '?';
2848
2829
  }
2849
2830
  const __key = (0, object_1.P2C)(key);
2850
2831
  V = (0, lodash_get_1.default)(_params, __key);
2851
- if (V) {
2852
- if (V !== undefined) {
2853
- params.push(V);
2854
- }
2832
+ if (V !== undefined) {
2833
+ params.push(V);
2855
2834
  return '?';
2856
2835
  }
2857
2836
  return txt;
@@ -3525,11 +3504,11 @@ class StreamQuery {
3525
3504
  return this;
3526
3505
  }
3527
3506
  groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3528
- groupBy2(...keys) { this._groups.push(...keys); return this; }
3507
+ groupBy2(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3529
3508
  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; }
3509
+ asc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3531
3510
  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; }
3511
+ desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3533
3512
  limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
3534
3513
  page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
3535
3514
  table(_table) { this._table = _table; return this; }
@@ -3551,9 +3530,16 @@ class StreamQuery {
3551
3530
  }
3552
3531
  select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
3553
3532
  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; }
3533
+ update(key, value) { this._updates ?? (this._updates = {}); this._updates[this[_fields][String(key)]?.C2()] = value; return this; }
3555
3534
  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; }
3535
+ updateT(t) {
3536
+ this._updates ?? (this._updates = {});
3537
+ for (const [key, value] of Object.entries(t)) {
3538
+ this._updates[this[_fields][String(key)]?.C2()] = value;
3539
+ }
3540
+ Object.assign(this._updates, t);
3541
+ return this;
3542
+ }
3557
3543
  replace(key, valueToFind, valueToReplace) {
3558
3544
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
3559
3545
  this._updateColumns.push(` ${this[_fields][String(key)]?.C2()} = REPLACE(${this[_fields][String(key)]?.C2()}, :${pkey1}, :${pkey2}) `);
@@ -3708,10 +3694,10 @@ class StreamQuery {
3708
3694
  ${where}
3709
3695
  `;
3710
3696
  if (option.sync === SyncMode.Async) {
3711
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3697
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3712
3698
  }
3713
3699
  else {
3714
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3700
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3715
3701
  }
3716
3702
  }
3717
3703
  else {
@@ -3727,10 +3713,10 @@ class StreamQuery {
3727
3713
  ${where}
3728
3714
  `;
3729
3715
  if (option.sync === SyncMode.Async) {
3730
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3716
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3731
3717
  }
3732
3718
  else {
3733
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3719
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3734
3720
  }
3735
3721
  }
3736
3722
  _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
@@ -1,6 +1,6 @@
1
1
  import { XML } from './convert-xml';
2
2
  import { ArrayList } from './list';
3
- import { EnumMap } from 'enum';
3
+ import { EnumMap } from './enum';
4
4
  import { ExtensionCodec } from "@msgpack/msgpack";
5
5
  export declare const extensionCodec: ExtensionCodec<undefined>;
6
6
  declare const _daoDBName: unique symbol;
@@ -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
  /**
@@ -1631,15 +1631,9 @@ const FieldFilter = (K, V, def, uuidColumn, option) => {
1631
1631
  // 只有在非插入或者非UUID时,进行空置检查
1632
1632
  if (option?.insert === true && uuidColumn === true) {
1633
1633
  ret = 1;
1634
- if (V === undefined) {
1634
+ if (V === undefined || emptyString(`${V ?? ''}`)) {
1635
1635
  V = null;
1636
1636
  }
1637
- else if (emptyString(`${V ?? ''}`)) {
1638
- V = '';
1639
- }
1640
- else {
1641
- ret = 1;
1642
- }
1643
1637
  }
1644
1638
  else {
1645
1639
  if (V === null) {
@@ -1906,9 +1900,6 @@ export const Field = (config) => {
1906
1900
  if (hasDef) {
1907
1901
  __def[propertyName] = field.def;
1908
1902
  }
1909
- if (field.comment) {
1910
- __def[propertyName] = field.comment;
1911
- }
1912
1903
  Reflect.defineMetadata(_fields, __fields, object);
1913
1904
  Reflect.defineMetadata(_columns, __columns, object);
1914
1905
  Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
@@ -2739,26 +2730,20 @@ export class SqlService {
2739
2730
  const params = [];
2740
2731
  const sql = formatDialect(option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
2741
2732
  let V = LGet(_params, key);
2742
- if (V) {
2743
- if (V !== undefined) {
2744
- params.push(V);
2745
- }
2733
+ if (V !== undefined) {
2734
+ params.push(V);
2746
2735
  return '?';
2747
2736
  }
2748
2737
  const _key = C2P(key);
2749
2738
  V = LGet(_params, _key);
2750
- if (V) {
2751
- if (V !== undefined) {
2752
- params.push(V);
2753
- }
2739
+ if (V !== undefined) {
2740
+ params.push(V);
2754
2741
  return '?';
2755
2742
  }
2756
2743
  const __key = P2C(key);
2757
2744
  V = LGet(_params, __key);
2758
- if (V) {
2759
- if (V !== undefined) {
2760
- params.push(V);
2761
- }
2745
+ if (V !== undefined) {
2746
+ params.push(V);
2762
2747
  return '?';
2763
2748
  }
2764
2749
  return txt;
@@ -2786,26 +2771,20 @@ export class SqlService {
2786
2771
  const params = [];
2787
2772
  const sql = formatDialect(option.sql?.replace(/\:(\w+)/g, (txt, key) => {
2788
2773
  let V = LGet(_params, key);
2789
- if (V) {
2790
- if (V !== undefined) {
2791
- params.push(V);
2792
- }
2774
+ if (V !== undefined) {
2775
+ params.push(V);
2793
2776
  return '?';
2794
2777
  }
2795
2778
  const _key = C2P(key);
2796
2779
  V = LGet(_params, _key);
2797
- if (V) {
2798
- if (V !== undefined) {
2799
- params.push(V);
2800
- }
2780
+ if (V !== undefined) {
2781
+ params.push(V);
2801
2782
  return '?';
2802
2783
  }
2803
2784
  const __key = P2C(key);
2804
2785
  V = LGet(_params, __key);
2805
- if (V) {
2806
- if (V !== undefined) {
2807
- params.push(V);
2808
- }
2786
+ if (V !== undefined) {
2787
+ params.push(V);
2809
2788
  return '?';
2810
2789
  }
2811
2790
  return txt;
@@ -3478,11 +3457,11 @@ class StreamQuery {
3478
3457
  return this;
3479
3458
  }
3480
3459
  groupBy(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3481
- groupBy2(...keys) { this._groups.push(...keys); return this; }
3460
+ groupBy2(...keys) { this._groups.push(...keys.map(key => `${this[_fields][String(key)]?.C2()}`)); return this; }
3482
3461
  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; }
3462
+ asc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3484
3463
  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; }
3464
+ desc2(...keys) { this._orders.push(...keys.map(key => `${this[_fields][String(key)]?.C2()} ASC`)); return this; }
3486
3465
  limit(startRow, pageSize) { this._startRow = startRow; this._pageSize = pageSize; return this; }
3487
3466
  page(pageNumber, pageSize) { this._startRow = ((pageNumber || 1) - 1) * pageSize; this._pageSize = pageSize; return this; }
3488
3467
  table(_table) { this._table = _table; return this; }
@@ -3504,9 +3483,16 @@ class StreamQuery {
3504
3483
  }
3505
3484
  select(...key) { this._columns.push(...(key.map(k => this[_fields][String(k)].C3()))); return this; }
3506
3485
  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; }
3486
+ update(key, value) { this._updates ?? (this._updates = {}); this._updates[this[_fields][String(key)]?.C2()] = value; return this; }
3508
3487
  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; }
3488
+ updateT(t) {
3489
+ this._updates ?? (this._updates = {});
3490
+ for (const [key, value] of Object.entries(t)) {
3491
+ this._updates[this[_fields][String(key)]?.C2()] = value;
3492
+ }
3493
+ Object.assign(this._updates, t);
3494
+ return this;
3495
+ }
3510
3496
  replace(key, valueToFind, valueToReplace) {
3511
3497
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
3512
3498
  this._updateColumns.push(` ${this[_fields][String(key)]?.C2()} = REPLACE(${this[_fields][String(key)]?.C2()}, :${pkey1}, :${pkey2}) `);
@@ -3661,10 +3647,10 @@ class StreamQuery {
3661
3647
  ${where}
3662
3648
  `;
3663
3649
  if (option.sync === SyncMode.Async) {
3664
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3650
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3665
3651
  }
3666
3652
  else {
3667
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3653
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3668
3654
  }
3669
3655
  }
3670
3656
  else {
@@ -3680,10 +3666,10 @@ class StreamQuery {
3680
3666
  ${where}
3681
3667
  `;
3682
3668
  if (option.sync === SyncMode.Async) {
3683
- return this._service.excute({ sync: SyncMode.Async, sql, params });
3669
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3684
3670
  }
3685
3671
  else {
3686
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
3672
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
3687
3673
  }
3688
3674
  }
3689
3675
  _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.21",
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.2.0",
54
+ "@typescript-eslint/parser": "8.2.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
@@ -13,7 +13,7 @@ import HTML from 'html-parse-stringify';
13
13
  import { XML, convert } from './convert-xml';
14
14
  import { ArrayList } from './list';
15
15
  import LGet from 'lodash.get';
16
- import { EnumMap } from 'enum';
16
+ import { EnumMap } from './enum';
17
17
  import { encode, decode, ExtensionCodec, DecodeError } from "@msgpack/msgpack";
18
18
  (BigInt.prototype as any).toJSON = function () { return this.toString() }
19
19
 
@@ -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
  /**
@@ -1998,12 +1998,8 @@ const FieldFilter = (
1998
1998
  // 只有在非插入或者非UUID时,进行空置检查
1999
1999
  if (option?.insert === true && uuidColumn === true) {
2000
2000
  ret = 1;
2001
- if (V === undefined) {
2001
+ if (V === undefined || emptyString(`${V ?? ''}`)) {
2002
2002
  V = null;
2003
- } else if (emptyString(`${V ?? ''}`)) {
2004
- V = '';
2005
- } else {
2006
- ret = 1;
2007
2003
  }
2008
2004
  } else {
2009
2005
  if (V === null) {
@@ -2269,9 +2265,6 @@ export const Field = (config: FieldOption) => {
2269
2265
  if (hasDef) {
2270
2266
  __def[propertyName] = field.def;
2271
2267
  }
2272
- if (field.comment) {
2273
- __def[propertyName] = field.comment;
2274
- }
2275
2268
  Reflect.defineMetadata(_fields, __fields, object);
2276
2269
  Reflect.defineMetadata(_columns, __columns, object);
2277
2270
  Reflect.defineMetadata(_columnsNoId, __columnsNoId, object);
@@ -3268,26 +3261,20 @@ export class SqlService<T extends object> {
3268
3261
  const params: any[] = [];
3269
3262
  const sql = formatDialect(option.sql?.replace(/\:([A-Za-z0-9._]+)/g, (txt, key) => {
3270
3263
  let V = LGet(_params, key);
3271
- if (V) {
3272
- if (V !== undefined) {
3273
- params.push(V);
3274
- }
3264
+ if (V !== undefined) {
3265
+ params.push(V);
3275
3266
  return '?';
3276
3267
  }
3277
3268
  const _key = C2P(key);
3278
3269
  V = LGet(_params, _key);
3279
- if (V) {
3280
- if (V !== undefined) {
3281
- params.push(V);
3282
- }
3270
+ if (V !== undefined) {
3271
+ params.push(V);
3283
3272
  return '?';
3284
3273
  }
3285
3274
  const __key = P2C(key);
3286
3275
  V = LGet(_params, __key);
3287
- if (V) {
3288
- if (V !== undefined) {
3289
- params.push(V);
3290
- }
3276
+ if (V !== undefined) {
3277
+ params.push(V);
3291
3278
  return '?';
3292
3279
  }
3293
3280
  return txt;
@@ -3332,26 +3319,20 @@ export class SqlService<T extends object> {
3332
3319
  const params: any[] = [];
3333
3320
  const sql = formatDialect(option.sql?.replace(/\:(\w+)/g, (txt, key) => {
3334
3321
  let V = LGet(_params, key);
3335
- if (V) {
3336
- if (V !== undefined) {
3337
- params.push(V);
3338
- }
3322
+ if (V !== undefined) {
3323
+ params.push(V);
3339
3324
  return '?';
3340
3325
  }
3341
3326
  const _key = C2P(key);
3342
3327
  V = LGet(_params, _key);
3343
- if (V) {
3344
- if (V !== undefined) {
3345
- params.push(V);
3346
- }
3328
+ if (V !== undefined) {
3329
+ params.push(V);
3347
3330
  return '?';
3348
3331
  }
3349
3332
  const __key = P2C(key);
3350
3333
  V = LGet(_params, __key);
3351
- if (V) {
3352
- if (V !== undefined) {
3353
- params.push(V);
3354
- }
3334
+ if (V !== undefined) {
3335
+ params.push(V);
3355
3336
  return '?';
3356
3337
  }
3357
3338
  return txt;
@@ -4059,15 +4040,15 @@ class StreamQuery<T extends object> {
4059
4040
  @IF_PROCEED<T>()
4060
4041
  groupBy(...keys: (keyof T)[]) { this._groups.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()}`)); return this; }
4061
4042
  @IF_PROCEED<T>()
4062
- groupBy2(...keys: string[]) { this._groups.push(...keys); return this; }
4043
+ groupBy2(...keys: string[]) { this._groups.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()}`)); return this; }
4063
4044
  @IF_PROCEED<T>()
4064
4045
  asc(...keys: (keyof T)[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} ASC`)); return this; }
4065
4046
  @IF_PROCEED<T>()
4066
- asc2(...keys: string[]) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
4047
+ asc2(...keys: string[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} ASC`)); return this; }
4067
4048
  @IF_PROCEED<T>()
4068
4049
  desc(...keys: (keyof T)[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} DESC`)); return this; }
4069
4050
  @IF_PROCEED<T>()
4070
- desc2(...keys: string[]) { this._orders.push(...keys.map(key => `${key} ASC`)); return this; }
4051
+ desc2(...keys: string[]) { this._orders.push(...keys.map(key => `${this[_fields]![String(key)]?.C2()} ASC`)); return this; }
4071
4052
  @IF_PROCEED<T>()
4072
4053
  limit(startRow: number, pageSize: number) { this._startRow = startRow; this._pageSize = pageSize; return this; }
4073
4054
  @IF_PROCEED<T>()
@@ -4103,11 +4084,18 @@ class StreamQuery<T extends object> {
4103
4084
  @IF_PROCEED<T>()
4104
4085
  select2(sql: string, param?: Record<string, any>) { this._columns.push(`${sql}`); Object.assign(this._param, param); return this; }
4105
4086
  @IF_PROCEED<T>()
4106
- update(key: keyof T, value: T[keyof T]) { this._updates ??= {}; this._updates[key] = value; return this; }
4087
+ update(key: keyof T, value: T[keyof T]) { this._updates ??= {}; this._updates[this[_fields]![String(key)]?.C2()!] = value; return this; }
4107
4088
  @IF_PROCEED<T>()
4108
4089
  update2(sql: string, param?: Record<string, any>) { this._updateColumns.push(sql); Object.assign(this._param, param); return this; }
4109
4090
  @IF_PROCEED<T>()
4110
- updateT(t: Partial<T>) { this._updates ??= {}; Object.assign(this._updates, t); return this; }
4091
+ updateT(t: Partial<T>) {
4092
+ this._updates ??= {};
4093
+ for (const [key, value] of Object.entries(t)) {
4094
+ this._updates[this[_fields]![String(key)]?.C2()!] = value;
4095
+ }
4096
+ Object.assign(this._updates, t);
4097
+ return this;
4098
+ }
4111
4099
  @IF_PROCEED<T>()
4112
4100
  replace(key: keyof T, valueToFind: T[keyof T], valueToReplace: T[keyof T]) {
4113
4101
  const [pkey1, pkey2] = [`p${this._prefix}${this._index++}`, `p${this._prefix}${this._index++}`];
@@ -4252,10 +4240,10 @@ class StreamQuery<T extends object> {
4252
4240
  });
4253
4241
  }
4254
4242
  }
4255
- excuteUpdate(option?: MethodOption & { sync?: SyncMode.Async }): Promise<number>;
4256
- excuteUpdate(option: MethodOption & { sync: SyncMode.Sync }): number;
4243
+ excuteUpdate(option?: MethodOption & { sync?: SyncMode.Async; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; }): Promise<number>;
4244
+ excuteUpdate(option: MethodOption & { sync: SyncMode.Sync; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; }): number;
4257
4245
  @IF_EXEC<T>(0)
4258
- excuteUpdate(option?: MethodOption & { sync?: SyncMode }): number | Promise<number> {
4246
+ excuteUpdate(option?: MethodOption & { sync?: SyncMode; skipUndefined?: boolean; skipNull?: boolean; skipEmptyString?: boolean; }): number | Promise<number> {
4259
4247
  option ??= {};
4260
4248
  option.sync ??= SyncMode.Async;
4261
4249
  const { where, params } = this._where();
@@ -4273,9 +4261,9 @@ class StreamQuery<T extends object> {
4273
4261
  ${where}
4274
4262
  `;
4275
4263
  if (option.sync === SyncMode.Async) {
4276
- return this._service.excute({ sync: SyncMode.Async, sql, params });
4264
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
4277
4265
  } else {
4278
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
4266
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
4279
4267
  }
4280
4268
  } else {
4281
4269
  return 0;
@@ -4293,9 +4281,9 @@ class StreamQuery<T extends object> {
4293
4281
  ${where}
4294
4282
  `;
4295
4283
  if (option.sync === SyncMode.Async) {
4296
- return this._service.excute({ sync: SyncMode.Async, sql, params });
4284
+ return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
4297
4285
  } else {
4298
- return this._service.excute({ sync: SyncMode.Sync, sql, params });
4286
+ return this._service.excute({ ...option, sync: SyncMode.Sync, sql, params });
4299
4287
  }
4300
4288
  }
4301
4289
  private _where() {