@maiyunnet/kebab 5.0.4 → 5.2.0

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/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "5.0.4";
8
+ export declare const VER = "5.2.0";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '5.0.4';
9
+ export const VER = '5.2.0';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/ai.d.ts CHANGED
@@ -43,6 +43,8 @@ export declare class Ai {
43
43
  chat(body: openai.default.Chat.Completions.ChatCompletionCreateParamsNonStreaming): Promise<openai.APIPromise<openai.default.Chat.ChatCompletion> | false>;
44
44
  /** --- 创建流式对话 --- */
45
45
  chat(body: openai.default.Chat.Completions.ChatCompletionCreateParamsStreaming): Promise<openai.APIPromise<streaming.Stream<openai.default.Chat.ChatCompletionChunk>> | false>;
46
+ /** --- 创建向量 --- */
47
+ embedding(body: openai.default.EmbeddingCreateParams): Promise<openai.APIPromise<openai.default.CreateEmbeddingResponse> | false>;
46
48
  }
47
49
  /**
48
50
  * --- 创建一个 AI 对象 ---
package/lib/ai.js CHANGED
@@ -83,6 +83,17 @@ export class Ai {
83
83
  return false;
84
84
  }
85
85
  }
86
+ /** --- 创建向量 --- */
87
+ async embedding(body) {
88
+ try {
89
+ return await this.link.embeddings.create(body);
90
+ }
91
+ catch (e) {
92
+ lCore.debug('[AI][EMBEDDING]', e);
93
+ lCore.log(this._ctr, `[AI][EMBEDDING] ${e.message}`, '-error');
94
+ return false;
95
+ }
96
+ }
86
97
  }
87
98
  /**
88
99
  * --- 创建一个 AI 对象 ---
package/lib/crypto.d.ts CHANGED
@@ -24,6 +24,13 @@ export declare function generateKeyPair(type: string, options?: {
24
24
  'public': string | Buffer;
25
25
  'private': string | Buffer;
26
26
  }>;
27
+ /**
28
+ * --- 非对称加签 ---
29
+ * @param data 数据
30
+ * @param privateKey 私钥
31
+ * @param format 输出格式
32
+ * @param algorithm 哈希方式
33
+ */
27
34
  export declare function sign(data: crypto.BinaryLike, privateKey: crypto.KeyLike | crypto.SignKeyObjectInput | crypto.SignPrivateKeyInput | crypto.SignJsonWebKeyInput, format: 'hex' | 'base64' | 'binary', algorithm?: string): string;
28
35
  export declare function sign(data: crypto.BinaryLike, privateKey: crypto.KeyLike | crypto.SignKeyObjectInput | crypto.SignPrivateKeyInput | crypto.SignJsonWebKeyInput, format?: 'buffer', algorithm?: string): Buffer;
29
36
  /**
@@ -77,10 +84,31 @@ export declare const SM4_CFB = "sm4-cfb";
77
84
  * @param method 加密方法
78
85
  */
79
86
  export declare function cipherEncrypt(original: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'base64' | 'buffer'): string | Buffer | false;
87
+ /**
88
+ * --- AES 加密 ---
89
+ * @param original 原始字符串
90
+ * @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
91
+ * @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
92
+ * @param method 加密方法
93
+ * @param output 输出类型
94
+ */
80
95
  export declare function aesEncrypt(original: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
81
96
  export declare function aesEncrypt(original: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'base64'): string | false;
97
+ /**
98
+ * --- AES GCM 托管加密 ---
99
+ * @param original 原始字符串
100
+ * @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
101
+ * @param output 输出类型
102
+ */
82
103
  export declare function gcmEncrypt(original: string | Buffer, key: crypto.CipherKey, output: 'buffer'): Buffer | false;
83
104
  export declare function gcmEncrypt(original: string | Buffer, key: crypto.CipherKey, output?: 'base64'): string | false;
105
+ /**
106
+ * --- SM4 加密 ---
107
+ * @param original 原始字符串
108
+ * @param key 密钥 32 个英文字母和数字
109
+ * @param iv 向量 16 个英文字母和数字
110
+ * @param method 加密方法
111
+ */
84
112
  export declare function sm4Encrypt(original: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
85
113
  export declare function sm4Encrypt(original: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'base64'): string | false;
86
114
  /**
@@ -91,12 +119,39 @@ export declare function sm4Encrypt(original: string | Buffer, key: crypto.Cipher
91
119
  * @param method 加密方法
92
120
  */
93
121
  export declare function cipherDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'binary' | 'buffer'): string | Buffer | false;
122
+ /**
123
+ * --- AES 解密 ---
124
+ * @param encrypt 需解密的字符串
125
+ * @param key 密钥 32 个英文字母和数字
126
+ * @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
127
+ * @param method 加密方法
128
+ */
94
129
  export declare function aesDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
95
130
  export declare function aesDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'binary'): string | false;
131
+ /**
132
+ * --- AES 解密 ---
133
+ * @param encrypt 需解密的字符串
134
+ * @param key 密钥 32 个英文字母和数字
135
+ * @param iv 向量 16 个英文字母和数字
136
+ * @param method 加密方法
137
+ */
96
138
  export declare function gcmDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, output: 'buffer'): Buffer | false;
97
139
  export declare function gcmDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, output?: 'binary'): string | false;
140
+ /**
141
+ * --- SM4 解密 ---
142
+ * @param encrypt 需解密的字符串
143
+ * @param key 密钥 32 个英文字母和数字
144
+ * @param iv 向量 16 个英文字母和数字
145
+ * @param method 加密方法
146
+ */
98
147
  export declare function sm4Decrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
99
148
  export declare function sm4Decrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'binary'): string | false;
149
+ /**
150
+ * --- hash 或 hmac 加密 ---
151
+ * @param algorithm 哈希方式
152
+ * @param data 源数据
153
+ * @param key 设置则采用 hmac 加密
154
+ */
100
155
  export declare function hashHmac(algorithm: string, data: Buffer | string, key?: crypto.CipherKey, format?: 'hex' | 'base64'): string;
101
156
  export declare function hashHmac(algorithm: string, data: Buffer | string, key: crypto.CipherKey | undefined, format: 'buffer'): Buffer;
102
157
  export declare function hashHmacFile(algorithm: string, path: string, key?: crypto.CipherKey, encoding?: 'hex' | 'base64' | 'base64url'): Promise<string | false>;
package/lib/crypto.js CHANGED
@@ -39,13 +39,6 @@ export function generateKeyPair(type, options = {}) {
39
39
  });
40
40
  });
41
41
  }
42
- /**
43
- * --- 非对称加签 ---
44
- * @param data 数据
45
- * @param privateKey 私钥
46
- * @param format 输出格式
47
- * @param algorithm 哈希方式
48
- */
49
42
  export function sign(data, privateKey, format = 'buffer', algorithm = 'sha256') {
50
43
  const sign = crypto.createSign(algorithm);
51
44
  sign.update(data);
@@ -165,26 +158,12 @@ export function cipherEncrypt(original, key, iv = '', method = AES_256_ECB, outp
165
158
  return false;
166
159
  }
167
160
  }
168
- /**
169
- * --- AES 加密 ---
170
- * @param original 原始字符串
171
- * @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
172
- * @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
173
- * @param method 加密方法
174
- * @param output 输出类型
175
- */
176
161
  export function aesEncrypt(original, key, iv = '', method = AES_256_ECB, output = 'base64') {
177
162
  if (iv !== '') {
178
163
  method = method === AES_256_ECB ? AES_256_CTR : method;
179
164
  }
180
165
  return cipherEncrypt(original, key, iv, method, output);
181
166
  }
182
- /**
183
- * --- AES GCM 托管加密 ---
184
- * @param original 原始字符串
185
- * @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
186
- * @param output 输出类型
187
- */
188
167
  export function gcmEncrypt(original, key, output = 'base64') {
189
168
  const iv = lCore.random(12, lCore.RANDOM_LUNS);
190
169
  const rtn = cipherEncrypt(original, key, iv, AES_256_GCM, output);
@@ -193,13 +172,6 @@ export function gcmEncrypt(original, key, output = 'base64') {
193
172
  }
194
173
  return typeof rtn === 'string' ? iv + rtn : Buffer.concat([Buffer.from(iv), rtn]);
195
174
  }
196
- /**
197
- * --- SM4 加密 ---
198
- * @param original 原始字符串
199
- * @param key 密钥 32 个英文字母和数字
200
- * @param iv 向量 16 个英文字母和数字
201
- * @param method 加密方法
202
- */
203
175
  export function sm4Encrypt(original, key, iv = '', method = SM4_ECB, output = 'base64') {
204
176
  if (iv !== '') {
205
177
  method = method === SM4_ECB ? SM4_CFB : method;
@@ -268,48 +240,21 @@ export function cipherDecrypt(encrypt, key, iv = '', method = AES_256_ECB, outpu
268
240
  return false;
269
241
  }
270
242
  }
271
- /**
272
- * --- AES 解密 ---
273
- * @param encrypt 需解密的字符串
274
- * @param key 密钥 32 个英文字母和数字
275
- * @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
276
- * @param method 加密方法
277
- */
278
243
  export function aesDecrypt(encrypt, key, iv = '', method = AES_256_ECB, output = 'binary') {
279
244
  if (iv !== '') {
280
245
  method = method === AES_256_ECB ? AES_256_CTR : method;
281
246
  }
282
247
  return cipherDecrypt(encrypt, key, iv, method, output);
283
248
  }
284
- /**
285
- * --- AES 解密 ---
286
- * @param encrypt 需解密的字符串
287
- * @param key 密钥 32 个英文字母和数字
288
- * @param iv 向量 16 个英文字母和数字
289
- * @param method 加密方法
290
- */
291
249
  export function gcmDecrypt(encrypt, key, output = 'binary') {
292
250
  return cipherDecrypt(typeof encrypt === 'string' ? encrypt.slice(12) : encrypt.subarray(12), key, typeof encrypt === 'string' ? encrypt.slice(0, 12) : encrypt.subarray(0, 12).toString(), AES_256_GCM, output);
293
251
  }
294
- /**
295
- * --- SM4 解密 ---
296
- * @param encrypt 需解密的字符串
297
- * @param key 密钥 32 个英文字母和数字
298
- * @param iv 向量 16 个英文字母和数字
299
- * @param method 加密方法
300
- */
301
252
  export function sm4Decrypt(encrypt, key, iv = '', method = SM4_ECB, output = 'binary') {
302
253
  if (iv !== '') {
303
254
  method = method === SM4_ECB ? SM4_CFB : method;
304
255
  }
305
256
  return cipherDecrypt(encrypt, key, iv, method, output);
306
257
  }
307
- /**
308
- * --- hash 或 hmac 加密 ---
309
- * @param algorithm 哈希方式
310
- * @param data 源数据
311
- * @param key 设置则采用 hmac 加密
312
- */
313
258
  export function hashHmac(algorithm, data, key, format = 'hex') {
314
259
  const cry = key ? crypto.createHmac(algorithm, key) : crypto.createHash(algorithm);
315
260
  cry.update(data);
package/lib/sql.js CHANGED
@@ -474,7 +474,12 @@ export class Sql {
474
474
  let field = this.field(f, pre || this._pre, suf ? ('#' + suf) : '');
475
475
  if (pre) {
476
476
  // --- 处理不同 pre 的 as 前缀问题 ---
477
- field = field.replace(new RegExp(`AS \`${pre}(.+?)\``), `AS \`${this._pre}$1\``);
477
+ if (this._service === ESERVICE.MYSQL) {
478
+ field = field.replace(new RegExp(`AS \`${pre}(.+?)\``), `AS \`${this._pre}$1\``);
479
+ }
480
+ else {
481
+ field = field.replace(new RegExp(`AS "${pre}"."(.+?)"`), `AS "${this._pre}"."$1"`);
482
+ }
478
483
  }
479
484
  let sql = ' ' + type + ' JOIN ' + field;
480
485
  if (Array.isArray(s) ? s.length : Object.keys(s).length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "5.0.4",
3
+ "version": "5.2.0",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/mod.d.ts CHANGED
@@ -40,6 +40,8 @@ export default class Mod {
40
40
  protected static _$key: string;
41
41
  /** --- 若使用 _$key 并且有多个 unique 索引,这里指定 _$key 的索引名 --- */
42
42
  protected static _$index: string;
43
+ /** --- 前缀,顺序:选项前缀 -> 本前缀 -> 配置文件前缀 --- */
44
+ protected static _$pre: string | null;
43
45
  /** --- 要 update 的内容 --- */
44
46
  protected _updates: Record<string, boolean>;
45
47
  /** --- 模型获取的属性 --- */
@@ -94,7 +96,8 @@ export default class Mod {
94
96
  * @param opt 选项
95
97
  */
96
98
  static insert(db: lDb.Pool | lDb.Transaction, cs: string[] | Record<string, any>, vs?: any[] | any[][], opt?: {
97
- 'pre'?: sCtr.Ctr | string;
99
+ 'pre'?: string;
100
+ 'ctr'?: sCtr.Ctr;
98
101
  'index'?: string;
99
102
  }): Promise<boolean | null | false>;
100
103
  /**
@@ -105,7 +108,8 @@ export default class Mod {
105
108
  * @param opt 选项
106
109
  */
107
110
  static insertSql(db: lDb.Pool | lDb.Transaction, cs: string[] | Record<string, any>, vs?: any[] | any[][], opt?: {
108
- 'pre'?: sCtr.Ctr | string;
111
+ 'pre'?: string;
112
+ 'ctr'?: sCtr.Ctr;
109
113
  'index'?: string;
110
114
  }): string;
111
115
  /**
@@ -116,7 +120,8 @@ export default class Mod {
116
120
  */
117
121
  static removeByWhere(db: lDb.Pool | lDb.Transaction, where: string | kebab.Json, opt?: {
118
122
  'raw'?: boolean;
119
- 'pre'?: sCtr.Ctr | string;
123
+ 'pre'?: string;
124
+ 'ctr'?: sCtr.Ctr;
120
125
  'index'?: string | string[];
121
126
  'by'?: [string | string[], 'DESC' | 'ASC'];
122
127
  'limit'?: [number, number?];
@@ -129,7 +134,8 @@ export default class Mod {
129
134
  */
130
135
  static removeByWhereSql(db: lDb.Pool | lDb.Transaction, where: string | kebab.Json, opt?: {
131
136
  'raw'?: boolean;
132
- 'pre'?: sCtr.Ctr | string;
137
+ 'pre'?: string;
138
+ 'ctr'?: sCtr.Ctr;
133
139
  'index'?: string;
134
140
  'by'?: [string | string[], 'DESC' | 'ASC'];
135
141
  'limit'?: [number, number?];
@@ -143,7 +149,8 @@ export default class Mod {
143
149
  */
144
150
  static updateByWhere(db: lDb.Pool | lDb.Transaction, data: kebab.Json, where: string | kebab.Json, opt?: {
145
151
  'raw'?: boolean;
146
- 'pre'?: sCtr.Ctr | string;
152
+ 'pre'?: string;
153
+ 'ctr'?: sCtr.Ctr;
147
154
  'index'?: string | string[];
148
155
  'by'?: [string | string[], 'DESC' | 'ASC'];
149
156
  'limit'?: [number, number?];
@@ -157,7 +164,8 @@ export default class Mod {
157
164
  */
158
165
  static updateByWhereSql(db: lDb.Pool | lDb.Transaction, data: kebab.Json, where: string | kebab.Json, opt?: {
159
166
  'raw'?: boolean;
160
- 'pre'?: sCtr.Ctr | string;
167
+ 'pre'?: string;
168
+ 'ctr'?: sCtr.Ctr;
161
169
  'index'?: string;
162
170
  'by'?: [string | string[], 'DESC' | 'ASC'];
163
171
  'limit'?: [number, number?];
@@ -335,7 +343,7 @@ export default class Mod {
335
343
  * @param s ON 信息
336
344
  * @param type 类型
337
345
  * @param index 给本表增加 index 分表项
338
- * @param pre 前缀
346
+ * @param pre 前缀,仅与主表的 pre 不同时传入
339
347
  */
340
348
  join(f: string, s?: kebab.Json, type?: string, index?: string, pre?: string): this;
341
349
  /**
@@ -343,6 +351,7 @@ export default class Mod {
343
351
  * @param f 表名
344
352
  * @param s ON 信息
345
353
  * @param index 给本表增加 index 分表项
354
+ * @param pre 前缀,仅与主表的 pre 不同时传入
346
355
  */
347
356
  leftJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
348
357
  /**
@@ -350,6 +359,7 @@ export default class Mod {
350
359
  * @param f 表名
351
360
  * @param s ON 信息
352
361
  * @param index 给本表增加 index 分表项
362
+ * @param pre 前缀,仅与主表的 pre 不同时传入
353
363
  */
354
364
  rightJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
355
365
  /**
@@ -357,6 +367,7 @@ export default class Mod {
357
367
  * @param f 表名
358
368
  * @param s ON 信息
359
369
  * @param index 给本表增加 index 分表项
370
+ * @param pre 前缀,仅与主表的 pre 不同时传入
360
371
  */
361
372
  innerJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
362
373
  /**
@@ -364,6 +375,7 @@ export default class Mod {
364
375
  * @param f 表名
365
376
  * @param s ON 信息
366
377
  * @param index 给本表增加 index 分表项
378
+ * @param pre 前缀,仅与主表的 pre 不同时传入
367
379
  */
368
380
  fullJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
369
381
  /**
@@ -371,6 +383,7 @@ export default class Mod {
371
383
  * @param f 表名
372
384
  * @param s ON 信息
373
385
  * @param index 给本表增加 index 分表项
386
+ * @param pre 前缀,仅与主表的 pre 不同时传入
374
387
  */
375
388
  crossJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
376
389
  /**
package/sys/mod.js CHANGED
@@ -7,7 +7,6 @@ import * as lSql from '#kebab/lib/sql.js';
7
7
  import * as lDb from '#kebab/lib/db.js';
8
8
  import * as lCore from '#kebab/lib/core.js';
9
9
  import * as lText from '#kebab/lib/text.js';
10
- import * as sCtr from '#kebab/sys/ctr.js';
11
10
  /** --- 条数列表 --- */
12
11
  class Rows {
13
12
  constructor(initialItems = []) {
@@ -54,6 +53,8 @@ export default class Mod {
54
53
  static { this._$key = ''; }
55
54
  /** --- 若使用 _$key 并且有多个 unique 索引,这里指定 _$key 的索引名 --- */
56
55
  static { this._$index = ''; }
56
+ /** --- 前缀,顺序:选项前缀 -> 本前缀 -> 配置文件前缀 --- */
57
+ static { this._$pre = null; }
57
58
  /**
58
59
  * --- 构造函数 ---
59
60
  * @param ctr Ctr 对象
@@ -79,7 +80,7 @@ export default class Mod {
79
80
  /** --- 导入数据库连接 --- */
80
81
  this._db = opt.db;
81
82
  /** --- 新建 sql 对象 --- */
82
- this._sql = lSql.get(opt.pre ?? opt.ctr, {
83
+ this._sql = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
83
84
  'service': this._db.getService() ?? lDb.ESERVICE.PGSQL,
84
85
  });
85
86
  if (opt.index) {
@@ -118,7 +119,7 @@ export default class Mod {
118
119
  * @param opt 选项
119
120
  */
120
121
  static async insert(db, cs, vs, opt = {}) {
121
- const sq = lSql.get(opt.pre, {
122
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
122
123
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
123
124
  });
124
125
  if (!vs) {
@@ -127,7 +128,7 @@ export default class Mod {
127
128
  sq.values(cs);
128
129
  const r = await db.execute(sq.getSql(), sq.getData());
129
130
  if (r.packet === null) {
130
- lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[insert, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
131
+ lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
131
132
  return false;
132
133
  }
133
134
  return r.packet.affected ? true : null;
@@ -147,7 +148,7 @@ export default class Mod {
147
148
  sq.values(cs, vs.slice(i * line, (i + 1) * line));
148
149
  const r = await db.execute(sq.getSql(), sq.getData());
149
150
  if (r.packet === null) {
150
- lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[insert, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
151
+ lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
151
152
  return false;
152
153
  }
153
154
  if (r.packet.affected) {
@@ -165,7 +166,7 @@ export default class Mod {
165
166
  * @param opt 选项
166
167
  */
167
168
  static insertSql(db, cs, vs, opt = {}) {
168
- const sq = lSql.get(opt.pre, {
169
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
169
170
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
170
171
  });
171
172
  sq.insert(this._$table + (opt.index ? ('_' + opt.index) : '')).values(cs, vs);
@@ -181,7 +182,7 @@ export default class Mod {
181
182
  const indexs = opt.index ? (typeof opt.index === 'string' ? [opt.index] : [...new Set(opt.index)]) : [''];
182
183
  let ar = 0;
183
184
  for (const index of indexs) {
184
- const sq = lSql.get(opt.pre, {
185
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
185
186
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
186
187
  });
187
188
  sq.delete(this._$table + (index ? ('_' + index) : '')).where(where);
@@ -193,7 +194,7 @@ export default class Mod {
193
194
  }
194
195
  const r = await db.execute(sq.getSql(), sq.getData());
195
196
  if (r.packet === null) {
196
- lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[MOD][removeByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
197
+ lCore.log(opt.ctr ?? {}, '[MOD][removeByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
197
198
  return false;
198
199
  }
199
200
  if (r.packet.affected) {
@@ -209,7 +210,7 @@ export default class Mod {
209
210
  * @param opt 选项
210
211
  */
211
212
  static removeByWhereSql(db, where, opt = {}) {
212
- const sq = lSql.get(opt.pre, {
213
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
213
214
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
214
215
  });
215
216
  sq.delete(this._$table + (opt.index ? ('_' + opt.index) : '')).where(where);
@@ -232,7 +233,7 @@ export default class Mod {
232
233
  const indexs = opt.index ? (typeof opt.index === 'string' ? [opt.index] : [...new Set(opt.index)]) : [''];
233
234
  let ar = 0;
234
235
  for (const index of indexs) {
235
- const sq = lSql.get(opt.pre, {
236
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
236
237
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
237
238
  });
238
239
  sq.update(this._$table + (index ? ('_' + index) : ''), data).where(where);
@@ -244,7 +245,7 @@ export default class Mod {
244
245
  }
245
246
  const r = await db.execute(sq.getSql(), sq.getData());
246
247
  if (r.packet === null) {
247
- lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[MOD][updateByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
248
+ lCore.log(opt.ctr ?? {}, '[MOD][updateByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
248
249
  return false;
249
250
  }
250
251
  if (r.packet.affected) {
@@ -261,7 +262,7 @@ export default class Mod {
261
262
  * @param opt 选项
262
263
  */
263
264
  static updateByWhereSql(db, data, where, opt = {}) {
264
- const sq = lSql.get(opt.pre, {
265
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
265
266
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
266
267
  });
267
268
  sq.update(this._$table + (opt.index ? ('_' + opt.index) : ''), data).where(where);
@@ -408,7 +409,7 @@ export default class Mod {
408
409
  * @param opt 选项
409
410
  */
410
411
  static async primarys(db, where = '', opt = {}) {
411
- const sq = lSql.get(opt.pre ?? opt.ctr, {
412
+ const sq = lSql.get(opt.pre ?? this.constructor._$pre ?? opt.ctr, {
412
413
  'service': db.getService() ?? lDb.ESERVICE.PGSQL,
413
414
  });
414
415
  sq.select(this._$primary, this._$table + (opt.index ? ('_' + opt.index) : '')).where(where);
@@ -435,7 +436,7 @@ export default class Mod {
435
436
  return rtn;
436
437
  }
437
438
  /**
438
- * --- 设置一个/多个属性 ---
439
+ * --- 设置一个/多个属性,值为 underfind 则不会被更新 ---
439
440
  * @param n 字符串或键/值
440
441
  * @param v 可能是数字
441
442
  */
@@ -1085,7 +1086,7 @@ export default class Mod {
1085
1086
  * @param s ON 信息
1086
1087
  * @param type 类型
1087
1088
  * @param index 给本表增加 index 分表项
1088
- * @param pre 前缀
1089
+ * @param pre 前缀,仅与主表的 pre 不同时传入
1089
1090
  */
1090
1091
  join(f, s = [], type = 'INNER', index = '', pre = '') {
1091
1092
  this._sql.join(f, s, type, index ? '_' + index : '', pre);
@@ -1096,6 +1097,7 @@ export default class Mod {
1096
1097
  * @param f 表名
1097
1098
  * @param s ON 信息
1098
1099
  * @param index 给本表增加 index 分表项
1100
+ * @param pre 前缀,仅与主表的 pre 不同时传入
1099
1101
  */
1100
1102
  leftJoin(f, s, index = '', pre = '') {
1101
1103
  this._sql.leftJoin(f, s, index ? '_' + index : '', pre);
@@ -1106,6 +1108,7 @@ export default class Mod {
1106
1108
  * @param f 表名
1107
1109
  * @param s ON 信息
1108
1110
  * @param index 给本表增加 index 分表项
1111
+ * @param pre 前缀,仅与主表的 pre 不同时传入
1109
1112
  */
1110
1113
  rightJoin(f, s, index = '', pre = '') {
1111
1114
  this._sql.rightJoin(f, s, index ? '_' + index : '', pre);
@@ -1116,6 +1119,7 @@ export default class Mod {
1116
1119
  * @param f 表名
1117
1120
  * @param s ON 信息
1118
1121
  * @param index 给本表增加 index 分表项
1122
+ * @param pre 前缀,仅与主表的 pre 不同时传入
1119
1123
  */
1120
1124
  innerJoin(f, s, index = '', pre = '') {
1121
1125
  this._sql.innerJoin(f, s, index ? '_' + index : '', pre);
@@ -1126,6 +1130,7 @@ export default class Mod {
1126
1130
  * @param f 表名
1127
1131
  * @param s ON 信息
1128
1132
  * @param index 给本表增加 index 分表项
1133
+ * @param pre 前缀,仅与主表的 pre 不同时传入
1129
1134
  */
1130
1135
  fullJoin(f, s, index = '', pre = '') {
1131
1136
  this._sql.fullJoin(f, s, index ? '_' + index : '', pre);
@@ -1136,6 +1141,7 @@ export default class Mod {
1136
1141
  * @param f 表名
1137
1142
  * @param s ON 信息
1138
1143
  * @param index 给本表增加 index 分表项
1144
+ * @param pre 前缀,仅与主表的 pre 不同时传入
1139
1145
  */
1140
1146
  crossJoin(f, s, index = '', pre = '') {
1141
1147
  this._sql.crossJoin(f, s, index ? '_' + index : '', pre);
@@ -573,7 +573,8 @@ Result:<pre id="result">Nothing.</pre>` + this._getEnd();
573
573
  await mTest.removeByWhere(db, [
574
574
  ['token', 'LIKE', 'test_%'],
575
575
  ], {
576
- 'pre': this._get['s'] === 'pgsql' ? 'm' : this,
576
+ 'ctr': this,
577
+ 'pre': this._get['s'] === 'pgsql' ? 'm' : undefined,
577
578
  });
578
579
  return this._location('test/mod-test' + (this._get['s'] === 'pgsql' ? '?s=pgsql' : ''));
579
580
  }
@@ -834,7 +835,7 @@ CREATE TABLE \`m_test_data_0\` (
834
835
  ]);
835
836
  }
836
837
  const res = await mTestData.insert(db, ['test_id', 'content', 'time_add'], datas, {
837
- 'pre': this,
838
+ 'ctr': this,
838
839
  'index': '0',
839
840
  });
840
841
  echo.push('<br><br>Result: ' + JSON.stringify(res));