@maiyunnet/kebab 4.1.0 → 5.0.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.
- package/index.d.ts +7 -2
- package/index.js +1 -1
- package/lib/db/conn.d.ts +91 -0
- package/lib/db/conn.js +328 -0
- package/lib/db/pool.d.ts +61 -0
- package/lib/db/pool.js +281 -0
- package/lib/db/tran.d.ts +33 -0
- package/lib/db/tran.js +122 -0
- package/lib/db.d.ts +35 -169
- package/lib/db.js +21 -582
- package/lib/scan.js +2 -2
- package/lib/sql.d.ts +24 -25
- package/lib/sql.js +230 -132
- package/lib/time.d.ts +1 -1
- package/lib/time.js +1 -1
- package/lib/turnstile.js +1 -1
- package/lib/vector.d.ts +9 -4
- package/lib/vector.js +46 -27
- package/package.json +6 -5
- package/sys/cmd.js +29 -6
- package/sys/mod.d.ts +8 -26
- package/sys/mod.js +110 -261
- package/www/example/ctr/test.js +119 -112
- package/www/example/data/test.zip +0 -0
- package/www/example/mod/test.js +22 -0
package/lib/sql.d.ts
CHANGED
|
@@ -1,55 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
3
3
|
* Date: 2019-5-27 20:18:50
|
|
4
|
-
* Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
|
|
4
|
+
* Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18, 2025-11-9 16:20:23
|
|
5
5
|
*/
|
|
6
6
|
import * as kebab from '#kebab/index.js';
|
|
7
7
|
import * as ctr from '#kebab/sys/ctr.js';
|
|
8
|
+
/** --- 服务商定义 --- */
|
|
9
|
+
export declare enum ESERVICE {
|
|
10
|
+
'MYSQL' = 0,
|
|
11
|
+
'PGSQL' = 1
|
|
12
|
+
}
|
|
8
13
|
export declare class Sql {
|
|
9
14
|
/** --- 前置 --- */
|
|
10
15
|
private readonly _pre;
|
|
16
|
+
/** --- 服务商 --- */
|
|
17
|
+
private readonly _service;
|
|
11
18
|
/** --- 预拼装 Sql 数组 --- */
|
|
12
19
|
private _sql;
|
|
13
20
|
/** --- 所有 data 数据 --- */
|
|
14
21
|
private _data;
|
|
22
|
+
/** --- 表别名列表 --- */
|
|
23
|
+
private readonly _alias;
|
|
24
|
+
/** --- PostgreSQL 占位符计数器 --- */
|
|
25
|
+
private _placeholder;
|
|
15
26
|
constructor(pre?: string, opt?: {
|
|
16
27
|
'data'?: kebab.DbValue[];
|
|
17
28
|
'sql'?: string[];
|
|
29
|
+
'service'?: ESERVICE;
|
|
18
30
|
});
|
|
19
31
|
/**
|
|
20
32
|
* --- 插入数据前导 ---
|
|
21
33
|
* @param table 表名
|
|
22
34
|
*/
|
|
23
35
|
insert(table: string): this;
|
|
24
|
-
/**
|
|
25
|
-
* --- 替换已经存在的唯一索引数据,不存在则插入 ---
|
|
26
|
-
* @param table 表名
|
|
27
|
-
*/
|
|
28
|
-
replace(table: string): this;
|
|
29
36
|
/**
|
|
30
37
|
* --- 实际插入数据的数据 ---
|
|
31
38
|
* @param cs [] 数据列或字段列
|
|
32
39
|
* @param vs [] | [][] 数据
|
|
33
40
|
*/
|
|
34
41
|
values(cs: string[] | Record<string, kebab.DbValue>, vs?: kebab.DbValue[] | kebab.DbValue[][]): this;
|
|
35
|
-
/**
|
|
36
|
-
* --- 不存在则插入,衔接在 insert 之后 ---
|
|
37
|
-
* @param table 表名
|
|
38
|
-
* @param insert {'xx': 'xx', 'xx': 'xx'}
|
|
39
|
-
* @param where [{'xx': 'xx', 'xx': 'xx'}], {'xx': 'xx'}
|
|
40
|
-
*/
|
|
41
|
-
notExists(table: string, insert: Record<string, kebab.DbValue>, where: string | kebab.Json): this;
|
|
42
|
-
/**
|
|
43
|
-
* --- 当不能 insert 时,update(仅能配合 insert 方法用) ---
|
|
44
|
-
* @param s 更新数据
|
|
45
|
-
*/
|
|
46
|
-
duplicate(s: kebab.Json): this;
|
|
47
42
|
/**
|
|
48
43
|
* --- '*', 'xx' ---
|
|
49
44
|
* @param c 字段字符串或字段数组
|
|
50
45
|
* @param f 表,允许多张表
|
|
51
46
|
*/
|
|
52
|
-
select(c: string | Array<string |
|
|
47
|
+
select(c: string | Array<string | any[]>, f: string | string[]): this;
|
|
53
48
|
/**
|
|
54
49
|
* --- UPDATE SQL 方法 ---
|
|
55
50
|
* @param f 表名
|
|
@@ -153,9 +148,9 @@ export declare class Sql {
|
|
|
153
148
|
*/
|
|
154
149
|
group(c: string | string[]): this;
|
|
155
150
|
/**
|
|
156
|
-
* --- LIMIT ---
|
|
157
|
-
* @param a
|
|
158
|
-
* @param b
|
|
151
|
+
* --- LIMIT(limit、offset, limit) ---
|
|
152
|
+
* @param a 起始(offset)
|
|
153
|
+
* @param b 长度(limit)
|
|
159
154
|
*/
|
|
160
155
|
limit(a: number, b?: number): this;
|
|
161
156
|
/**
|
|
@@ -192,11 +187,13 @@ export declare class Sql {
|
|
|
192
187
|
* @param sql
|
|
193
188
|
*/
|
|
194
189
|
append(sql: string): this;
|
|
190
|
+
/** --- 获取占位符 --- */
|
|
191
|
+
placeholder(): string;
|
|
195
192
|
/**
|
|
196
193
|
* --- 对字段进行包裹 ---
|
|
197
194
|
* @param str
|
|
198
195
|
* @param pre 表前缀,仅请在 field 表名时倒入前缀
|
|
199
|
-
* @param suf 表后缀,仅请在 field 表名时倒入后缀,前面加 # 代表要强制 AS
|
|
196
|
+
* @param suf 表后缀,仅请在 field 表名时倒入后缀,前面加 # 代表要强制 AS,可能是分表查询时用
|
|
200
197
|
*/
|
|
201
198
|
field(str: string | number | Array<string | string[]>, pre?: string, suf?: string): string;
|
|
202
199
|
/**
|
|
@@ -213,13 +210,15 @@ export declare class Sql {
|
|
|
213
210
|
export declare function get(ctrPre?: ctr.Ctr | string, opt?: {
|
|
214
211
|
'data'?: kebab.DbValue[];
|
|
215
212
|
'sql'?: string[];
|
|
213
|
+
'service'?: ESERVICE;
|
|
216
214
|
}): Sql;
|
|
217
215
|
/**
|
|
218
|
-
* --- 返回代入后的完整 SQL
|
|
216
|
+
* --- 返回代入后的完整 SQL 字符串,这并不安全不能直接执行,只是用来调试打印 sql 语句 ---
|
|
219
217
|
* @param sql SQL 字符串
|
|
220
218
|
* @param data DATA 数据
|
|
219
|
+
* @param service 服务商,默认 MySQL
|
|
221
220
|
*/
|
|
222
|
-
export declare function format(sql: string, data: kebab.DbValue[]): string;
|
|
221
|
+
export declare function format(sql: string, data: kebab.DbValue[], service?: ESERVICE): string;
|
|
223
222
|
/**
|
|
224
223
|
* --- 将数组兑换为组合的对象(Array/Object mix) ---
|
|
225
224
|
* @param arr 要转换的数组
|