baja-lite 1.5.25 → 1.5.27

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/package.json +4 -4
  2. package/sql.d.ts +5 -1
  3. package/sql.js +16 -7
  4. package/sqlite.js +7 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.5.25",
3
+ "version": "1.5.27",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@msgpack/msgpack": "3.1.2",
39
39
  "@types/request-promise": "4.1.51",
40
- "axios": "1.10.0",
40
+ "axios": "1.11.0",
41
41
  "baja-lite-field": "1.4.13",
42
42
  "decimal.js": "10.6.0",
43
43
  "html-parse-stringify": "3.0.1",
@@ -64,8 +64,8 @@
64
64
  "@typescript-eslint/parser": "8.36.0",
65
65
  "better-sqlite3": "12.2.0",
66
66
  "ioredis": "5.6.1",
67
- "mongodb": "6.17.0",
68
- "mysql2": "3.14.1",
67
+ "mongodb": "6.18.0",
68
+ "mysql2": "3.14.2",
69
69
  "pg": "8.16.3",
70
70
  "pg-pool": "3.10.1",
71
71
  "redlock": "5.0.0-beta.2",
package/sql.d.ts CHANGED
@@ -57,10 +57,14 @@ export declare enum InsertMode {
57
57
  2. 临时表的结构复制正式表
58
58
  */
59
59
  InsertWithTempTable = 1,
60
+ /**
61
+ * 如果不存在则插入
62
+ * 来源是数据库,根据ID或者指定字段查询
63
+ */
60
64
  InsertIfNotExists = 2,
61
65
  /**
62
66
  # 插入或者更新
63
- 1. 判断依据是主键
67
+ 1. 判断依据是主键,来源是从数据库查询
64
68
  */
65
69
  Replace = 3
66
70
  }
package/sql.js CHANGED
@@ -23,6 +23,7 @@ import { Throw } from './error.js';
23
23
  import { excuteSplit, ExcuteSplitMode, sleep } from './fn.js';
24
24
  import { add, calc, ten2Any } from './math.js';
25
25
  import { C2P, C2P2, P2C } from './object.js';
26
+ import { snowflake } from './snowflake.js';
26
27
  import { emptyString } from './string.js';
27
28
  const iterate = ite.iterate;
28
29
  BigInt.prototype.toJSON = function () { return this.toString(); };
@@ -129,10 +130,14 @@ export var InsertMode;
129
130
  2. 临时表的结构复制正式表
130
131
  */
131
132
  InsertMode[InsertMode["InsertWithTempTable"] = 1] = "InsertWithTempTable";
133
+ /**
134
+ * 如果不存在则插入
135
+ * 来源是数据库,根据ID或者指定字段查询
136
+ */
132
137
  InsertMode[InsertMode["InsertIfNotExists"] = 2] = "InsertIfNotExists";
133
138
  /**
134
139
  # 插入或者更新
135
- 1. 判断依据是主键
140
+ 1. 判断依据是主键,来源是从数据库查询
136
141
  */
137
142
  InsertMode[InsertMode["Replace"] = 3] = "Replace";
138
143
  })(InsertMode || (InsertMode = {}));
@@ -944,6 +949,10 @@ export class Sqlite {
944
949
  PRIMARY KEY ( ______tableName )
945
950
  );
946
951
  `);
952
+ this[_daoDB].function('UUID_SHORT', { deterministic: true }, () => snowflake.generate());
953
+ this[_daoDB].function('TIME_TO_SEC', { deterministic: true }, (time) => time.split(':').map((v, i) => parseInt(v) * (i > 0 ? 1 : 60)).reduce((a, b) => a + b, 0));
954
+ this[_daoDB].function('IF', { deterministic: true }, (condition, v1, v2) => condition ? v1 : v2);
955
+ this[_daoDB].function('RIGHT', { deterministic: true }, (src, p) => src.slice(p * -1));
947
956
  }
948
957
  createConnection(sync) {
949
958
  if (sync === SyncMode.Async) {
@@ -2862,13 +2871,13 @@ export class SqlService {
2862
2871
  const { sql, params } = this._generSql(option.dbType, option.sql, _params);
2863
2872
  if (option.sync === SyncMode.Sync) {
2864
2873
  const result = option.conn.query(SyncMode.Sync, sql, params);
2865
- return result.map(item => this._select(option.selectResult, result, null, undefined, option.hump, option.mapper, option.mapperIfUndefined, option.dataConvert));
2874
+ return result.map(item => this._select(option.selectResult, item, null, undefined, option.hump, option.mapper, option.mapperIfUndefined, option.dataConvert));
2866
2875
  }
2867
2876
  else {
2868
2877
  return new Promise(async (resolve, reject) => {
2869
2878
  try {
2870
2879
  const result = await option.conn.query(SyncMode.Async, sql, params);
2871
- resolve(result.map(item => this._select(option.selectResult, result, null, undefined, option.hump, option.mapper, option.mapperIfUndefined, option.dataConvert)));
2880
+ resolve(result.map(item => this._select(option.selectResult, item, null, undefined, option.hump, option.mapper, option.mapperIfUndefined, option.dataConvert)));
2872
2881
  }
2873
2882
  catch (error) {
2874
2883
  reject(error);
@@ -3975,10 +3984,10 @@ class StreamQuery {
3975
3984
  }
3976
3985
  }
3977
3986
  if (sets.length > 0) {
3978
- const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} t SET ${sets.join(',')}
3987
+ const sql = `UPDATE ${option.tableName ?? this._service[_tableName]} SET ${sets.join(',')}
3979
3988
  ${where ? ' WHERE ' : ''}
3980
3989
  ${where}
3981
- `;
3990
+ `.replace(/t\./g, '');
3982
3991
  if (option.sync === SyncMode.Async) {
3983
3992
  return this._service.excute({ ...option, sync: SyncMode.Async, sql, params });
3984
3993
  }
@@ -3994,10 +4003,10 @@ class StreamQuery {
3994
4003
  option ?? (option = {});
3995
4004
  option.sync ?? (option.sync = SyncMode.Async);
3996
4005
  const { where, params } = this._where();
3997
- const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]} t
4006
+ const sql = `DELETE FROM ${option.tableName ?? this._service[_tableName]}
3998
4007
  ${where ? ' WHERE ' : ''}
3999
4008
  ${where}
4000
- `;
4009
+ `.replace(/t\./g, '');
4001
4010
  // if (option.sync === SyncMode.Async) {
4002
4011
  // return this._service.delete({ ...option, sync: SyncMode.Async, whereSql: where, whereParams: params });
4003
4012
  // } else {
package/sqlite.js CHANGED
@@ -1,6 +1,7 @@
1
- import { extensionCodec, logger } from './sql.js';
1
+ import { decode, encode } from "@msgpack/msgpack";
2
2
  import Sqlstring from 'sqlstring';
3
- import { encode, decode } from "@msgpack/msgpack";
3
+ import { snowflake } from './snowflake.js';
4
+ import { extensionCodec, logger } from './sql.js';
4
5
  export class SqliteRemoteClass {
5
6
  constructor() {
6
7
  this.dbList = {};
@@ -131,6 +132,10 @@ export class SqliteRemoteClass {
131
132
  PRIMARY KEY ( ______tableName )
132
133
  );
133
134
  `);
135
+ this.dbList[dbName].function('UUID_SHORT', { deterministic: true }, () => snowflake.generate());
136
+ this.dbList[dbName].function('TIME_TO_SEC', { deterministic: true }, (time) => time.split(':').map((v, i) => parseInt(v) * (i > 0 ? 1 : 60)).reduce((a, b) => a + b, 0));
137
+ this.dbList[dbName].function('IF', { deterministic: true }, (condition, v1, v2) => condition ? v1 : v2);
138
+ this.dbList[dbName].function('RIGHT', { deterministic: true }, (src, p) => src.slice(p * -1));
134
139
  }
135
140
  }
136
141
  async export(dbName, exportPath) {