baja-lite 1.4.13 → 1.5.1

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 (3) hide show
  1. package/package.json +4 -4
  2. package/sql.d.ts +3 -1
  3. package/sql.js +12 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.4.13",
3
+ "version": "1.5.1",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
@@ -60,9 +60,9 @@
60
60
  "@types/node": "24.0.3",
61
61
  "@types/shelljs": "0.8.16",
62
62
  "@types/sqlstring": "2.3.2",
63
- "@typescript-eslint/eslint-plugin": "8.34.1",
64
- "@typescript-eslint/parser": "8.34.1",
65
- "better-sqlite3": "11.10.0",
63
+ "@typescript-eslint/eslint-plugin": "8.35.0",
64
+ "@typescript-eslint/parser": "8.35.0",
65
+ "better-sqlite3": "12.1.0",
66
66
  "ioredis": "5.6.1",
67
67
  "mongodb": "6.17.0",
68
68
  "mysql2": "3.14.1",
package/sql.d.ts CHANGED
@@ -471,7 +471,7 @@ export interface GlobalSqlOption extends GlobalSqlOptionForWeb {
471
471
  jsMode?: boolean;
472
472
  }
473
473
  export interface PageQuery<L> {
474
- sum?: Record<string, number>;
474
+ sum?: Record<string, string | number>;
475
475
  total?: number;
476
476
  size?: number;
477
477
  records?: L[];
@@ -1331,6 +1331,7 @@ export declare class SqlService<T extends object> {
1331
1331
  pageNumber?: number;
1332
1332
  limitSelf?: boolean;
1333
1333
  countSelf?: boolean;
1334
+ sum?: boolean;
1334
1335
  sumSelf?: boolean;
1335
1336
  sortName?: string;
1336
1337
  sortType?: string;
@@ -1348,6 +1349,7 @@ export declare class SqlService<T extends object> {
1348
1349
  pageNumber?: number;
1349
1350
  limitSelf?: boolean;
1350
1351
  countSelf?: boolean;
1352
+ sum?: boolean;
1351
1353
  sumSelf?: boolean;
1352
1354
  sortName?: string;
1353
1355
  sortType?: string;
package/sql.js CHANGED
@@ -2508,11 +2508,11 @@ export class SqlService {
2508
2508
  }
2509
2509
  }
2510
2510
  delete(option) {
2511
- Throw.if(!!this[_ids] && this[_ids].length > 1 && !option.where, 'muit id must set where!');
2512
- Throw.if((!this[_ids] || this[_ids].length === 0) && !option.where, 'if not set id on class, must set where!');
2513
- Throw.if(!option.id && !option.where, 'not found id or where!');
2511
+ Throw.if(!!this[_ids] && this[_ids].length > 1 && !option.where && !option.whereSql, 'muit id must set where!');
2512
+ Throw.if((!this[_ids] || this[_ids].length === 0) && !option.where && !option.whereSql, 'if not set id on class, must set where!');
2513
+ Throw.if(!option.id && !option.where && !option.whereSql, 'not found id or where!');
2514
2514
  Throw.if(!!option.id && !!this[_ids] && this[_ids].length > 1, 'muit id must set where!');
2515
- Throw.if(!!option.id && !!option.where, 'id and where only one can set!');
2515
+ Throw.if(!!option.id && !!option.where && !option.whereSql, 'id and where only one can set!');
2516
2516
  option.mode ?? (option.mode = DeleteMode.Common);
2517
2517
  const tableTemp = `${option?.tableName}_${Math.random()}`.replace(/\./, '');
2518
2518
  const tableTempESC = tableTemp;
@@ -2945,16 +2945,17 @@ export class SqlService {
2945
2945
  let sql = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, ...option.params });
2946
2946
  let sqlSum = '';
2947
2947
  let sqlCount = '';
2948
- if (option.sumSelf) {
2949
- sqlSum = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, isSum: true, ...option.params });
2950
- }
2951
- if (option.limitSelf !== true) {
2952
- if (option.countSelf !== true) {
2948
+ if (option.sum) {
2949
+ if (option.sumSelf) {
2950
+ sqlCount = globalThis[_sqlCache].load(this._matchSqlid(`${option.sqlId}_sum`), { ctx: option.context, isCount: false, isSum: true, ...option.params });
2953
2951
  }
2954
- if (option.pageSize > 0) {
2955
- sql = `${sql} LIMIT ${option.params['limitStart']}, ${option.pageSize}`;
2952
+ else {
2953
+ sqlSum = globalThis[_sqlCache].load(this._matchSqlid(option.sqlId), { ctx: option.context, isCount: false, isSum: true, ...option.params });
2956
2954
  }
2957
2955
  }
2956
+ if (option.limitSelf !== true && option.pageSize > 0) {
2957
+ sql = `${sql} LIMIT ${option.params['limitStart']}, ${option.pageSize}`;
2958
+ }
2958
2959
  if (option.pageSize > 0) {
2959
2960
  if (option.countSelf) {
2960
2961
  sqlCount = globalThis[_sqlCache].load(this._matchSqlid(`${option.sqlId}_count`), { ctx: option.context, isCount: true, isSum: false, ...option.params });