imodel 0.19.3 → 0.20.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 (5) hide show
  1. package/index.d.mts +1676 -1922
  2. package/index.mjs +3108 -3059
  3. package/migrate.d.mts +5 -4
  4. package/migrate.mjs +31 -12
  5. package/package.json +3 -1
package/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * imodel v0.19.3
3
- * (c) 2019-2026 undefined
4
- * @license undefined
2
+ * imodel v0.20.1
3
+ * (c) 2019-2026 猛火Fierflame
4
+ * @license MIT
5
5
  */
6
6
 
7
7
  declare const now: unique symbol;
@@ -17,2115 +17,1783 @@ declare const coefficient$1: unique symbol;
17
17
  declare const values_now: typeof now;
18
18
  declare const values_uuid: typeof uuid;
19
19
  declare namespace values {
20
- export { coefficient$1 as coefficient, decrement$1 as decrement, divide$1 as divide, increment$1 as increment, multiply$1 as multiply, values_now as now, values_uuid as uuid };
20
+ export {
21
+ coefficient$1 as coefficient,
22
+ decrement$1 as decrement,
23
+ divide$1 as divide,
24
+ increment$1 as increment,
25
+ multiply$1 as multiply,
26
+ values_now as now,
27
+ values_uuid as uuid,
28
+ };
21
29
  }
22
30
 
31
+ type deleted = typeof deleted;
32
+ declare const deleted: unique symbol;
33
+ type undeleted = typeof undeleted;
34
+ declare const undeleted: unique symbol;
35
+ type withDeleted = typeof withDeleted;
36
+ declare const withDeleted: unique symbol;
37
+ type FindRange = deleted | undeleted | withDeleted;
38
+
39
+ /** @typedef {SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | SetValue.Coefficient | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[]} SetValue */
40
+ /** @typedef {{[values.increment]: number | bigint}} SetValue.Increment */
41
+ /** @typedef {{[values.decrement]: number | bigint}} SetValue.Decrement */
42
+ /** @typedef {{[values.multiply]: number | bigint}} SetValue.Multiply */
43
+ /** @typedef {{[values.divide]: number | bigint}} SetValue.Divide */
44
+ /** @typedef {{[values.coefficient]: (number | bigint)[]}} SetValue.Coefficient */
23
45
  /**
24
- * @template {keyof FieldType} T
25
- * @overload
26
- * @param {T} type
27
- * @param {{
28
- * nullable?: false;
29
- * array?: false;
30
- * default?: ToType<T, false, false> | symbol;
31
- * [k: string]: any;
32
- * } & FieldDefineOption} [options]
33
- * @returns {FieldDecorator<ToType<T, false, false>>}
46
+ * @param {number | bigint} value
47
+ * @returns {SetValue.Increment}
34
48
  */
35
- declare function field$1<T extends keyof FieldType>(type: T, options?: ({
36
- [k: string]: any;
37
- nullable?: false;
38
- array?: false;
39
- default?: ToType<T, false, false> | symbol;
40
- } & FieldDefineOption) | undefined): FieldDecorator<ToType<T, false, false>>;
49
+ declare function increment(value: number | bigint): SetValue.Increment;
41
50
  /**
42
- * @template {keyof FieldType} T
43
- * @overload
44
- * @param {T} type
45
- * @param {{
46
- * nullable?: false;
47
- * array: true;
48
- * default?: ToType<T, true, false> | symbol;
49
- * [k: string]: any;
50
- * } & FieldDefineOption} options
51
- * @returns {FieldDecorator<ToType<T, true, false>>}
51
+ * @param {number | bigint} value
52
+ * @returns {SetValue.Decrement}
52
53
  */
53
- declare function field$1<T extends keyof FieldType>(type: T, options: {
54
- nullable?: false;
55
- array: true;
56
- default?: ToType<T, true, false> | symbol;
57
- [k: string]: any;
58
- } & FieldDefineOption): FieldDecorator<ToType<T, true, false>>;
54
+ declare function decrement(value: number | bigint): SetValue.Decrement;
59
55
  /**
60
- * @template {keyof FieldType} T
61
- * @overload
62
- * @param {T} type
63
- * @param {true} array
64
- * @param {{
65
- * nullable?: false;
66
- * default?: ToType<T, true, false> | symbol;
67
- * [k: string]: any;
68
- * } & FieldDefineOption} options
69
- * @returns {FieldDecorator<ToType<T, true, false>>}
56
+ * @param {number | bigint} value
57
+ * @returns {SetValue.Multiply}
70
58
  */
71
- declare function field$1<T extends keyof FieldType>(type: T, array: true, options: {
72
- nullable?: false;
73
- default?: ToType<T, true, false> | symbol;
74
- [k: string]: any;
75
- } & FieldDefineOption): FieldDecorator<ToType<T, true, false>>;
59
+ declare function multiply(value: number | bigint): SetValue.Multiply;
76
60
  /**
77
- * @template {keyof FieldType} T
78
- * @overload
79
- * @param {T} type
80
- * @param {{
81
- * nullable: true;
82
- * array?: false;
83
- * default?: ToType<T, false, true> | symbol;
84
- * [k: string]: any;
85
- * } & FieldDefineOption} options
86
- * @returns {FieldDecorator<ToType<T, false, true>>}
61
+ * @param {number | bigint} value
62
+ * @returns {SetValue.Divide}
87
63
  */
88
- declare function field$1<T extends keyof FieldType>(type: T, options: {
89
- nullable: true;
90
- array?: false;
91
- default?: ToType<T, false, true> | symbol;
92
- [k: string]: any;
93
- } & FieldDefineOption): FieldDecorator<ToType<T, false, true>>;
64
+ declare function divide(value: number | bigint): SetValue.Divide;
94
65
  /**
95
- * @template {keyof FieldType} T
96
- * @overload
97
- * @param {T} type
98
- * @param {{
99
- * nullable: true;
100
- * array: true;
101
- * default?: ToType<T, true, true> | symbol;
102
- * [k: string]: any;
103
- * } & FieldDefineOption} options
104
- * @returns {FieldDecorator<ToType<T, true, true>>}
66
+ * @param {...number | bigint} value
67
+ * @returns {SetValue.Coefficient}
105
68
  */
106
- declare function field$1<T extends keyof FieldType>(type: T, options: {
107
- nullable: true;
108
- array: true;
109
- default?: ToType<T, true, true> | symbol;
110
- [k: string]: any;
111
- } & FieldDefineOption): FieldDecorator<ToType<T, true, true>>;
69
+ declare function coefficient(...value: (number | bigint)[]): SetValue.Coefficient;
70
+ type SetValue = SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | SetValue.Coefficient | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[];
71
+ declare namespace SetValue {
72
+ type Increment = {
73
+ [increment$1]: number | bigint;
74
+ };
75
+ type Decrement = {
76
+ [decrement$1]: number | bigint;
77
+ };
78
+ type Multiply = {
79
+ [multiply$1]: number | bigint;
80
+ };
81
+ type Divide = {
82
+ [divide$1]: number | bigint;
83
+ };
84
+ type Coefficient = {
85
+ [coefficient$1]: (number | bigint)[];
86
+ };
87
+ }
88
+
89
+ type Select = {
90
+ field: string;
91
+ table?: string;
92
+ fn?: string;
93
+ };
94
+ declare namespace Select {
95
+ type Param = boolean | string | Select;
96
+ }
97
+ type JoinType = 'left' | 'right' | 'inner' | 'full';
98
+ interface Join<T extends TableDefine = TableDefine> {
99
+ type: JoinType;
100
+ table: T;
101
+ /** 关联项目 { [this table field]: base table field } */
102
+ on: {
103
+ [k: string]: string;
104
+ };
105
+ }
106
+ interface Options {
107
+ distinct?: boolean;
108
+ range?: FindRange;
109
+ select?: Record<string, Select> | null;
110
+ /** 排序配置,true 表示逆序 */
111
+ sort?: [field: string, desc: boolean][];
112
+ /** 匹配信息 */
113
+ where: WhereValue[];
114
+ /** 偏移量 */
115
+ offset?: number;
116
+ /** 最大返回数 */
117
+ limit?: number;
118
+ update?: Record<string, SetValue>;
119
+ alias?: string;
120
+ group?: string[];
121
+ lock?: 'S' | 'X' | null;
122
+ }
123
+ interface Queryable<T extends Fields = Fields> extends TableDefine<T> {
124
+ readonly options: Options;
125
+ }
126
+
127
+ interface ColumnOptions<T = unknown> extends FieldDefineOption {
128
+ /**
129
+ * 是否可为空
130
+ * @default true
131
+ */
132
+ nullable?: boolean;
133
+ /** 是否为数组格式 */
134
+ array?: boolean;
135
+ /** 默认值 */
136
+ default?: T extends never ? never : T;
137
+ }
138
+ interface Column<T> extends ColumnOptions<T> {
139
+ column: string;
140
+ type: string;
141
+ }
142
+
143
+ declare class ConnectionError extends Error {
144
+ /**
145
+ * @param {string} code - 自定义通用错误码 (例如 constraint:unique)
146
+ * @param {string} message - 原始错误信息或自定义信息
147
+ */
148
+ constructor(code: string, message: string);
149
+ /** @type {string} */
150
+ code: string;
151
+ }
112
152
  /**
113
- * @template {keyof FieldType} T
114
- * @overload
115
- * @param {T} type
116
- * @param {true} array
117
- * @param {{
118
- * nullable: true;
119
- * default?: ToType<T, true, true> | symbol;
120
- * [k: string]: any;
121
- * } & FieldDefineOption} options
122
- * @returns {FieldDecorator<ToType<T, true, true>>}
153
+ * 非空约束违规
154
+ * 对应 PG 23502 / MySQL 1048
155
+ * 场景:插入数据时,必填字段为空
123
156
  */
124
- declare function field$1<T extends keyof FieldType>(type: T, array: true, options: {
125
- nullable: true;
126
- default?: ToType<T, true, true> | symbol;
127
- [k: string]: any;
128
- } & FieldDefineOption): FieldDecorator<ToType<T, true, true>>;
157
+ declare class NotNullViolationError extends ConnectionError {
158
+ /** @type {string} */
159
+ table: string;
160
+ /** @type {string} */
161
+ column: string;
162
+ }
129
163
  /**
130
- * @template {keyof FieldType} T
131
- * @template {boolean} A
132
- * @overload
133
- * @param {T} type
134
- * @param {{
135
- * nullable: true;
136
- * array: A;
137
- * default?: ToType<T, A, true> | symbol;
138
- * [k: string]: any;
139
- * } & FieldDefineOption} options
140
- * @returns {FieldDecorator<ToType<T, A, true>>}
164
+ * 唯一性约束违规
165
+ * 对应 PG 23505 / MySQL 1062
166
+ * 支持单字段和多字段组合冲突
141
167
  */
142
- declare function field$1<T extends keyof FieldType, A extends boolean>(type: T, options: {
143
- nullable: true;
144
- array: A;
145
- default?: ToType<T, A, true> | symbol;
146
- [k: string]: any;
147
- } & FieldDefineOption): FieldDecorator<ToType<T, A, true>>;
168
+ declare class UniqueViolationError extends ConnectionError {
169
+ /**
170
+ * @param {string} table - 表名
171
+ * @param {string | string[]} columns - 冲突的列名(可以是字符串或字符串数组)
172
+ * @param {any} [values] - 导致冲突的值(可选,多字段时为对象或数组)
173
+ */
174
+ constructor(table: string, columns: string | string[], values?: any);
175
+ /** @type {string} */
176
+ table: string;
177
+ /** @type {string[]} */
178
+ columns: string[];
179
+ /** @type {any} */
180
+ values: any;
181
+ }
148
182
  /**
149
- * @template {keyof FieldType} T
150
- * @template {boolean} A
151
- * @overload
152
- * @param {T} type
153
- * @param {{
154
- * nullable?: false;
155
- * array: A;
156
- * default?: ToType<T, A, false> | symbol;
157
- * [k: string]: any;
158
- * } & FieldDefineOption} options
159
- * @returns {FieldDecorator<ToType<T, A, false>>}
160
- */
161
- declare function field$1<T extends keyof FieldType, A extends boolean>(type: T, options: {
162
- nullable?: false;
163
- array: A;
164
- default?: ToType<T, A, false> | symbol;
165
- [k: string]: any;
166
- } & FieldDefineOption): FieldDecorator<ToType<T, A, false>>;
167
- /**
168
- * @template {keyof FieldType} T
169
- * @template {boolean} N
170
- * @overload
171
- * @param {T} type
172
- * @param {{
173
- * nullable: N;
174
- * array?: false;
175
- * default?: ToType<T, false, N> | symbol;
176
- * [k: string]: any;
177
- * } & FieldDefineOption} options
178
- * @returns {FieldDecorator<ToType<T, false, N>>}
179
- */
180
- declare function field$1<T extends keyof FieldType, N extends boolean>(type: T, options: {
181
- nullable: N;
182
- array?: false;
183
- default?: ToType<T, false, N> | symbol;
184
- [k: string]: any;
185
- } & FieldDefineOption): FieldDecorator<ToType<T, false, N>>;
186
- /**
187
- * @template {keyof FieldType} T
188
- * @template {boolean} N
189
- * @overload
190
- * @param {T} type
191
- * @param {{
192
- * nullable: N;
193
- * array: true;
194
- * default?: ToType<T, true, N> | symbol;
195
- * [k: string]: any;
196
- * } & FieldDefineOption} options
197
- * @returns {FieldDecorator<ToType<T, true, N>>}
198
- */
199
- declare function field$1<T extends keyof FieldType, N extends boolean>(type: T, options: {
200
- nullable: N;
201
- array: true;
202
- default?: ToType<T, true, N> | symbol;
203
- [k: string]: any;
204
- } & FieldDefineOption): FieldDecorator<ToType<T, true, N>>;
205
- /**
206
- * @template {keyof FieldType} T
207
- * @template {boolean} N
208
- * @overload
209
- * @param {T} type
210
- * @param {true} array
211
- * @param {{
212
- * nullable: N;
213
- * default?: ToType<T, true, N> | symbol;
214
- * [k: string]: any;
215
- * } & FieldDefineOption} options
216
- * @returns {FieldDecorator<ToType<T, true, N>>}
217
- */
218
- declare function field$1<T extends keyof FieldType, N extends boolean>(type: T, array: true, options: {
219
- nullable: N;
220
- default?: ToType<T, true, N> | symbol;
221
- [k: string]: any;
222
- } & FieldDefineOption): FieldDecorator<ToType<T, true, N>>;
223
- /**
224
- * @template {keyof FieldType} T
225
- * @template {boolean} A
226
- * @template {boolean} N
227
- * @overload
228
- * @param {T} type
229
- * @param {{
230
- * nullable: N;
231
- * array: A;
232
- * default?: ToType<T, A, N> | symbol;
233
- * [k: string]: any;
234
- * } & FieldDefineOption} options
235
- * @returns {FieldDecorator<ToType<T, A, N>>}
236
- */
237
- declare function field$1<T extends keyof FieldType, A extends boolean, N extends boolean>(type: T, options: {
238
- nullable: N;
239
- array: A;
240
- default?: ToType<T, A, N> | symbol;
241
- [k: string]: any;
242
- } & FieldDefineOption): FieldDecorator<ToType<T, A, N>>;
243
- /**
244
- * @template {keyof FieldType} T
245
- * @overload
246
- * @param {T} type
247
- * @param {{
248
- * nullable?: boolean;
249
- * array?: boolean;
250
- * default?: ToType<T, boolean, boolean> | symbol;
251
- * [k: string]: any;
252
- * } & FieldDefineOption} options
253
- * @returns {FieldDecorator<ToType<T, boolean, boolean>>}
254
- */
255
- declare function field$1<T extends keyof FieldType>(type: T, options: {
256
- nullable?: boolean;
257
- array?: boolean;
258
- default?: ToType<T, boolean, boolean> | symbol;
259
- [k: string]: any;
260
- } & FieldDefineOption): FieldDecorator<ToType<T, boolean, boolean>>;
261
-
262
- /** @import { FieldDecorator } from './index.mjs' */
263
- /**
264
- * @param {string} prop
265
- * @param {any} value
266
- * @param {boolean} [array]
267
- * @param {boolean} [end]
268
- * @returns {FieldDecorator<any>}
269
- */
270
- declare function prop(prop: string, value: any, array?: boolean, end?: boolean): FieldDecorator<any>;
271
-
272
- /** @import { FieldDecorator } from './index.mjs' */
273
- /**
274
- *
275
- * @param {string} [column]
276
- * @returns {FieldDecorator<any>}
277
- */
278
- declare function column(column?: string): FieldDecorator<any>;
279
-
280
- /** @import { FieldDecorator } from './index.mjs' */
281
- /**
282
- *
283
- * @param {number} [primary]
284
- * @returns {FieldDecorator<any>}
183
+ * 外键约束违规
184
+ * 对应 PG 23503 / MySQL 1452
185
+ * 场景:插入了一个不存在的 user_id
285
186
  */
286
- declare function primary(primary?: number): FieldDecorator<any>;
287
-
288
- /** @import { FieldDecorator } from './index.mjs' */
289
- /** @returns {FieldDecorator<any>} */
290
- declare function uncreatable(): FieldDecorator<any>;
291
-
292
- /** @import { FieldDecorator } from './index.mjs' */
293
- /** @returns {FieldDecorator<any>} */
294
- declare function immutable(): FieldDecorator<any>;
295
-
187
+ declare class ForeignKeyViolationError extends ConnectionError {
188
+ /**
189
+ * @param {string} table - 当前操作的表
190
+ * @param {string | string[]} columns - 当前操作的外键列
191
+ * @param {string} [referencedTable] - 被引用的父表
192
+ */
193
+ constructor(table: string, columns: string | string[], referencedTable?: string);
194
+ /** @type {string} */
195
+ table: string;
196
+ /** @type {string[]} */
197
+ columns: string[];
198
+ /** @type {string} */
199
+ referencedTable: string;
200
+ }
296
201
  /**
297
- * 索引信息
298
- * @overload
299
- * @param {string[]} fields
300
- * @param {IndexOptions} [options]
301
- * @returns {ClassDecorator}
202
+ * 检查约束违规
203
+ * 对应 PG 23514
204
+ * 场景:年龄字段要求 > 0,但插入了 -5
302
205
  */
303
- declare function index(fields: string[], options?: IndexOptions | undefined): ClassDecorator;
206
+ declare class CheckViolationError extends ConnectionError {
207
+ /**
208
+ * @param {string} table - 当前操作的表
209
+ * @param {string} [constraint] - 当前操作的外键列
210
+ */
211
+ constructor(table: string, constraint?: string);
212
+ /** @type {string} */
213
+ table: string;
214
+ /** @type {string} */
215
+ constraint: string;
216
+ }
304
217
  /**
305
- * 索引信息
306
- * @overload
307
- * @param {string} [name]
308
- * @param {boolean} [unique]
309
- * @returns {FieldDecorator<any>}
218
+ * 无效的类型输入语法错误
219
+ * 对应 PG 22P02
220
+ * 场景:无效的 UUID、日期格式错误等
310
221
  */
311
- declare function index(name?: string | undefined, unique?: boolean | undefined): FieldDecorator<any>;
222
+ declare class InvalidInputSyntaxError extends ConnectionError {
223
+ /**
224
+ * @param {string} message - 目标数据类型
225
+ */
226
+ constructor(message: string);
227
+ }
312
228
  /**
313
- * 索引信息
314
- * @overload
315
- * @param {boolean} [unique]
316
- * @returns {FieldDecorator<any>}
229
+ * 操作符不匹配错误
230
+ * 对应 PG 42883
231
+ * 场景:uuid = integer 等类型不兼容的操作
317
232
  */
318
- declare function index(unique?: boolean | undefined): FieldDecorator<any>;
233
+ declare class OperatorMismatchError extends ConnectionError {
234
+ /**
235
+ * @param {string} message
236
+ */
237
+ constructor(message: string);
238
+ }
319
239
 
320
- /** @import { FieldDecorator } from './index.mjs' */
321
- /**
322
- * 默认排序顺序,绝对值表示在排序列表中的顺序,负数表示逆序排序, 0 表示不排序
323
- * @param {number} sort
324
- * @returns {FieldDecorator<any>}
325
- */
326
- declare function sort(sort: number): FieldDecorator<any>;
240
+ type errors_CheckViolationError = CheckViolationError;
241
+ declare const errors_CheckViolationError: typeof CheckViolationError;
242
+ type errors_ConnectionError = ConnectionError;
243
+ declare const errors_ConnectionError: typeof ConnectionError;
244
+ type errors_ForeignKeyViolationError = ForeignKeyViolationError;
245
+ declare const errors_ForeignKeyViolationError: typeof ForeignKeyViolationError;
246
+ type errors_InvalidInputSyntaxError = InvalidInputSyntaxError;
247
+ declare const errors_InvalidInputSyntaxError: typeof InvalidInputSyntaxError;
248
+ type errors_NotNullViolationError = NotNullViolationError;
249
+ declare const errors_NotNullViolationError: typeof NotNullViolationError;
250
+ type errors_OperatorMismatchError = OperatorMismatchError;
251
+ declare const errors_OperatorMismatchError: typeof OperatorMismatchError;
252
+ type errors_UniqueViolationError = UniqueViolationError;
253
+ declare const errors_UniqueViolationError: typeof UniqueViolationError;
254
+ declare namespace errors {
255
+ export {
256
+ errors_CheckViolationError as CheckViolationError,
257
+ errors_ConnectionError as ConnectionError,
258
+ errors_ForeignKeyViolationError as ForeignKeyViolationError,
259
+ errors_InvalidInputSyntaxError as InvalidInputSyntaxError,
260
+ errors_NotNullViolationError as NotNullViolationError,
261
+ errors_OperatorMismatchError as OperatorMismatchError,
262
+ errors_UniqueViolationError as UniqueViolationError,
263
+ };
264
+ }
327
265
 
328
- /** @import { ClassDecorator } from './index.mjs' */
329
- /**
330
- *
331
- * @param {string} pseudo
332
- * @returns {ClassDecorator}
333
- */
334
- declare function pseudo(pseudo: string): ClassDecorator;
266
+ interface BaseEnvironment {
267
+ isDevelopment: boolean;
268
+ values: typeof values;
269
+ errors: typeof errors;
270
+ }
271
+ interface Environment<T extends object> extends BaseEnvironment {
272
+ readonly transaction: T | null;
273
+ }
335
274
 
336
- /**
337
- * @template T
338
- * @overload
339
- * @param {now} value
340
- * @returns {FieldDecorator<string | Date>}
341
- */
342
- declare function defaultValue<T>(value: symbol): FieldDecorator<string | Date>;
343
- /**
344
- * @template T
345
- * @overload
346
- * @param {uuid} value
347
- * @returns {FieldDecorator<string>}
348
- */
349
- declare function defaultValue<T>(value: symbol): FieldDecorator<string>;
350
- /**
351
- * @template T
352
- * @overload
353
- * @param {T} value
354
- * @returns {FieldDecorator<T>}
355
- */
356
- declare function defaultValue<T>(value: T): FieldDecorator<T>;
357
-
358
- /**
359
- *
360
- * @overload
361
- * @param {string} table
362
- * @returns {ClassDecorator}
363
- */
364
- declare function model(table: string): ClassDecorator;
365
- /**
366
- * @template {Record<string, any>} T
367
- * @overload
368
- * @param {TableDefine & {new(...a: any): T}} type
369
- * @param {Record<string, Constraint>} constraints
370
- * @param {true} array
371
- * @param {FieldDefineOption} [options]
372
- * @returns {FieldDecorator<T[]>}
373
- */
374
- declare function model<T extends Record<string, any>>(type: TableDefine & {
375
- new (...a: any): T;
376
- }, constraints: Record<string, Constraint>, array: true, options?: FieldDefineOption | undefined): FieldDecorator<T[]>;
377
- /**
378
- * @template {Record<string, any>} T
379
- * @overload
380
- * @param {TableDefine & {new(...a: any): T}} type
381
- * @param {Record<string, Constraint>} constraints
382
- * @param {false} [array]
383
- * @param {FieldDefineOption} [options]
384
- * @returns {FieldDecorator<T>}
385
- */
386
- declare function model<T extends Record<string, any>>(type: TableDefine & {
387
- new (...a: any): T;
388
- }, constraints: Record<string, Constraint>, array?: false | undefined, options?: FieldDefineOption | undefined): FieldDecorator<T>;
389
- /**
390
- * @template {Record<string, any>} T
391
- * @overload
392
- * @param {TableDefine & {new(...a: any): T}} type
393
- * @param {Record<string, Constraint>} constraints
394
- * @param {FieldDefineOption} [options]
395
- * @returns {FieldDecorator<T>}
396
- */
397
- declare function model<T extends Record<string, any>>(type: TableDefine & {
398
- new (...a: any): T;
399
- }, constraints: Record<string, Constraint>, options?: FieldDefineOption | undefined): FieldDecorator<T>;
400
- /**
401
- * @template {Record<string, any>} T
402
- * @template {boolean} [A=boolean]
403
- * @overload
404
- * @param {TableDefine & {new(...a: any): T}} type
405
- * @param {Record<string, Constraint>} constraints
406
- * @param {A} array
407
- * @param {FieldDefineOption} [options]
408
- * @returns {FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>}
409
- */
410
- declare function model<T extends Record<string, any>, A extends boolean = boolean>(type: TableDefine & {
411
- new (...a: any): T;
412
- }, constraints: Record<string, Constraint>, array: A, options?: FieldDefineOption | undefined): FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>;
413
- /**
414
- * @template {object} T
415
- * @overload
416
- * @param {TableDefine} type
417
- * @param {Record<string, Constraint>} constraints
418
- * @param {true} array
419
- * @param {FieldDefineOption} [options]
420
- * @returns {FieldDecorator<T[]>}
421
- */
422
- declare function model<T extends Record<string, any>>(type: TableDefine, constraints: Record<string, Constraint>, array: true, options?: FieldDefineOption | undefined): FieldDecorator<T[]>;
423
- /**
424
- * @template {object} T
425
- * @overload
426
- * @param {TableDefine} type
427
- * @param {Record<string, Constraint>} constraints
428
- * @param {false} [array]
429
- * @param {FieldDefineOption} [options]
430
- * @returns {FieldDecorator<T>}
431
- */
432
- declare function model<T extends Record<string, any>>(type: TableDefine, constraints: Record<string, Constraint>, array?: false | undefined, options?: FieldDefineOption | undefined): FieldDecorator<T>;
433
- /**
434
- * @template {object} T
435
- * @overload
436
- * @param {TableDefine} type
437
- * @param {Record<string, Constraint>} constraints
438
- * @param {FieldDefineOption} [options]
439
- * @returns {FieldDecorator<T>}
440
- */
441
- declare function model<T extends Record<string, any>>(type: TableDefine, constraints: Record<string, Constraint>, options?: FieldDefineOption | undefined): FieldDecorator<T>;
442
- /**
443
- * @template {object} T
444
- * @template {boolean} [A=boolean]
445
- * @overload
446
- * @param {TableDefine} type
447
- * @param {Record<string, Constraint>} constraints
448
- * @param {A} array
449
- * @param {FieldDefineOption} [options]
450
- * @returns {FieldDecorator<A extends false ? T :A extends true ? T[] : T | T[]>}
451
- */
452
- declare function model<T extends Record<string, any>, A extends boolean = boolean>(type: TableDefine, constraints: Record<string, Constraint>, array: A, options?: FieldDefineOption | undefined): FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>;
453
-
454
- /**
455
- * @param {number} [size]
456
- * @returns {FieldDecorator<Date?>}
457
- */
458
- declare function creating(size?: number): FieldDecorator<Date | null>;
459
- /**
460
- * @param {number} [size]
461
- * @returns {FieldDecorator<Date?>}
462
- */
463
- declare function updating(size?: number): FieldDecorator<Date | null>;
464
- /**
465
- * @param {number} [size]
466
- * @returns {FieldDecorator<Date?>}
467
- */
468
- declare function deleting(size?: number): FieldDecorator<Date | null>;
469
-
470
- /**
471
- * @overload
472
- * @param {Partial<Hooks>} hook
473
- * @param {boolean} [approach] 插入位置是否为更靠近执行的位置
474
- * @returns {ClassDecorator}
475
- */
476
- declare function hooks(hook: Partial<Hooks>, approach?: boolean | undefined): ClassDecorator;
477
- /**
478
- * @overload
479
- * @param {Function} Model
480
- * @param {Partial<Hooks>} hook
481
- * @param {boolean} [approach] 插入位置是否为更靠近执行的位置
482
- * @returns {void}
483
- */
484
- declare function hooks(Model: Function, hook: Partial<Hooks>, approach?: boolean | undefined): void;
485
- /** @type {Hook<Hooks['where']>} */
486
- declare const where: Hook<Hooks["where"]>;
487
- /** @type {Hook<Hooks['beforeCreateMany']>} */
488
- declare const beforeCreateMany: Hook<Hooks["beforeCreateMany"]>;
489
- /** @type {Hook<Hooks['afterCreateMany']>} */
490
- declare const afterCreateMany: Hook<Hooks["afterCreateMany"]>;
491
- /** @type {Hook<Hooks['beforeCreate']>} */
492
- declare const beforeCreate: Hook<Hooks["beforeCreate"]>;
493
- /** @type {Hook<Hooks['afterCreate']>} */
494
- declare const afterCreate: Hook<Hooks["afterCreate"]>;
495
- /** @type {Hook<Hooks['beforeUpdate']>} */
496
- declare const beforeUpdate: Hook<Hooks["beforeUpdate"]>;
497
- /** @type {Hook<Hooks['afterUpdate']>} */
498
- declare const afterUpdate: Hook<Hooks["afterUpdate"]>;
499
- /** @type {Hook<Hooks['beforeDelete']>} */
500
- declare const beforeDelete: Hook<Hooks["beforeDelete"]>;
501
- /** @type {Hook<Hooks['afterDelete']>} */
502
- declare const afterDelete: Hook<Hooks["afterDelete"]>;
503
-
504
- type ClassDecorator = (val: Function, ctx: ClassDecoratorContext) => any;
505
- type FieldDecorator<T> = (val: {
506
- get(): T;
507
- set(v: T): void;
508
- }, ctx: ClassAccessorDecoratorContext) => any;
509
- type MethodDecorator<T extends Function> = (val: T, ctx: ClassMethodDecoratorContext<any, T>) => any;
510
-
511
- declare class ConnectionError extends Error {
512
- /**
513
- * @param {string} code - 自定义通用错误码 (例如 constraint:unique)
514
- * @param {string} message - 原始错误信息或自定义信息
515
- */
516
- constructor(code: string, message: string);
517
- /** @type {string} */
518
- code: string;
519
- }
520
- /**
521
- * 非空约束违规
522
- * 对应 PG 23502 / MySQL 1048
523
- * 场景:插入数据时,必填字段为空
524
- */
525
- declare class NotNullViolationError extends ConnectionError {
526
- /** @type {string} */
527
- table: string;
528
- /** @type {string} */
529
- column: string;
275
+ type TableType = '' | 'table' | 'view';
276
+ interface FindArg {
277
+ /** 排序配置,true 表示逆序 */
278
+ sort?: [field: string, desc: boolean][];
279
+ /** 匹配信息 */
280
+ where: WhereValue[];
281
+ select: [string, Select][];
282
+ /** 偏移量 */
283
+ offset?: number;
284
+ /** 最大返回数 */
285
+ limit?: number;
530
286
  }
531
- /**
532
- * 唯一性约束违规
533
- * 对应 PG 23505 / MySQL 1062
534
- * 支持单字段和多字段组合冲突
535
- */
536
- declare class UniqueViolationError extends ConnectionError {
537
- /**
538
- * @param {string} table - 表名
539
- * @param {string | string[]} columns - 冲突的列名(可以是字符串或字符串数组)
540
- * @param {any} [values] - 导致冲突的值(可选,多字段时为对象或数组)
541
- */
542
- constructor(table: string, columns: string | string[], values?: any);
543
- /** @type {string} */
287
+ interface JOIN {
288
+ type?: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL' | 'CROSS';
544
289
  table: string;
545
- /** @type {string[]} */
546
- columns: string[];
547
- /** @type {any} */
548
- values: any;
290
+ columns: Record<string, DBColumn>;
291
+ alias?: string;
292
+ condition?: WhereValue[];
549
293
  }
550
- /**
551
- * 外键约束违规
552
- * 对应 PG 23503 / MySQL 1452
553
- * 场景:插入了一个不存在的 user_id
554
- */
555
- declare class ForeignKeyViolationError extends ConnectionError {
556
- /**
557
- * @param {string} table - 当前操作的表
558
- * @param {string | string[]} columns - 当前操作的外键列
559
- * @param {string} [referencedTable] - 被引用的父表
560
- */
561
- constructor(table: string, columns: string | string[], referencedTable?: string);
562
- /** @type {string} */
294
+ type LockType = 'S' | 'X';
295
+ interface IDBTable {
563
296
  table: string;
564
- /** @type {string[]} */
565
- columns: string[];
566
- /** @type {string} */
567
- referencedTable: string;
297
+ columns: Record<string, DBColumn>;
568
298
  }
569
- /**
570
- * 检查约束违规
571
- * 对应 PG 23514
572
- * 场景:年龄字段要求 > 0,但插入了 -5
573
- */
574
- declare class CheckViolationError extends ConnectionError {
575
- /**
576
- * @param {string} table - 当前操作的表
577
- * @param {string} [constraint] - 当前操作的外键列
578
- */
579
- constructor(table: string, constraint?: string);
580
- /** @type {string} */
581
- table: string;
582
- /** @type {string} */
583
- constraint: string;
299
+ interface SelectItem extends IDBTable {
300
+ distinct?: boolean;
301
+ select: [string, Select][];
302
+ alias?: string;
303
+ /** 匹配信息 */
304
+ where: WhereValue[];
305
+ group: string[];
306
+ having: WhereValue[];
307
+ /** 排序配置,true 表示逆序 */
308
+ sort: [field: string, desc: boolean][];
309
+ /** 偏移量 */
310
+ offset?: number;
311
+ /** 最大返回数 */
312
+ limit?: number;
313
+ lock?: LockType | null;
584
314
  }
585
- /**
586
- * 无效的类型输入语法错误
587
- * 对应 PG 22P02
588
- * 场景:无效的 UUID、日期格式错误等
589
- */
590
- declare class InvalidInputSyntaxError extends ConnectionError {
591
- /**
592
- * @param {string} message - 目标数据类型
593
- */
594
- constructor(message: string);
315
+ type GetName = (table?: string) => string;
316
+ interface DBColumn {
317
+ type: string;
318
+ size?: number;
319
+ scale?: number;
320
+ default?: any;
321
+ nullable?: boolean;
322
+ array?: boolean;
323
+ primary?: number;
595
324
  }
596
- /**
597
- * 操作符不匹配错误
598
- * 对应 PG 42883
599
- * 场景:uuid = integer 等类型不兼容的操作
600
- */
601
- declare class OperatorMismatchError extends ConnectionError {
602
- /**
603
- * @param {string} message
604
- */
605
- constructor(message: string);
325
+ interface DBIndex {
326
+ fields: string[];
327
+ includes?: string[];
328
+ unique?: boolean;
329
+ name?: string;
606
330
  }
607
-
608
- type errors_CheckViolationError = CheckViolationError;
609
- declare const errors_CheckViolationError: typeof CheckViolationError;
610
- type errors_ConnectionError = ConnectionError;
611
- declare const errors_ConnectionError: typeof ConnectionError;
612
- type errors_ForeignKeyViolationError = ForeignKeyViolationError;
613
- declare const errors_ForeignKeyViolationError: typeof ForeignKeyViolationError;
614
- type errors_InvalidInputSyntaxError = InvalidInputSyntaxError;
615
- declare const errors_InvalidInputSyntaxError: typeof InvalidInputSyntaxError;
616
- type errors_NotNullViolationError = NotNullViolationError;
617
- declare const errors_NotNullViolationError: typeof NotNullViolationError;
618
- type errors_OperatorMismatchError = OperatorMismatchError;
619
- declare const errors_OperatorMismatchError: typeof OperatorMismatchError;
620
- type errors_UniqueViolationError = UniqueViolationError;
621
- declare const errors_UniqueViolationError: typeof UniqueViolationError;
622
- declare namespace errors {
623
- export { errors_CheckViolationError as CheckViolationError, errors_ConnectionError as ConnectionError, errors_ForeignKeyViolationError as ForeignKeyViolationError, errors_InvalidInputSyntaxError as InvalidInputSyntaxError, errors_NotNullViolationError as NotNullViolationError, errors_OperatorMismatchError as OperatorMismatchError, errors_UniqueViolationError as UniqueViolationError };
331
+ interface DBTable {
332
+ table: string;
333
+ fields: Record<string, DBColumn>;
334
+ indexes?: DBIndex[];
335
+ primary?: string;
624
336
  }
625
-
626
- interface Environment<T extends object> {
627
- transaction: T | null;
628
- isDevelopment: boolean;
629
- values: typeof values;
630
- errors: typeof errors;
337
+ interface Savepoint {
338
+ readonly name: string;
339
+ rollback(): Promise<void>;
340
+ release(): Promise<void>;
341
+ [Symbol.asyncDispose](): Promise<void>;
631
342
  }
632
-
633
- /** 特性支持情况 */
634
- interface Support {
635
- /** 是否支持 sql 查询 */
636
- sql?: boolean;
637
- /** 是否支持数组类型 */
638
- array?: boolean;
639
- /** 是否支持对象存储 */
640
- object?: boolean;
641
- /** 是否支持递归查询 */
642
- recursive?: boolean;
643
- [key: string]: undefined | boolean;
343
+ interface ConnectionInterface {
344
+ dbType(): Promise<string>;
345
+ dbVersion(): Promise<string>;
346
+ query(...values: any[]): Promise<any[]>;
347
+ exec(...values: any[]): Promise<number>;
348
+ type(table: string): Promise<TableType | null>;
349
+ insert(table: IDBTable, data: object[], key: string[], conflictTarget?: string[] | boolean, conflictSet?: Record<string, SetValue> | boolean, conflictWhere?: WhereValue[]): PromiseLike<any[]>;
350
+ update(table: IDBTable, update: Record<string, SetValue>, where?: WhereValue[]): PromiseLike<number>;
351
+ updateReturn(returning: string[], table: IDBTable, update: Record<string, SetValue>, where?: WhereValue[]): PromiseLike<any[]>;
352
+ updateList(table: IDBTable, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
353
+ updateListReturn(returning: string[], table: IDBTable, update: Record<string, any>, primaryKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<any[]>;
354
+ count(table: IDBTable, where?: WhereValue[]): PromiseLike<number>;
355
+ select(select: SelectItem): PromiseLike<any[]>;
356
+ delete(table: IDBTable, where?: WhereValue[]): PromiseLike<number>;
357
+ deleteReturn(returning: string[], table: IDBTable, where?: WhereValue[]): PromiseLike<any[]>;
358
+ transaction<T>(fn: (signal: AbortSignal) => PromiseLike<T> | T): PromiseLike<T>;
359
+ abort(): boolean;
360
+ savepoint(): PromiseLike<Savepoint>;
644
361
  }
645
-
646
- interface ColumnOptions<T = unknown> extends FieldDefineOption {
362
+ interface TableConnect {
363
+ (conn: ConnectionInterface, env: BaseEnvironment): ConnectionInterface;
364
+ }
365
+ interface Action<T> {
366
+ invoke(connect: () => Promise<ConnectionInterface>, connection: Connection, environment: BaseEnvironment): PromiseLike<T> | T;
367
+ connect?: TableConnect | null;
368
+ }
369
+ interface TableConnection<E extends object = object> {
370
+ insert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[], conflictTarget?: string[] | boolean, conflictSet?: Record<string, SetValue> | boolean, conflictWhere?: WhereValue[] | null): PromiseLike<any[]>;
371
+ update(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
372
+ updateReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
373
+ updateMany(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
374
+ updateManyReturn(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
375
+ count(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
376
+ select(environment: Environment<E>, select: SelectItem[]): PromiseLike<any[]>;
377
+ delete(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
378
+ deleteReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
379
+ }
380
+ interface IConnection<E extends object = object> extends TableConnection<E> {
381
+ /** 数据库类型 */
382
+ readonly dbType: string;
383
+ /** 数据库版本 */
384
+ dbVersion(environment: Environment<E>): PromiseLike<string>;
385
+ exec(environment: Environment<E>, ...values: any): Promise<number>;
647
386
  /**
648
- * 是否可为空
649
- * @default true
387
+ * 执行一条语句
388
+ * @param sql 要执行的 SQL 语句
650
389
  */
651
- nullable?: boolean;
652
- /** 是否为数组格式 */
653
- array?: boolean;
654
- /** 默认值 */
655
- default?: T extends never ? never : T;
390
+ query(environment: Environment<E>, ...values: any): PromiseLike<any[]>;
391
+ type(environment: Environment<E>, table: string): PromiseLike<TableType | null>;
392
+ createSavepoint(environment: Environment<E>, name: string): PromiseLike<void>;
393
+ rollbackSavepoint(environment: Environment<E>, name: string): PromiseLike<void>;
394
+ releaseSavepoint(environment: Environment<E>, name: string): PromiseLike<void>;
395
+ createTable(environment: Environment<E>, table: string, columns: Column<any>[]): PromiseLike<number>;
396
+ dropTable(environment: Environment<E>, table: string): PromiseLike<number>;
397
+ renameTable(environment: Environment<E>, table: string, newName: string): PromiseLike<number>;
398
+ addColumn(environment: Environment<E>, table: string, column: string, type: string, options: ColumnOptions<any>): PromiseLike<number>;
399
+ changeColumn(environment: Environment<E>, table: string, column: string, type: string, options: ColumnOptions<any>): PromiseLike<number>;
400
+ changeColumnNull(environment: Environment<E>, table: string, column: string, nullable: boolean): PromiseLike<number>;
401
+ dropColumn(environment: Environment<E>, table: string, column: string): PromiseLike<number>;
402
+ renameColumn(environment: Environment<E>, table: string, column: string, newName: string): PromiseLike<number>;
403
+ addIndex(environment: Environment<E>, table: string, name: string, columns: string[], options: IndexOptions): PromiseLike<number>;
404
+ dropIndex(environment: Environment<E>, table: string, name: string): PromiseLike<number>;
405
+ loadTables(environment: Environment<E>, tables: string[]): PromiseLike<DBTable[]>;
406
+ syncTables(environment: Environment<E>, tables: DBTable[]): PromiseLike<void>;
407
+ transaction<R>(environment: Environment<E>, fn: (t: E) => R | PromiseLike<R>): PromiseLike<R>;
656
408
  }
657
- interface Column<T> extends ColumnOptions<T> {
658
- column: string;
659
- type: string;
409
+ interface Skip {
410
+ uncreatable?: boolean;
411
+ immutable?: boolean;
412
+ specific?: boolean;
413
+ where?: boolean;
660
414
  }
661
-
662
- /** @typedef {SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | SetValue.Coefficient | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[]} SetValue */
663
- /** @typedef {{[values.increment]: number | bigint}} SetValue.Increment */
664
- /** @typedef {{[values.decrement]: number | bigint}} SetValue.Decrement */
665
- /** @typedef {{[values.multiply]: number | bigint}} SetValue.Multiply */
666
- /** @typedef {{[values.divide]: number | bigint}} SetValue.Divide */
667
- /** @typedef {{[values.coefficient]: (number | bigint)[]}} SetValue.Coefficient */
668
- /**
669
- * @param {number | bigint} value
670
- * @returns {SetValue.Increment}
671
- */
672
- declare function increment(value: number | bigint): SetValue.Increment;
673
- /**
674
- * @param {number | bigint} value
675
- * @returns {SetValue.Decrement}
676
- */
677
- declare function decrement(value: number | bigint): SetValue.Decrement;
678
- /**
679
- * @param {number | bigint} value
680
- * @returns {SetValue.Multiply}
681
- */
682
- declare function multiply(value: number | bigint): SetValue.Multiply;
683
- /**
684
- * @param {number | bigint} value
685
- * @returns {SetValue.Divide}
686
- */
687
- declare function divide(value: number | bigint): SetValue.Divide;
688
- /**
689
- * @param {...number | bigint} value
690
- * @returns {SetValue.Coefficient}
691
- */
692
- declare function coefficient(...value: (number | bigint)[]): SetValue.Coefficient;
693
- type SetValue = SetValue.Increment | SetValue.Decrement | SetValue.Multiply | SetValue.Divide | SetValue.Coefficient | string | number | bigint | boolean | null | typeof now | typeof uuid | (string | number | bigint | boolean)[];
694
- declare namespace SetValue {
695
- type Increment = {
696
- [increment$1]: number | bigint;
697
- };
698
- type Decrement = {
699
- [decrement$1]: number | bigint;
700
- };
701
- type Multiply = {
702
- [multiply$1]: number | bigint;
703
- };
704
- type Divide = {
705
- [divide$1]: number | bigint;
706
- };
707
- type Coefficient = {
708
- [coefficient$1]: (number | bigint)[];
709
- };
415
+ interface TransactionFn {
416
+ <T>(fn: (t: Connection) => PromiseLike<T> | T): Promise<T>;
710
417
  }
711
-
712
- interface VirtualTable<E extends object = object> {
713
- insert(environment: Environment<E>, conn: TableConnection<E>, columns: Record<string, DBColumn>, data: object[], key: string[], ignoreConflict?: boolean): PromiseLike<any[]>;
714
- upsert(environment: Environment<E>, conn: TableConnection<E>, columns: Record<string, DBColumn>, data: object[], key: string[], conflict: true | string[], conflictSet?: Record<string, SetValue>): PromiseLike<any[]>;
715
- update(environment: Environment<E>, conn: TableConnection<E>, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
716
- updateReturn(environment: Environment<E>, conn: TableConnection<E>, returning: string[], columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
717
- updateMany(environment: Environment<E>, conn: TableConnection<E>, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
718
- updateManyReturn(environment: Environment<E>, conn: TableConnection<E>, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
719
- count(environment: Environment<E>, conn: TableConnection<E>, columns: Record<string, DBColumn>, where: WhereValue[]): PromiseLike<number>;
720
- select(environment: Environment<E>, conn: TableConnection<E>, select: SelectItem[]): PromiseLike<any[]>;
721
- delete(environment: Environment<E>, conn: TableConnection<E>, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
722
- deleteReturn(environment: Environment<E>, conn: TableConnection<E>, returning: string[], columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
418
+ type TransactionHandlerArray = [
419
+ promise: TransactionHandler['promise'],
420
+ commit: TransactionHandler['commit'],
421
+ rollback: TransactionHandler['rollback']
422
+ ];
423
+ interface TransactionHandler extends TransactionHandlerArray {
424
+ promise: Promise<void>;
425
+ commit(): Promise<void>;
426
+ rollback(e?: any): Promise<void>;
427
+ [Symbol.dispose](): void;
723
428
  }
724
429
 
725
- type MaybePromise<T> = PromiseLike<T> | T;
726
-
727
- interface Hook<T extends Hooks[keyof Hooks]> {
728
- (approach?: boolean): MethodDecorator<T>;
729
- (hook: T, approach?: boolean): ClassDecorator;
730
- (Model: Function, hook: T, approach?: boolean): void;
430
+ /** 字段基本类型 */
431
+ interface FieldType {
432
+ i16: number;
433
+ i32: number;
434
+ i64: bigint;
435
+ f32: number;
436
+ f64: number;
437
+ decimal: number;
438
+ numeric: number;
439
+ money: number;
440
+ /** 文本类型(含字符串类型) */
441
+ string: string;
442
+ text: string;
443
+ char: string;
444
+ uuid: string;
445
+ ip: string;
446
+ ipv4: string;
447
+ ipv6: string;
448
+ ipnet: string;
449
+ ipnetv4: string;
450
+ ipnetv6: string;
451
+ mac48: string;
452
+ mac64: string;
453
+ /** 布尔型 */
454
+ bool: boolean;
455
+ /** 日期类型 */
456
+ date: Date;
457
+ /** 时间类型 */
458
+ time: Date;
459
+ /** 时间类型 */
460
+ timetz: Date;
461
+ /** 日期时间类型 */
462
+ datetime: Date;
463
+ /** 时间戳类型 */
464
+ timestamp: Date;
465
+ interval: number | bigint;
466
+ /** 对象类型 */
467
+ object: Record<string, unknown>;
468
+ /** JSON 类型 */
469
+ json: any;
731
470
  }
732
-
733
- /**
734
- * @param {WhereValue[]?} [items]
735
- * @returns {WhereValue[]?}
736
- */
737
- declare function toNot(items?: WhereValue[] | null): WhereValue[] | null;
738
- type WhereItem = {
739
- exists?: false | null | undefined;
740
- where?: null | undefined;
741
- or?: null | undefined;
742
- field: string | {
743
- table?: string;
744
- field: string;
745
- } | (string | {
746
- table?: string;
747
- field: string;
748
- })[];
749
- value: any;
750
- subquery?: SelectItem[] | null | undefined;
751
- not?: boolean | undefined;
752
- operator?: string | null | undefined;
753
- };
754
- type WhereExists = {
755
- where?: null | undefined;
756
- or?: null | undefined;
757
- field?: null | undefined;
758
- exists: true;
759
- subquery: SelectItem[];
760
- not?: boolean | undefined;
761
- };
762
- type WhereRaw = {
763
- exists?: false | null | undefined;
764
- field?: null | undefined;
765
- or?: null | undefined;
766
- where: readonly string[];
767
- values: readonly any[];
768
- not?: boolean | undefined;
769
- };
770
- type WhereOr = {
771
- exists?: false | null | undefined;
772
- where?: null | undefined;
773
- field?: null | undefined;
774
- or: WhereValue[][];
775
- not?: boolean | undefined;
471
+ interface Constraint {
472
+ noField?: boolean;
473
+ field?: string;
474
+ value?: any;
475
+ writeOnly?: boolean;
476
+ }
477
+ type MainFieldType = keyof FieldType | TableDefine | null;
478
+ type ToFieldType<T> = T extends keyof FieldType ? FieldType[T] : unknown;
479
+ type FieldSpecificValue = (string | number | bigint | boolean)[] | string | number | bigint | boolean | null | typeof now | typeof uuid;
480
+ type FieldSpecific = FieldSpecificValue | {
481
+ value?: FieldSpecificValue;
482
+ computed?(): PromiseLike<FieldSpecificValue> | FieldSpecificValue;
776
483
  };
777
- type WhereValue = WhereItem | WhereExists | WhereRaw | WhereOr;
778
- type WhereLike = {
779
- toWhereValue(): WhereValue[][];
484
+ interface FieldDefineOption {
485
+ column?: string;
486
+ /** 缩放比 */
487
+ scale?: number;
488
+ /** 占用空间大小 */
489
+ size?: number;
490
+ /** 是否为主键 */
491
+ primary?: number;
492
+ /** 唯一索引? */
493
+ unique?: boolean;
494
+ /** 索引信息 */
495
+ index?: string | boolean;
496
+ /** 创建时,自定义数据 */
497
+ creating?: FieldSpecific;
498
+ /** 更新时,自定义数据 */
499
+ updating?: FieldSpecific;
500
+ /** 伪删除时,自定义数据 */
501
+ deleting?: FieldSpecific;
502
+ /** 是否为可创建 */
503
+ uncreatable?: boolean;
504
+ /** 是否为固定值 */
505
+ immutable?: boolean;
506
+ /** 固定值 */
507
+ fixedValue?: any;
508
+ /** 文本查询 */
509
+ text?: boolean;
510
+ /** 排序顺序,绝对值表示在排序列表中的顺序,负数表示逆序排序, 0 表示不排序 */
511
+ sort?: number;
512
+ constraints?: Record<string, Constraint>;
513
+ }
514
+ /** 字段类型信息 */
515
+ interface FieldDefine<T extends MainFieldType = MainFieldType, A extends boolean = boolean, N extends boolean = boolean> extends FieldTypeDefine<T, A, N>, FieldDefineOption {
516
+ /** 默认值 */
517
+ default?: ToType<T, A, N>;
518
+ }
519
+ interface FieldTypeDefine<T extends MainFieldType = MainFieldType, A extends boolean = boolean, N extends boolean = boolean> {
520
+ /** 字段的基本类型 */
521
+ type: T;
522
+ /** 是否可为空 */
523
+ nullable: N;
524
+ /** 是否为数组 */
525
+ array: A;
526
+ }
527
+ type ToType<T extends MainFieldType = MainFieldType, A extends boolean = boolean, N extends boolean = boolean> = N extends false ? A extends false ? ToFieldType<T> : A extends true ? ToFieldType<T>[] : ToFieldType<T> | ToFieldType<T>[] : A extends false ? ToFieldType<T> | null : A extends true ? ToFieldType<T>[] | null : ToFieldType<T> | ToFieldType<T>[] | null;
528
+ type FieldDefineType<F extends FieldTypeDefine> = F extends FieldTypeDefine<infer T, infer A, infer N> ? ToType<T, A, N> : never;
529
+ type Fields<T extends MainFieldType = MainFieldType> = Record<string, FieldDefine<T>>;
530
+ type FieldValue<T extends Fields> = {
531
+ [K in keyof T]: FieldDefineType<T[K]>;
780
532
  };
781
- type Wheres = WhereLike | Record<string, any> | (WhereLike | Record<string, any>)[];
782
- declare class Where {
783
- /**
784
- * @overload
785
- * @param {Wheres} matches
786
- * @returns {WhereValue[]?}
787
- */
788
- static parse(matches: Wheres): WhereValue[] | null;
789
- /**
790
- * @overload
791
- * @param {string | string[]} field
792
- * @param {any} value
793
- * @returns {WhereValue[]?}
794
- */
795
- static parse(field: string | string[], value: any): WhereValue[] | null;
796
- /**
797
- * @overload
798
- * @param {string | string[]} field
799
- * @param {string} operator
800
- * @param {any} value
801
- * @param {boolean} [not]
802
- * @returns {WhereValue[]?}
803
- */
804
- static parse(field: string | string[], operator: string, value: any, not?: boolean | undefined): WhereValue[] | null;
805
- /**
806
- * @overload
807
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
808
- * @returns {WhereValue[]?}
809
- */
810
- static parse(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): WhereValue[] | null;
811
- /**
812
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
813
- * @returns {WhereValue[]?}
814
- */
815
- static parseParams(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): WhereValue[] | null;
816
- /**
817
- * @overload
818
- * @param {Wheres} matches
819
- * @returns {Where}
820
- */
821
- static and(matches: Wheres): Where;
822
- /**
823
- *
824
- * @overload
825
- * @param {TemplateStringsArray} where
826
- * @param {...any} values
827
- * @returns {Where}
828
- */
829
- static and(where: TemplateStringsArray, ...values: any[]): Where;
830
- /**
831
- * @overload
832
- * @param {string} field
833
- * @param {any} value
834
- * @returns {Where}
835
- */
836
- static and(field: string, value: any): Where;
837
- /**
838
- * @overload
839
- * @param {string[]} field
840
- * @param {any[]} value
841
- * @returns {Where}
842
- */
843
- static and(field: string[], value: any[]): Where;
844
- /**
845
- * @overload
846
- * @param {string} field
847
- * @param {string} operator
848
- * @param {any} value
849
- * @param {boolean} [not]
850
- * @returns {Where}
851
- */
852
- static and(field: string, operator: string, value: any, not?: boolean | undefined): Where;
853
- /**
854
- * @overload
855
- * @param {string[]} field
856
- * @param {string} operator
857
- * @param {any[]} value
858
- * @param {boolean} [not]
859
- * @returns {Where}
860
- */
861
- static and(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
862
- /**
863
- * @overload
864
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
865
- * @returns {Where}
866
- */
867
- static and(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
868
- /**
869
- * @overload
870
- * @param {Wheres} matches
871
- * @returns {Where}
872
- */
873
- static where(matches: Wheres): Where;
874
- /**
875
- *
876
- * @overload
877
- * @param {TemplateStringsArray} where
878
- * @param {...any} values
879
- * @returns {Where}
880
- */
881
- static where(where: TemplateStringsArray, ...values: any[]): Where;
882
- /**
883
- * @overload
884
- * @param {string} field
885
- * @param {any} value
886
- * @returns {Where}
887
- */
888
- static where(field: string, value: any): Where;
889
- /**
890
- * @overload
891
- * @param {string[]} field
892
- * @param {any[]} value
893
- * @returns {Where}
894
- */
895
- static where(field: string[], value: any[]): Where;
896
- /**
897
- * @overload
898
- * @param {string} field
899
- * @param {string} operator
900
- * @param {any} value
901
- * @param {boolean} [not]
902
- * @returns {Where}
903
- */
904
- static where(field: string, operator: string, value: any, not?: boolean | undefined): Where;
905
- /**
906
- * @overload
907
- * @param {string[]} field
908
- * @param {string} operator
909
- * @param {any[]} value
910
- * @param {boolean} [not]
911
- * @returns {Where}
912
- */
913
- static where(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
914
- /**
915
- * @overload
916
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
917
- * @returns {Where}
918
- */
919
- static where(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
920
- /**
921
- * @overload
922
- * @param {Wheres} matches
923
- * @returns {Where}
924
- */
925
- static or(matches: Wheres): Where;
926
- /**
927
- *
928
- * @overload
929
- * @param {TemplateStringsArray} where
930
- * @param {...any} values
931
- * @returns {Where}
932
- */
933
- static or(where: TemplateStringsArray, ...values: any[]): Where;
934
- /**
935
- * @overload
936
- * @param {string} field
937
- * @param {any} value
938
- * @returns {Where}
939
- */
940
- static or(field: string, value: any): Where;
941
- /**
942
- * @overload
943
- * @param {string[]} field
944
- * @param {any[]} value
945
- * @returns {Where}
946
- */
947
- static or(field: string[], value: any[]): Where;
948
- /**
949
- * @overload
950
- * @param {string} field
951
- * @param {string} operator
952
- * @param {any} value
953
- * @param {boolean} [not]
954
- * @returns {Where}
955
- */
956
- static or(field: string, operator: string, value: any, not?: boolean | undefined): Where;
957
- /**
958
- * @overload
959
- * @param {string[]} field
960
- * @param {string} operator
961
- * @param {any[]} value
962
- * @param {boolean} [not]
963
- * @returns {Where}
964
- */
965
- static or(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
966
- /**
967
- * @overload
968
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
969
- * @returns {Where}
970
- */
971
- static or(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
972
- /**
973
- * @overload
974
- * @param {Wheres} matches
975
- * @returns {Where}
976
- */
977
- static not(matches: Wheres): Where;
978
- /**
979
- *
980
- * @overload
981
- * @param {TemplateStringsArray} where
982
- * @param {...any} values
983
- * @returns {Where}
984
- */
985
- static not(where: TemplateStringsArray, ...values: any[]): Where;
986
- /**
987
- * @overload
988
- * @param {string} field
989
- * @param {any} value
990
- * @returns {Where}
991
- */
992
- static not(field: string, value: any): Where;
993
- /**
994
- * @overload
995
- * @param {string[]} field
996
- * @param {any[]} value
997
- * @returns {Where}
998
- */
999
- static not(field: string[], value: any[]): Where;
1000
- /**
1001
- * @overload
1002
- * @param {string} field
1003
- * @param {string} operator
1004
- * @param {any} value
1005
- * @param {boolean} [not]
1006
- * @returns {Where}
1007
- */
1008
- static not(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1009
- /**
1010
- * @overload
1011
- * @param {string[]} field
1012
- * @param {string} operator
1013
- * @param {any[]} value
1014
- * @param {boolean} [not]
1015
- * @returns {Where}
1016
- */
1017
- static not(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1018
- /**
1019
- * @overload
1020
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1021
- * @returns {Where}
1022
- */
1023
- static not(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1024
- /**
1025
- * @overload
1026
- * @param {Wheres} matches
1027
- * @returns {Where}
1028
- */
1029
- static orNot(matches: Wheres): Where;
1030
- /**
1031
- *
1032
- * @overload
1033
- * @param {TemplateStringsArray} where
1034
- * @param {...any} values
1035
- * @returns {Where}
1036
- */
1037
- static orNot(where: TemplateStringsArray, ...values: any[]): Where;
1038
- /**
1039
- * @overload
1040
- * @param {string} field
1041
- * @param {any} value
1042
- * @returns {Where}
1043
- */
1044
- static orNot(field: string, value: any): Where;
1045
- /**
1046
- * @overload
1047
- * @param {string[]} field
1048
- * @param {any[]} value
1049
- * @returns {Where}
1050
- */
1051
- static orNot(field: string[], value: any[]): Where;
1052
- /**
1053
- * @overload
1054
- * @param {string} field
1055
- * @param {string} operator
1056
- * @param {any} value
1057
- * @param {boolean} [not]
1058
- * @returns {Where}
1059
- */
1060
- static orNot(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1061
- /**
1062
- * @overload
1063
- * @param {string[]} field
1064
- * @param {string} operator
1065
- * @param {any[]} value
1066
- * @param {boolean} [not]
1067
- * @returns {Where}
1068
- */
1069
- static orNot(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1070
- /**
1071
- * @overload
1072
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1073
- * @returns {Where}
1074
- */
1075
- static orNot(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1076
- /**
1077
- *
1078
- * @param {...SelectItem} subquery
1079
- * @returns {Where}
1080
- */
1081
- static exists(...subquery: SelectItem[]): Where;
1082
- /**
1083
- *
1084
- * @param {...SelectItem} subquery
1085
- * @returns {Where}
1086
- */
1087
- static notExists(...subquery: SelectItem[]): Where;
1088
- toWhereValue(): WhereValue[][];
1089
- /**
1090
- * @overload
1091
- * @param {Wheres} matches
1092
- * @returns {this}
1093
- */
1094
- and(matches: Wheres): this;
1095
- /**
1096
- *
1097
- * @overload
1098
- * @param {TemplateStringsArray} where
1099
- * @param {...any} values
1100
- * @returns {this}
1101
- */
1102
- and(where: TemplateStringsArray, ...values: any[]): this;
1103
- /**
1104
- * @overload
1105
- * @param {string} field
1106
- * @param {any} value
1107
- * @returns {this}
1108
- */
1109
- and(field: string, value: any): this;
1110
- /**
1111
- * @overload
1112
- * @param {string[]} field
1113
- * @param {any[]} value
1114
- * @returns {this}
1115
- */
1116
- and(field: string[], value: any[]): this;
1117
- /**
1118
- * @overload
1119
- * @param {string} field
1120
- * @param {string} operator
1121
- * @param {any} value
1122
- * @param {boolean} [not]
1123
- * @returns {this}
1124
- */
1125
- and(field: string, operator: string, value: any, not?: boolean | undefined): this;
1126
- /**
1127
- * @overload
1128
- * @param {string[]} field
1129
- * @param {string} operator
1130
- * @param {any[]} value
1131
- * @param {boolean} [not]
1132
- * @returns {this}
1133
- */
1134
- and(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1135
- /**
1136
- * @overload
1137
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1138
- * @returns {this}
1139
- */
1140
- and(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1141
- /**
1142
- * @overload
1143
- * @param {Wheres} matches
1144
- * @returns {this}
1145
- */
1146
- or(matches: Wheres): this;
1147
- /**
1148
- *
1149
- * @overload
1150
- * @param {TemplateStringsArray} where
1151
- * @param {...any} values
1152
- * @returns {this}
1153
- */
1154
- or(where: TemplateStringsArray, ...values: any[]): this;
1155
- /**
1156
- * @overload
1157
- * @param {string} field
1158
- * @param {any} value
1159
- * @returns {this}
1160
- */
1161
- or(field: string, value: any): this;
1162
- /**
1163
- * @overload
1164
- * @param {string[]} field
1165
- * @param {any[]} value
1166
- * @returns {this}
1167
- */
1168
- or(field: string[], value: any[]): this;
1169
- /**
1170
- * @overload
1171
- * @param {string} field
1172
- * @param {string} operator
1173
- * @param {any} value
1174
- * @param {boolean} [not]
1175
- * @returns {this}
1176
- */
1177
- or(field: string, operator: string, value: any, not?: boolean | undefined): this;
1178
- /**
1179
- * @overload
1180
- * @param {string[]} field
1181
- * @param {string} operator
1182
- * @param {any[]} value
1183
- * @param {boolean} [not]
1184
- * @returns {this}
1185
- */
1186
- or(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1187
- /**
1188
- * @overload
1189
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1190
- * @returns {this}
1191
- */
1192
- or(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1193
- /**
1194
- * @overload
1195
- * @param {Wheres} matches
1196
- * @returns {this}
1197
- */
1198
- not(matches: Wheres): this;
1199
- /**
1200
- *
1201
- * @overload
1202
- * @param {TemplateStringsArray} where
1203
- * @param {...any} values
1204
- * @returns {this}
1205
- */
1206
- not(where: TemplateStringsArray, ...values: any[]): this;
1207
- /**
1208
- * @overload
1209
- * @param {string} field
1210
- * @param {any} value
1211
- * @returns {this}
1212
- */
1213
- not(field: string, value: any): this;
1214
- /**
1215
- * @overload
1216
- * @param {string[]} field
1217
- * @param {any[]} value
1218
- * @returns {this}
1219
- */
1220
- not(field: string[], value: any[]): this;
1221
- /**
1222
- * @overload
1223
- * @param {string} field
1224
- * @param {string} operator
1225
- * @param {any} value
1226
- * @param {boolean} [not]
1227
- * @returns {this}
1228
- */
1229
- not(field: string, operator: string, value: any, not?: boolean | undefined): this;
1230
- /**
1231
- * @overload
1232
- * @param {string[]} field
1233
- * @param {string} operator
1234
- * @param {any[]} value
1235
- * @param {boolean} [not]
1236
- * @returns {this}
1237
- */
1238
- not(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1239
- /**
1240
- * @overload
1241
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1242
- * @returns {this}
1243
- */
1244
- not(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1245
- /**
1246
- * @overload
1247
- * @param {Wheres} matches
1248
- * @returns {this}
1249
- */
1250
- orNot(matches: Wheres): this;
1251
- /**
1252
- *
1253
- * @overload
1254
- * @param {TemplateStringsArray} where
1255
- * @param {...any} values
1256
- * @returns {this}
1257
- */
1258
- orNot(where: TemplateStringsArray, ...values: any[]): this;
1259
- /**
1260
- * @overload
1261
- * @param {string} field
1262
- * @param {any} value
1263
- * @returns {this}
1264
- */
1265
- orNot(field: string, value: any): this;
1266
- /**
1267
- * @overload
1268
- * @param {string[]} field
1269
- * @param {any[]} value
1270
- * @returns {this}
1271
- */
1272
- orNot(field: string[], value: any[]): this;
1273
- /**
1274
- * @overload
1275
- * @param {string} field
1276
- * @param {string} operator
1277
- * @param {any} value
1278
- * @param {boolean} [not]
1279
- * @returns {this}
1280
- */
1281
- orNot(field: string, operator: string, value: any, not?: boolean | undefined): this;
1282
- /**
1283
- * @overload
1284
- * @param {string[]} field
1285
- * @param {string} operator
1286
- * @param {any[]} value
1287
- * @param {boolean} [not]
1288
- * @returns {this}
1289
- */
1290
- orNot(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1291
- /**
1292
- * @overload
1293
- * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1294
- * @returns {this}
1295
- */
1296
- orNot(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1297
- /**
1298
- *
1299
- * @param {...SelectItem} subquery
1300
- * @returns {this}
1301
- */
1302
- exists(...subquery: SelectItem[]): this;
1303
- /**
1304
- *
1305
- * @param {...SelectItem} subquery
1306
- * @returns {this}
1307
- */
1308
- notExists(...subquery: SelectItem[]): this;
1309
- #private;
533
+ interface IndexOptions {
534
+ unique?: boolean;
535
+ name?: string;
536
+ includes?: string[];
537
+ }
538
+ interface IndexInfo extends IndexOptions {
539
+ fields: string[];
540
+ }
541
+ interface Index extends IndexInfo {
542
+ name: string;
543
+ }
544
+ interface Hooks<T extends Record<string, any> = Record<string, any>> {
545
+ where(this: unknown, conn: Connection, model: TableDefine): PromiseLike<void | Where> | void;
546
+ beforeCreateMany(this: unknown, conn: Connection, model: TableDefine, records: Record<string, any>[]): PromiseLike<void | Record<string, any>[]> | void | Record<string, any>[];
547
+ afterCreateMany(this: unknown, conn: Connection, model: TableDefine, records: Record<string, any>[]): PromiseLike<void> | void;
548
+ beforeCreate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>): PromiseLike<void | Record<string, any>> | void | Record<string, any>;
549
+ afterCreate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>): PromiseLike<void> | void;
550
+ beforeUpdate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>, set: Record<string, any>): PromiseLike<void | Record<string, any>> | void | Record<string, any>;
551
+ afterUpdate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>, oldRecord: Record<string, any>): PromiseLike<void> | void;
552
+ beforeDelete(this: unknown, conn: Connection, model: TableDefine, record: T, update: Record<string, any> | null): PromiseLike<void> | void;
553
+ afterDelete(this: unknown, conn: Connection, model: TableDefine, record: T, update: Record<string, any> | null): PromiseLike<void> | void;
554
+ }
555
+ interface TableDefine<T extends Fields = Fields, TT extends string | undefined = string | undefined> {
556
+ readonly connect?: TableConnect | null;
557
+ /** 字段信息 */
558
+ readonly fields: T;
559
+ /** 表名 */
560
+ readonly table: TT;
561
+ /** 是否启用软删除 */
562
+ readonly pseudo?: string;
563
+ /** 索引信息 */
564
+ readonly indexes?: readonly IndexInfo[];
565
+ /** 钩子 */
566
+ readonly hooks?: Partial<Hooks>;
1310
567
  }
568
+ type TableValue<T extends TableDefine> = T extends TableDefine<infer F> ? FieldValue<F> : never;
569
+
570
+ /**
571
+ * @template {keyof FieldType} T
572
+ * @overload
573
+ * @param {T} type
574
+ * @param {{
575
+ * nullable?: false;
576
+ * array?: false;
577
+ * default?: ToType<T, false, false> | symbol;
578
+ * [k: string]: any;
579
+ * } & FieldDefineOption} [options]
580
+ * @returns {FieldDecorator<ToType<T, false, false>>}
581
+ */
582
+ declare function field$1<T extends keyof FieldType>(type: T, options?: ({
583
+ [k: string]: any;
584
+ nullable?: false;
585
+ array?: false;
586
+ default?: ToType<T, false, false> | symbol;
587
+ } & FieldDefineOption) | undefined): FieldDecorator<ToType<T, false, false>>;
588
+ /**
589
+ * @template {keyof FieldType} T
590
+ * @overload
591
+ * @param {T} type
592
+ * @param {{
593
+ * nullable?: false;
594
+ * array: true;
595
+ * default?: ToType<T, true, false> | symbol;
596
+ * [k: string]: any;
597
+ * } & FieldDefineOption} options
598
+ * @returns {FieldDecorator<ToType<T, true, false>>}
599
+ */
600
+ declare function field$1<T extends keyof FieldType>(type: T, options: {
601
+ nullable?: false;
602
+ array: true;
603
+ default?: ToType<T, true, false> | symbol;
604
+ [k: string]: any;
605
+ } & FieldDefineOption): FieldDecorator<ToType<T, true, false>>;
606
+ /**
607
+ * @template {keyof FieldType} T
608
+ * @overload
609
+ * @param {T} type
610
+ * @param {true} array
611
+ * @param {{
612
+ * nullable?: false;
613
+ * default?: ToType<T, true, false> | symbol;
614
+ * [k: string]: any;
615
+ * } & FieldDefineOption} options
616
+ * @returns {FieldDecorator<ToType<T, true, false>>}
617
+ */
618
+ declare function field$1<T extends keyof FieldType>(type: T, array: true, options: {
619
+ nullable?: false;
620
+ default?: ToType<T, true, false> | symbol;
621
+ [k: string]: any;
622
+ } & FieldDefineOption): FieldDecorator<ToType<T, true, false>>;
623
+ /**
624
+ * @template {keyof FieldType} T
625
+ * @overload
626
+ * @param {T} type
627
+ * @param {{
628
+ * nullable: true;
629
+ * array?: false;
630
+ * default?: ToType<T, false, true> | symbol;
631
+ * [k: string]: any;
632
+ * } & FieldDefineOption} options
633
+ * @returns {FieldDecorator<ToType<T, false, true>>}
634
+ */
635
+ declare function field$1<T extends keyof FieldType>(type: T, options: {
636
+ nullable: true;
637
+ array?: false;
638
+ default?: ToType<T, false, true> | symbol;
639
+ [k: string]: any;
640
+ } & FieldDefineOption): FieldDecorator<ToType<T, false, true>>;
641
+ /**
642
+ * @template {keyof FieldType} T
643
+ * @overload
644
+ * @param {T} type
645
+ * @param {{
646
+ * nullable: true;
647
+ * array: true;
648
+ * default?: ToType<T, true, true> | symbol;
649
+ * [k: string]: any;
650
+ * } & FieldDefineOption} options
651
+ * @returns {FieldDecorator<ToType<T, true, true>>}
652
+ */
653
+ declare function field$1<T extends keyof FieldType>(type: T, options: {
654
+ nullable: true;
655
+ array: true;
656
+ default?: ToType<T, true, true> | symbol;
657
+ [k: string]: any;
658
+ } & FieldDefineOption): FieldDecorator<ToType<T, true, true>>;
659
+ /**
660
+ * @template {keyof FieldType} T
661
+ * @overload
662
+ * @param {T} type
663
+ * @param {true} array
664
+ * @param {{
665
+ * nullable: true;
666
+ * default?: ToType<T, true, true> | symbol;
667
+ * [k: string]: any;
668
+ * } & FieldDefineOption} options
669
+ * @returns {FieldDecorator<ToType<T, true, true>>}
670
+ */
671
+ declare function field$1<T extends keyof FieldType>(type: T, array: true, options: {
672
+ nullable: true;
673
+ default?: ToType<T, true, true> | symbol;
674
+ [k: string]: any;
675
+ } & FieldDefineOption): FieldDecorator<ToType<T, true, true>>;
676
+ /**
677
+ * @template {keyof FieldType} T
678
+ * @template {boolean} A
679
+ * @overload
680
+ * @param {T} type
681
+ * @param {{
682
+ * nullable: true;
683
+ * array: A;
684
+ * default?: ToType<T, A, true> | symbol;
685
+ * [k: string]: any;
686
+ * } & FieldDefineOption} options
687
+ * @returns {FieldDecorator<ToType<T, A, true>>}
688
+ */
689
+ declare function field$1<T extends keyof FieldType, A extends boolean>(type: T, options: {
690
+ nullable: true;
691
+ array: A;
692
+ default?: ToType<T, A, true> | symbol;
693
+ [k: string]: any;
694
+ } & FieldDefineOption): FieldDecorator<ToType<T, A, true>>;
695
+ /**
696
+ * @template {keyof FieldType} T
697
+ * @template {boolean} A
698
+ * @overload
699
+ * @param {T} type
700
+ * @param {{
701
+ * nullable?: false;
702
+ * array: A;
703
+ * default?: ToType<T, A, false> | symbol;
704
+ * [k: string]: any;
705
+ * } & FieldDefineOption} options
706
+ * @returns {FieldDecorator<ToType<T, A, false>>}
707
+ */
708
+ declare function field$1<T extends keyof FieldType, A extends boolean>(type: T, options: {
709
+ nullable?: false;
710
+ array: A;
711
+ default?: ToType<T, A, false> | symbol;
712
+ [k: string]: any;
713
+ } & FieldDefineOption): FieldDecorator<ToType<T, A, false>>;
714
+ /**
715
+ * @template {keyof FieldType} T
716
+ * @template {boolean} N
717
+ * @overload
718
+ * @param {T} type
719
+ * @param {{
720
+ * nullable: N;
721
+ * array?: false;
722
+ * default?: ToType<T, false, N> | symbol;
723
+ * [k: string]: any;
724
+ * } & FieldDefineOption} options
725
+ * @returns {FieldDecorator<ToType<T, false, N>>}
726
+ */
727
+ declare function field$1<T extends keyof FieldType, N extends boolean>(type: T, options: {
728
+ nullable: N;
729
+ array?: false;
730
+ default?: ToType<T, false, N> | symbol;
731
+ [k: string]: any;
732
+ } & FieldDefineOption): FieldDecorator<ToType<T, false, N>>;
733
+ /**
734
+ * @template {keyof FieldType} T
735
+ * @template {boolean} N
736
+ * @overload
737
+ * @param {T} type
738
+ * @param {{
739
+ * nullable: N;
740
+ * array: true;
741
+ * default?: ToType<T, true, N> | symbol;
742
+ * [k: string]: any;
743
+ * } & FieldDefineOption} options
744
+ * @returns {FieldDecorator<ToType<T, true, N>>}
745
+ */
746
+ declare function field$1<T extends keyof FieldType, N extends boolean>(type: T, options: {
747
+ nullable: N;
748
+ array: true;
749
+ default?: ToType<T, true, N> | symbol;
750
+ [k: string]: any;
751
+ } & FieldDefineOption): FieldDecorator<ToType<T, true, N>>;
752
+ /**
753
+ * @template {keyof FieldType} T
754
+ * @template {boolean} N
755
+ * @overload
756
+ * @param {T} type
757
+ * @param {true} array
758
+ * @param {{
759
+ * nullable: N;
760
+ * default?: ToType<T, true, N> | symbol;
761
+ * [k: string]: any;
762
+ * } & FieldDefineOption} options
763
+ * @returns {FieldDecorator<ToType<T, true, N>>}
764
+ */
765
+ declare function field$1<T extends keyof FieldType, N extends boolean>(type: T, array: true, options: {
766
+ nullable: N;
767
+ default?: ToType<T, true, N> | symbol;
768
+ [k: string]: any;
769
+ } & FieldDefineOption): FieldDecorator<ToType<T, true, N>>;
770
+ /**
771
+ * @template {keyof FieldType} T
772
+ * @template {boolean} A
773
+ * @template {boolean} N
774
+ * @overload
775
+ * @param {T} type
776
+ * @param {{
777
+ * nullable: N;
778
+ * array: A;
779
+ * default?: ToType<T, A, N> | symbol;
780
+ * [k: string]: any;
781
+ * } & FieldDefineOption} options
782
+ * @returns {FieldDecorator<ToType<T, A, N>>}
783
+ */
784
+ declare function field$1<T extends keyof FieldType, A extends boolean, N extends boolean>(type: T, options: {
785
+ nullable: N;
786
+ array: A;
787
+ default?: ToType<T, A, N> | symbol;
788
+ [k: string]: any;
789
+ } & FieldDefineOption): FieldDecorator<ToType<T, A, N>>;
790
+ /**
791
+ * @template {keyof FieldType} T
792
+ * @overload
793
+ * @param {T} type
794
+ * @param {{
795
+ * nullable?: boolean;
796
+ * array?: boolean;
797
+ * default?: ToType<T, boolean, boolean> | symbol;
798
+ * [k: string]: any;
799
+ * } & FieldDefineOption} options
800
+ * @returns {FieldDecorator<ToType<T, boolean, boolean>>}
801
+ */
802
+ declare function field$1<T extends keyof FieldType>(type: T, options: {
803
+ nullable?: boolean;
804
+ array?: boolean;
805
+ default?: ToType<T, boolean, boolean> | symbol;
806
+ [k: string]: any;
807
+ } & FieldDefineOption): FieldDecorator<ToType<T, boolean, boolean>>;
808
+
809
+ /** @import { FieldDecorator } from './index.mjs' */
810
+ /**
811
+ * @param {string} prop
812
+ * @param {any} value
813
+ * @param {boolean} [array]
814
+ * @param {boolean} [end]
815
+ * @returns {FieldDecorator<any>}
816
+ */
817
+ declare function prop(prop: string, value: any, array?: boolean, end?: boolean): FieldDecorator<any>;
818
+
819
+ /** @import { FieldDecorator } from './index.mjs' */
820
+ /**
821
+ *
822
+ * @param {string} [column]
823
+ * @returns {FieldDecorator<any>}
824
+ */
825
+ declare function column(column?: string): FieldDecorator<any>;
826
+
827
+ /** @import { FieldDecorator } from './index.mjs' */
828
+ /**
829
+ *
830
+ * @param {number} [primary]
831
+ * @returns {FieldDecorator<any>}
832
+ */
833
+ declare function primary(primary?: number): FieldDecorator<any>;
834
+
835
+ /** @import { FieldDecorator } from './index.mjs' */
836
+ /** @returns {FieldDecorator<any>} */
837
+ declare function uncreatable(): FieldDecorator<any>;
838
+
839
+ /** @import { FieldDecorator } from './index.mjs' */
840
+ /** @returns {FieldDecorator<any>} */
841
+ declare function immutable(): FieldDecorator<any>;
842
+
843
+ /**
844
+ * 索引信息
845
+ * @overload
846
+ * @param {string[]} fields
847
+ * @param {IndexOptions} [options]
848
+ * @returns {ClassDecorator}
849
+ */
850
+ declare function index(fields: string[], options?: IndexOptions | undefined): ClassDecorator;
851
+ /**
852
+ * 索引信息
853
+ * @overload
854
+ * @param {string} [name]
855
+ * @param {boolean} [unique]
856
+ * @returns {FieldDecorator<any>}
857
+ */
858
+ declare function index(name?: string | undefined, unique?: boolean | undefined): FieldDecorator<any>;
859
+ /**
860
+ * 索引信息
861
+ * @overload
862
+ * @param {boolean} [unique]
863
+ * @returns {FieldDecorator<any>}
864
+ */
865
+ declare function index(unique?: boolean | undefined): FieldDecorator<any>;
866
+
867
+ /** @import { FieldDecorator } from './index.mjs' */
868
+ /**
869
+ * 默认排序顺序,绝对值表示在排序列表中的顺序,负数表示逆序排序, 0 表示不排序
870
+ * @param {number} sort
871
+ * @returns {FieldDecorator<any>}
872
+ */
873
+ declare function sort(sort: number): FieldDecorator<any>;
874
+
875
+ /** @import { ClassDecorator } from './index.mjs' */
876
+ /**
877
+ *
878
+ * @param {string} pseudo
879
+ * @returns {ClassDecorator}
880
+ */
881
+ declare function pseudo(pseudo: string): ClassDecorator;
882
+
883
+ /**
884
+ * @template T
885
+ * @overload
886
+ * @param {now} value
887
+ * @returns {FieldDecorator<string | Date>}
888
+ */
889
+ declare function defaultValue<T>(value: typeof now): FieldDecorator<string | Date>;
890
+ /**
891
+ * @template T
892
+ * @overload
893
+ * @param {uuid} value
894
+ * @returns {FieldDecorator<string>}
895
+ */
896
+ declare function defaultValue<T>(value: typeof uuid): FieldDecorator<string>;
897
+ /**
898
+ * @template T
899
+ * @overload
900
+ * @param {T} value
901
+ * @returns {FieldDecorator<T>}
902
+ */
903
+ declare function defaultValue<T>(value: T): FieldDecorator<T>;
904
+
905
+ /**
906
+ *
907
+ * @overload
908
+ * @param {string} table
909
+ * @returns {ClassDecorator}
910
+ */
911
+ declare function model(table: string): ClassDecorator;
912
+ /**
913
+ * @template {Record<string, any>} T
914
+ * @overload
915
+ * @param {TableDefine & {new(...a: any): T}} type
916
+ * @param {Record<string, Constraint>} constraints
917
+ * @param {true} array
918
+ * @param {FieldDefineOption} [options]
919
+ * @returns {FieldDecorator<T[]>}
920
+ */
921
+ declare function model<T extends Record<string, any>>(type: TableDefine & {
922
+ new (...a: any): T;
923
+ }, constraints: Record<string, Constraint>, array: true, options?: FieldDefineOption | undefined): FieldDecorator<T[]>;
924
+ /**
925
+ * @template {Record<string, any>} T
926
+ * @overload
927
+ * @param {TableDefine & {new(...a: any): T}} type
928
+ * @param {Record<string, Constraint>} constraints
929
+ * @param {false} [array]
930
+ * @param {FieldDefineOption} [options]
931
+ * @returns {FieldDecorator<T>}
932
+ */
933
+ declare function model<T extends Record<string, any>>(type: TableDefine & {
934
+ new (...a: any): T;
935
+ }, constraints: Record<string, Constraint>, array?: false | undefined, options?: FieldDefineOption | undefined): FieldDecorator<T>;
936
+ /**
937
+ * @template {Record<string, any>} T
938
+ * @overload
939
+ * @param {TableDefine & {new(...a: any): T}} type
940
+ * @param {Record<string, Constraint>} constraints
941
+ * @param {FieldDefineOption} [options]
942
+ * @returns {FieldDecorator<T>}
943
+ */
944
+ declare function model<T extends Record<string, any>>(type: TableDefine & {
945
+ new (...a: any): T;
946
+ }, constraints: Record<string, Constraint>, options?: FieldDefineOption | undefined): FieldDecorator<T>;
947
+ /**
948
+ * @template {Record<string, any>} T
949
+ * @template {boolean} [A=boolean]
950
+ * @overload
951
+ * @param {TableDefine & {new(...a: any): T}} type
952
+ * @param {Record<string, Constraint>} constraints
953
+ * @param {A} array
954
+ * @param {FieldDefineOption} [options]
955
+ * @returns {FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>}
956
+ */
957
+ declare function model<T extends Record<string, any>, A extends boolean = boolean>(type: TableDefine & {
958
+ new (...a: any): T;
959
+ }, constraints: Record<string, Constraint>, array: A, options?: FieldDefineOption | undefined): FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>;
960
+ /**
961
+ * @template {object} T
962
+ * @overload
963
+ * @param {TableDefine} type
964
+ * @param {Record<string, Constraint>} constraints
965
+ * @param {true} array
966
+ * @param {FieldDefineOption} [options]
967
+ * @returns {FieldDecorator<T[]>}
968
+ */
969
+ declare function model<T extends Record<string, any>>(type: TableDefine, constraints: Record<string, Constraint>, array: true, options?: FieldDefineOption | undefined): FieldDecorator<T[]>;
970
+ /**
971
+ * @template {object} T
972
+ * @overload
973
+ * @param {TableDefine} type
974
+ * @param {Record<string, Constraint>} constraints
975
+ * @param {false} [array]
976
+ * @param {FieldDefineOption} [options]
977
+ * @returns {FieldDecorator<T>}
978
+ */
979
+ declare function model<T extends Record<string, any>>(type: TableDefine, constraints: Record<string, Constraint>, array?: false | undefined, options?: FieldDefineOption | undefined): FieldDecorator<T>;
980
+ /**
981
+ * @template {object} T
982
+ * @overload
983
+ * @param {TableDefine} type
984
+ * @param {Record<string, Constraint>} constraints
985
+ * @param {FieldDefineOption} [options]
986
+ * @returns {FieldDecorator<T>}
987
+ */
988
+ declare function model<T extends Record<string, any>>(type: TableDefine, constraints: Record<string, Constraint>, options?: FieldDefineOption | undefined): FieldDecorator<T>;
989
+ /**
990
+ * @template {object} T
991
+ * @template {boolean} [A=boolean]
992
+ * @overload
993
+ * @param {TableDefine} type
994
+ * @param {Record<string, Constraint>} constraints
995
+ * @param {A} array
996
+ * @param {FieldDefineOption} [options]
997
+ * @returns {FieldDecorator<A extends false ? T :A extends true ? T[] : T | T[]>}
998
+ */
999
+ declare function model<T extends Record<string, any>, A extends boolean = boolean>(type: TableDefine, constraints: Record<string, Constraint>, array: A, options?: FieldDefineOption | undefined): FieldDecorator<A extends false ? T : A extends true ? T[] : T | T[]>;
1311
1000
 
1312
- /** 字段基本类型 */
1313
- interface FieldType {
1314
- i16: number;
1315
- i32: number;
1316
- i64: bigint;
1317
- f32: number;
1318
- f64: number;
1319
- decimal: number;
1320
- numeric: number;
1321
- money: number;
1322
- /** 文本类型(含字符串类型) */
1323
- string: string;
1324
- text: string;
1325
- char: string;
1326
- uuid: string;
1327
- ip: string;
1328
- ipv4: string;
1329
- ipv6: string;
1330
- ipnet: string;
1331
- ipnetv4: string;
1332
- ipnetv6: string;
1333
- mac48: string;
1334
- mac64: string;
1335
- /** 布尔型 */
1336
- bool: boolean;
1337
- /** 日期类型 */
1338
- date: Date;
1339
- /** 时间类型 */
1340
- time: Date;
1341
- /** 时间类型 */
1342
- timetz: Date;
1343
- /** 日期时间类型 */
1344
- datetime: Date;
1345
- /** 时间戳类型 */
1346
- timestamp: Date;
1347
- interval: number | bigint;
1348
- /** 对象类型 */
1349
- object: Record<string, unknown>;
1350
- /** JSON 类型 */
1351
- json: any;
1352
- }
1353
- interface Constraint {
1354
- noField?: boolean;
1355
- field?: string;
1356
- value?: any;
1357
- writeOnly?: boolean;
1358
- }
1359
- type MainFieldType = keyof FieldType | TableDefine | null;
1360
- type ToFieldType<T> = T extends keyof FieldType ? FieldType[T] : unknown;
1361
- type FieldSpecificValue = (string | number | bigint | boolean)[] | string | number | bigint | boolean | null | typeof now | typeof uuid;
1362
- type FieldSpecific = FieldSpecificValue | {
1363
- value?: FieldSpecificValue;
1364
- computed?(): PromiseLike<FieldSpecificValue> | FieldSpecificValue;
1365
- };
1366
- interface FieldDefineOption {
1367
- column?: string;
1368
- /** 缩放比 */
1369
- scale?: number;
1370
- /** 占用空间大小 */
1371
- size?: number;
1372
- /** 是否为主键 */
1373
- primary?: number;
1374
- /** 唯一索引? */
1375
- unique?: boolean;
1376
- /** 索引信息 */
1377
- index?: string | boolean;
1378
- /** 创建时,自定义数据 */
1379
- creating?: FieldSpecific;
1380
- /** 更新时,自定义数据 */
1381
- updating?: FieldSpecific;
1382
- /** 伪删除时,自定义数据 */
1383
- deleting?: FieldSpecific;
1384
- /** 是否为可创建 */
1385
- uncreatable?: boolean;
1386
- /** 是否为固定值 */
1387
- immutable?: boolean;
1388
- /** 固定值 */
1389
- fixedValue?: any;
1390
- /** 文本查询 */
1391
- text?: boolean;
1392
- /** 排序顺序,绝对值表示在排序列表中的顺序,负数表示逆序排序, 0 表示不排序 */
1393
- sort?: number;
1394
- constraints?: Record<string, Constraint>;
1395
- }
1396
- /** 字段类型信息 */
1397
- interface FieldDefine<T extends MainFieldType = MainFieldType, A extends boolean = boolean, N extends boolean = boolean> extends FieldTypeDefine<T, A, N>, FieldDefineOption {
1398
- /** 默认值 */
1399
- default?: ToType<T, A, N>;
1400
- }
1401
- interface FieldTypeDefine<T extends MainFieldType = MainFieldType, A extends boolean = boolean, N extends boolean = boolean> {
1402
- /** 字段的基本类型 */
1403
- type: T;
1404
- /** 是否可为空 */
1405
- nullable: N;
1406
- /** 是否为数组 */
1407
- array: A;
1408
- }
1409
- type ToType<T extends MainFieldType = MainFieldType, A extends boolean = boolean, N extends boolean = boolean> = N extends false ? A extends false ? ToFieldType<T> : A extends true ? ToFieldType<T>[] : ToFieldType<T> | ToFieldType<T>[] : A extends false ? ToFieldType<T> | null : A extends true ? ToFieldType<T>[] | null : ToFieldType<T> | ToFieldType<T>[] | null;
1410
- type FieldDefineType<F extends FieldTypeDefine> = F extends FieldTypeDefine<infer T, infer A, infer N> ? ToType<T, A, N> : never;
1411
- type Fields<T extends MainFieldType = MainFieldType> = Record<string, FieldDefine<T>>;
1412
- type FieldValue<T extends Fields> = {
1413
- [K in keyof T]: FieldDefineType<T[K]>;
1414
- };
1415
- interface IndexOptions {
1416
- unique?: boolean;
1417
- name?: string;
1418
- includes?: string[];
1419
- }
1420
- interface IndexInfo extends IndexOptions {
1421
- fields: string[];
1422
- }
1423
- interface Index extends IndexInfo {
1424
- name: string;
1425
- }
1426
- interface Hooks<T extends Record<string, any> = Record<string, any>> {
1427
- where(this: unknown, conn: Connection, model: TableDefine): PromiseLike<void | Where> | void;
1428
- beforeCreateMany(this: unknown, conn: Connection, model: TableDefine, records: Record<string, any>[]): PromiseLike<void | Record<string, any>[]> | void | Record<string, any>[];
1429
- afterCreateMany(this: unknown, conn: Connection, model: TableDefine, records: Record<string, any>[]): PromiseLike<void> | void;
1430
- beforeCreate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>): PromiseLike<void | Record<string, any>> | void | Record<string, any>;
1431
- afterCreate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>): PromiseLike<void> | void;
1432
- beforeUpdate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>, set: Record<string, any>): PromiseLike<void | Record<string, any>> | void | Record<string, any>;
1433
- afterUpdate(this: unknown, conn: Connection, model: TableDefine, record: Record<string, any>, oldRecord: Record<string, any>): PromiseLike<void> | void;
1434
- beforeDelete(this: unknown, conn: Connection, model: TableDefine, record: T, update: Record<string, any> | null): PromiseLike<void> | void;
1435
- afterDelete(this: unknown, conn: Connection, model: TableDefine, record: T, update: Record<string, any> | null): PromiseLike<void> | void;
1436
- }
1437
- interface TableDefine<T extends Fields = Fields, TT extends string | VirtualTable | undefined = string | VirtualTable | undefined> {
1438
- readonly connect?: TableConnect<any> | null;
1439
- /** 字段信息 */
1440
- readonly fields: T;
1441
- /** 表名 */
1442
- readonly table: TT;
1443
- /** 是否启用软删除 */
1444
- readonly pseudo?: string;
1445
- /** 索引信息 */
1446
- readonly indexes?: readonly IndexInfo[];
1447
- /** 钩子 */
1448
- readonly hooks?: Partial<Hooks>;
1449
- }
1450
- type TableValue<T extends TableDefine> = T extends TableDefine<infer F> ? FieldValue<F> : never;
1001
+ /**
1002
+ * @param {number} [size]
1003
+ * @returns {FieldDecorator<Date?>}
1004
+ */
1005
+ declare function creating(size?: number): FieldDecorator<Date | null>;
1006
+ /**
1007
+ * @param {number} [size]
1008
+ * @returns {FieldDecorator<Date?>}
1009
+ */
1010
+ declare function updating(size?: number): FieldDecorator<Date | null>;
1011
+ /**
1012
+ * @param {number} [size]
1013
+ * @returns {FieldDecorator<Date?>}
1014
+ */
1015
+ declare function deleting(size?: number): FieldDecorator<Date | null>;
1451
1016
 
1452
- type deleted = typeof deleted;
1453
- declare const deleted: unique symbol;
1454
- type undeleted = typeof undeleted;
1455
- declare const undeleted: unique symbol;
1456
- type withDeleted = typeof withDeleted;
1457
- declare const withDeleted: unique symbol;
1458
- type FindRange = deleted | undeleted | withDeleted;
1017
+ /**
1018
+ * @overload
1019
+ * @param {Partial<Hooks>} hook
1020
+ * @param {boolean} [approach] 插入位置是否为更靠近执行的位置
1021
+ * @returns {ClassDecorator}
1022
+ */
1023
+ declare function hooks(hook: Partial<Hooks>, approach?: boolean | undefined): ClassDecorator;
1024
+ /**
1025
+ * @overload
1026
+ * @param {Function} Model
1027
+ * @param {Partial<Hooks>} hook
1028
+ * @param {boolean} [approach] 插入位置是否为更靠近执行的位置
1029
+ * @returns {void}
1030
+ */
1031
+ declare function hooks(Model: Function, hook: Partial<Hooks>, approach?: boolean | undefined): void;
1032
+ /** @type {Hook<Hooks['where']>} */
1033
+ declare const where: Hook<Hooks["where"]>;
1034
+ /** @type {Hook<Hooks['beforeCreateMany']>} */
1035
+ declare const beforeCreateMany: Hook<Hooks["beforeCreateMany"]>;
1036
+ /** @type {Hook<Hooks['afterCreateMany']>} */
1037
+ declare const afterCreateMany: Hook<Hooks["afterCreateMany"]>;
1038
+ /** @type {Hook<Hooks['beforeCreate']>} */
1039
+ declare const beforeCreate: Hook<Hooks["beforeCreate"]>;
1040
+ /** @type {Hook<Hooks['afterCreate']>} */
1041
+ declare const afterCreate: Hook<Hooks["afterCreate"]>;
1042
+ /** @type {Hook<Hooks['beforeUpdate']>} */
1043
+ declare const beforeUpdate: Hook<Hooks["beforeUpdate"]>;
1044
+ /** @type {Hook<Hooks['afterUpdate']>} */
1045
+ declare const afterUpdate: Hook<Hooks["afterUpdate"]>;
1046
+ /** @type {Hook<Hooks['beforeDelete']>} */
1047
+ declare const beforeDelete: Hook<Hooks["beforeDelete"]>;
1048
+ /** @type {Hook<Hooks['afterDelete']>} */
1049
+ declare const afterDelete: Hook<Hooks["afterDelete"]>;
1459
1050
 
1460
- type Select = {
1461
- field: string;
1462
- table?: string;
1463
- fn?: string;
1464
- };
1465
- declare namespace Select {
1466
- type Param = boolean | string | Select;
1467
- }
1468
- type JoinType = 'left' | 'right' | 'inner' | 'full';
1469
- interface Join<T extends TableDefine = TableDefine> {
1470
- type: JoinType;
1471
- table: T;
1472
- /** 关联项目 { [this table field]: base table field } */
1473
- on: {
1474
- [k: string]: string;
1475
- };
1476
- }
1477
- interface Options {
1478
- distinct?: boolean;
1479
- range?: FindRange;
1480
- select?: Record<string, Select> | null;
1481
- /** 排序配置,true 表示逆序 */
1482
- sort?: [field: string, desc: boolean][];
1483
- /** 匹配信息 */
1484
- where: WhereValue[];
1485
- /** 偏移量 */
1486
- offset?: number;
1487
- /** 最大返回数 */
1488
- limit?: number;
1489
- update?: Record<string, SetValue>;
1490
- alias?: string;
1491
- group?: string[];
1492
- lock?: 'S' | 'X' | null;
1493
- }
1494
- interface Queryable<T extends Fields = Fields> extends TableDefine<T> {
1495
- readonly options: Options;
1496
- }
1051
+ type ClassDecorator = (val: Function, ctx: ClassDecoratorContext) => any;
1052
+ type FieldDecorator<T> = (val: {
1053
+ get(): T;
1054
+ set(v: T): void;
1055
+ }, ctx: ClassAccessorDecoratorContext) => any;
1056
+ type MethodDecorator<T extends Function> = (val: T, ctx: ClassMethodDecoratorContext<any, T>) => any;
1497
1057
 
1498
- type TableType = '' | 'table' | 'view';
1499
- interface FindArg {
1500
- /** 排序配置,true 表示逆序 */
1501
- sort?: [field: string, desc: boolean][];
1502
- /** 匹配信息 */
1503
- where: WhereValue[];
1504
- select: [string, Select][];
1505
- /** 偏移量 */
1506
- offset?: number;
1507
- /** 最大返回数 */
1508
- limit?: number;
1509
- }
1510
- interface JOIN {
1511
- type?: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL' | 'CROSS';
1512
- table: string;
1513
- columns: Record<string, DBColumn>;
1514
- alias?: string;
1515
- condition?: WhereValue[];
1516
- }
1517
- type LockType = 'S' | 'X';
1518
- interface SelectItem {
1519
- distinct?: boolean;
1520
- select: [string, Select][];
1521
- table: string;
1522
- columns: Record<string, DBColumn>;
1523
- alias?: string;
1524
- /** 匹配信息 */
1525
- where: WhereValue[];
1526
- group: string[];
1527
- having: WhereValue[];
1528
- /** 排序配置,true 表示逆序 */
1529
- sort: [field: string, desc: boolean][];
1530
- /** 偏移量 */
1531
- offset?: number;
1532
- /** 最大返回数 */
1533
- limit?: number;
1534
- lock?: LockType | null;
1535
- }
1536
- type GetName = (table?: string) => string;
1537
- interface DBColumn {
1538
- type: string;
1539
- size?: number;
1540
- scale?: number;
1541
- default?: any;
1542
- nullable?: boolean;
1058
+ /** 特性支持情况 */
1059
+ interface Support {
1060
+ /** 是否支持 sql 查询 */
1061
+ sql?: boolean;
1062
+ /** 是否支持数组类型 */
1543
1063
  array?: boolean;
1544
- primary?: number;
1545
- }
1546
- interface DBIndex {
1547
- fields: string[];
1548
- includes?: string[];
1549
- unique?: boolean;
1550
- name?: string;
1551
- }
1552
- interface DBTable {
1553
- table: string;
1554
- fields: Record<string, DBColumn>;
1555
- indexes?: DBIndex[];
1556
- primary?: string;
1064
+ /** 是否支持对象存储 */
1065
+ object?: boolean;
1066
+ /** 是否支持递归查询 */
1067
+ recursive?: boolean;
1068
+ [key: string]: undefined | boolean;
1557
1069
  }
1558
- interface TableConnection<E extends object = object> {
1559
- insert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[], ignoreConflict?: boolean): PromiseLike<any[]>;
1560
- upsert(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, data: object[], key: string[], conflict: true | string[], conflictSet?: Record<string, SetValue>): PromiseLike<any[]>;
1561
- update(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<number>;
1562
- updateReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, update: Record<string, SetValue>, where?: WhereValue[] | null): PromiseLike<any[]>;
1563
- updateMany(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[]): PromiseLike<number>;
1564
- updateManyReturn(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
1565
- count(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
1566
- select(environment: Environment<E>, select: SelectItem[]): PromiseLike<any[]>;
1567
- delete(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
1568
- deleteReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
1070
+
1071
+ type MaybePromise<T> = PromiseLike<T> | T;
1072
+
1073
+ interface Hook<T extends Hooks[keyof Hooks]> {
1074
+ (approach?: boolean): MethodDecorator<T>;
1075
+ (hook: T, approach?: boolean): ClassDecorator;
1076
+ (Model: Function, hook: T, approach?: boolean): void;
1569
1077
  }
1570
- interface IConnection<E extends object = object> extends TableConnection<E> {
1571
- /** 数据库类型 */
1572
- readonly dbType: string;
1573
- /** 数据库版本 */
1574
- dbVersion(environment: Environment<E>): PromiseLike<string>;
1575
- exec(environment: Environment<E>, ...values: any): Promise<number>;
1078
+
1079
+ /**
1080
+ * @param {WhereValue[]?} [items]
1081
+ * @returns {WhereValue[]?}
1082
+ */
1083
+ declare function toNot(items?: WhereValue[] | null): WhereValue[] | null;
1084
+ type WhereItem = {
1085
+ exists?: false | null | undefined;
1086
+ where?: null | undefined;
1087
+ or?: null | undefined;
1088
+ field: string | {
1089
+ table?: string;
1090
+ field: string;
1091
+ } | (string | {
1092
+ table?: string;
1093
+ field: string;
1094
+ })[];
1095
+ value: any;
1096
+ subquery?: SelectItem[] | null | undefined;
1097
+ not?: boolean | undefined;
1098
+ operator?: string | null | undefined;
1099
+ };
1100
+ type WhereExists = {
1101
+ where?: null | undefined;
1102
+ or?: null | undefined;
1103
+ field?: null | undefined;
1104
+ exists: true;
1105
+ subquery: SelectItem[];
1106
+ not?: boolean | undefined;
1107
+ };
1108
+ type WhereRaw = {
1109
+ exists?: false | null | undefined;
1110
+ field?: null | undefined;
1111
+ or?: null | undefined;
1112
+ where: readonly string[];
1113
+ values: readonly any[];
1114
+ not?: boolean | undefined;
1115
+ };
1116
+ type WhereOr = {
1117
+ exists?: false | null | undefined;
1118
+ where?: null | undefined;
1119
+ field?: null | undefined;
1120
+ or: WhereValue[][];
1121
+ not?: boolean | undefined;
1122
+ };
1123
+ type WhereValue = WhereItem | WhereExists | WhereRaw | WhereOr;
1124
+ type WhereLike = {
1125
+ toWhereValue(): WhereValue[][];
1126
+ };
1127
+ type Wheres = WhereLike | Record<string, any> | (WhereLike | Record<string, any>)[];
1128
+ declare class Where {
1129
+ /**
1130
+ * @overload
1131
+ * @param {Wheres} matches
1132
+ * @returns {WhereValue[]?}
1133
+ */
1134
+ static parse(matches: Wheres): WhereValue[] | null;
1135
+ /**
1136
+ * @overload
1137
+ * @param {string | string[]} field
1138
+ * @param {any} value
1139
+ * @returns {WhereValue[]?}
1140
+ */
1141
+ static parse(field: string | string[], value: any): WhereValue[] | null;
1142
+ /**
1143
+ * @overload
1144
+ * @param {string | string[]} field
1145
+ * @param {string} operator
1146
+ * @param {any} value
1147
+ * @param {boolean} [not]
1148
+ * @returns {WhereValue[]?}
1149
+ */
1150
+ static parse(field: string | string[], operator: string, value: any, not?: boolean | undefined): WhereValue[] | null;
1151
+ /**
1152
+ * @overload
1153
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1154
+ * @returns {WhereValue[]?}
1155
+ */
1156
+ static parse(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): WhereValue[] | null;
1157
+ /**
1158
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1159
+ * @returns {WhereValue[]?}
1160
+ */
1161
+ static parseParams(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): WhereValue[] | null;
1162
+ /**
1163
+ * @overload
1164
+ * @param {Wheres} matches
1165
+ * @returns {Where}
1166
+ */
1167
+ static and(matches: Wheres): Where;
1168
+ /**
1169
+ *
1170
+ * @overload
1171
+ * @param {TemplateStringsArray} where
1172
+ * @param {...any} values
1173
+ * @returns {Where}
1174
+ */
1175
+ static and(where: TemplateStringsArray, ...values: any[]): Where;
1176
+ /**
1177
+ * @overload
1178
+ * @param {string} field
1179
+ * @param {any} value
1180
+ * @returns {Where}
1181
+ */
1182
+ static and(field: string, value: any): Where;
1183
+ /**
1184
+ * @overload
1185
+ * @param {string[]} field
1186
+ * @param {any[]} value
1187
+ * @returns {Where}
1188
+ */
1189
+ static and(field: string[], value: any[]): Where;
1190
+ /**
1191
+ * @overload
1192
+ * @param {string} field
1193
+ * @param {string} operator
1194
+ * @param {any} value
1195
+ * @param {boolean} [not]
1196
+ * @returns {Where}
1197
+ */
1198
+ static and(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1199
+ /**
1200
+ * @overload
1201
+ * @param {string[]} field
1202
+ * @param {string} operator
1203
+ * @param {any[]} value
1204
+ * @param {boolean} [not]
1205
+ * @returns {Where}
1206
+ */
1207
+ static and(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1208
+ /**
1209
+ * @overload
1210
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1211
+ * @returns {Where}
1212
+ */
1213
+ static and(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1214
+ /**
1215
+ * @overload
1216
+ * @param {Wheres} matches
1217
+ * @returns {Where}
1218
+ */
1219
+ static where(matches: Wheres): Where;
1220
+ /**
1221
+ *
1222
+ * @overload
1223
+ * @param {TemplateStringsArray} where
1224
+ * @param {...any} values
1225
+ * @returns {Where}
1226
+ */
1227
+ static where(where: TemplateStringsArray, ...values: any[]): Where;
1228
+ /**
1229
+ * @overload
1230
+ * @param {string} field
1231
+ * @param {any} value
1232
+ * @returns {Where}
1233
+ */
1234
+ static where(field: string, value: any): Where;
1235
+ /**
1236
+ * @overload
1237
+ * @param {string[]} field
1238
+ * @param {any[]} value
1239
+ * @returns {Where}
1240
+ */
1241
+ static where(field: string[], value: any[]): Where;
1242
+ /**
1243
+ * @overload
1244
+ * @param {string} field
1245
+ * @param {string} operator
1246
+ * @param {any} value
1247
+ * @param {boolean} [not]
1248
+ * @returns {Where}
1249
+ */
1250
+ static where(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1576
1251
  /**
1577
- * 执行一条语句
1578
- * @param sql 要执行的 SQL 语句
1252
+ * @overload
1253
+ * @param {string[]} field
1254
+ * @param {string} operator
1255
+ * @param {any[]} value
1256
+ * @param {boolean} [not]
1257
+ * @returns {Where}
1579
1258
  */
1580
- query(environment: Environment<E>, ...values: any): PromiseLike<any[]>;
1581
- type(environment: Environment<E>, table: string): PromiseLike<TableType | null>;
1582
- createTable(environment: Environment<E>, table: string, columns: Column<any>[]): PromiseLike<number>;
1583
- dropTable(environment: Environment<E>, table: string): PromiseLike<number>;
1584
- renameTable(environment: Environment<E>, table: string, newName: string): PromiseLike<number>;
1585
- addColumn(environment: Environment<E>, table: string, column: string, type: string, options: ColumnOptions<any>): PromiseLike<number>;
1586
- changeColumn(environment: Environment<E>, table: string, column: string, type: string, options: ColumnOptions<any>): PromiseLike<number>;
1587
- changeColumnNull(environment: Environment<E>, table: string, column: string, nullable: boolean): PromiseLike<number>;
1588
- dropColumn(environment: Environment<E>, table: string, column: string): PromiseLike<number>;
1589
- renameColumn(environment: Environment<E>, table: string, column: string, newName: string): PromiseLike<number>;
1590
- addIndex(environment: Environment<E>, table: string, name: string, columns: string[], options: IndexOptions): PromiseLike<number>;
1591
- dropIndex(environment: Environment<E>, table: string, name: string): PromiseLike<number>;
1592
- loadTables(environment: Environment<E>, tables: string[]): PromiseLike<DBTable[]>;
1593
- syncTables(environment: Environment<E>, tables: DBTable[]): PromiseLike<void>;
1594
- transaction<R>(environment: Environment<E>, fn: (t: E) => R | PromiseLike<R>): PromiseLike<R>;
1595
- }
1596
- interface TableConnect<E extends object = object> {
1597
- (conn: IConnection<E>): TableConnection<E>;
1598
- }
1599
- interface Skip {
1600
- uncreatable?: boolean;
1601
- immutable?: boolean;
1602
- specific?: boolean;
1603
- where?: boolean;
1604
- }
1605
- interface TransactionFn {
1606
- <T>(fn: (t: Connection) => PromiseLike<T> | T): Promise<T>;
1607
- }
1608
- type TransactionHandlerArray = [
1609
- promise: TransactionHandler['promise'],
1610
- commit: TransactionHandler['commit'],
1611
- rollback: TransactionHandler['rollback']
1612
- ];
1613
- interface TransactionHandler extends TransactionHandlerArray {
1614
- promise: Promise<void>;
1615
- commit(): Promise<void>;
1616
- rollback(e?: any): Promise<void>;
1617
- [Symbol.dispose](): void;
1618
- }
1619
-
1620
- declare const Destroy: unique symbol;
1621
- interface Destroy {
1622
- [Destroy](connection: Connection, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
1623
- }
1624
- declare const PseudoDestroy: unique symbol;
1625
- interface PseudoDestroy {
1626
- [PseudoDestroy](connection: Connection, update: Record<string, SetValue>, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
1627
- }
1628
- declare const Save: unique symbol;
1629
- interface Save {
1630
- [Save](connection: Connection, run: (data: any, newData?: any) => Promise<object | null>, newData: Record<string, any> | null, table: TableDefine): PromiseLike<this | null>;
1631
- }
1632
- declare const Create: unique symbol;
1633
- interface Create<T = unknown> {
1634
- [Create](connection: Connection, data: object, run: (data: any, that: any) => Promise<object>, table: TableDefine): PromiseLike<T>;
1635
- }
1636
- declare const Build: unique symbol;
1637
- interface Build<T = unknown> {
1638
- [Build](data: object, others: object | boolean): T;
1639
- }
1640
-
1641
- /**
1642
- * @template {{}} [E={}]
1643
- */
1644
- declare class Connection<E extends {} = {}> {
1259
+ static where(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1645
1260
  /**
1646
- *
1647
- * @param {PromiseLike<IConnection<E>> | IConnection<E>} connection
1648
- * @param {E?} [transaction]
1261
+ * @overload
1262
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1263
+ * @returns {Where}
1649
1264
  */
1650
- constructor(connection: PromiseLike<IConnection<E>> | IConnection<E>, transaction?: E | null);
1265
+ static where(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1651
1266
  /**
1652
- *
1653
- * @returns {Connection<E>}
1267
+ * @overload
1268
+ * @param {Wheres} matches
1269
+ * @returns {Where}
1654
1270
  */
1655
- clone(): Connection<E>;
1656
- /** @return {Promise<string>} */
1657
- dbType(): Promise<string>;
1658
- /** @return {Promise<string>} */
1659
- dbVersion(): Promise<string>;
1271
+ static or(matches: Wheres): Where;
1660
1272
  /**
1661
1273
  *
1662
- * @param {...any} values
1663
- * @returns {Promise<any[]>}
1274
+ * @overload
1275
+ * @param {TemplateStringsArray} where
1276
+ * @param {...any} values
1277
+ * @returns {Where}
1664
1278
  */
1665
- query(...values: any[]): Promise<any[]>;
1279
+ static or(where: TemplateStringsArray, ...values: any[]): Where;
1666
1280
  /**
1667
- *
1668
- * @param {...any} values
1669
- * @returns {Promise<number>}
1281
+ * @overload
1282
+ * @param {string} field
1283
+ * @param {any} value
1284
+ * @returns {Where}
1670
1285
  */
1671
- exec(...values: any[]): Promise<number>;
1286
+ static or(field: string, value: any): Where;
1287
+ /**
1288
+ * @overload
1289
+ * @param {string[]} field
1290
+ * @param {any[]} value
1291
+ * @returns {Where}
1292
+ */
1293
+ static or(field: string[], value: any[]): Where;
1294
+ /**
1295
+ * @overload
1296
+ * @param {string} field
1297
+ * @param {string} operator
1298
+ * @param {any} value
1299
+ * @param {boolean} [not]
1300
+ * @returns {Where}
1301
+ */
1302
+ static or(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1303
+ /**
1304
+ * @overload
1305
+ * @param {string[]} field
1306
+ * @param {string} operator
1307
+ * @param {any[]} value
1308
+ * @param {boolean} [not]
1309
+ * @returns {Where}
1310
+ */
1311
+ static or(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1312
+ /**
1313
+ * @overload
1314
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1315
+ * @returns {Where}
1316
+ */
1317
+ static or(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1318
+ /**
1319
+ * @overload
1320
+ * @param {Wheres} matches
1321
+ * @returns {Where}
1322
+ */
1323
+ static not(matches: Wheres): Where;
1672
1324
  /**
1673
1325
  *
1674
- * @param {string} table
1675
- * @returns {Promise<TableType?>}
1326
+ * @overload
1327
+ * @param {TemplateStringsArray} where
1328
+ * @param {...any} values
1329
+ * @returns {Where}
1676
1330
  */
1677
- type(table: string): Promise<TableType | null>;
1331
+ static not(where: TemplateStringsArray, ...values: any[]): Where;
1678
1332
  /**
1679
- * @template T
1680
1333
  * @overload
1681
- * @param {Build<T>} build
1682
- * @param {object} data
1683
- * @param {object | boolean} [saved]
1684
- * @returns {T}
1334
+ * @param {string} field
1335
+ * @param {any} value
1336
+ * @returns {Where}
1685
1337
  */
1686
- build<T extends Fields>(build: Build<T>, data: object, saved?: object | boolean): T;
1338
+ static not(field: string, value: any): Where;
1687
1339
  /**
1688
- * @template {Fields} T
1689
1340
  * @overload
1690
- * @param {TableDefine<T>} table
1691
- * @param {object} data
1692
- * @param {object | boolean} [saved]
1693
- * @returns {FieldValue<T>}
1341
+ * @param {string[]} field
1342
+ * @param {any[]} value
1343
+ * @returns {Where}
1694
1344
  */
1695
- build<T extends Fields>(table: TableDefine<T>, data: object, saved?: object | boolean): FieldValue<T>;
1345
+ static not(field: string[], value: any[]): Where;
1696
1346
  /**
1697
- * @template {TableDefine} T
1698
1347
  * @overload
1699
- * @param {T} model
1700
- * @param {object[]} list
1701
- * @returns {Promise<TableValue<T>[]>}
1348
+ * @param {string} field
1349
+ * @param {string} operator
1350
+ * @param {any} value
1351
+ * @param {boolean} [not]
1352
+ * @returns {Where}
1702
1353
  */
1703
- create<T extends TableDefine>(model: T, list: object[]): Promise<TableValue<T>[]>;
1354
+ static not(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1704
1355
  /**
1705
- * @template {TableDefine} T
1706
1356
  * @overload
1707
- * @param {T} model
1708
- * @param {object} value
1709
- * @returns {Promise<T extends Build<infer R> ? R : TableValue<T>>}
1357
+ * @param {string[]} field
1358
+ * @param {string} operator
1359
+ * @param {any[]} value
1360
+ * @param {boolean} [not]
1361
+ * @returns {Where}
1710
1362
  */
1711
- create<T extends TableDefine>(model: T, value: object): Promise<T extends Build<infer R> ? R : TableValue<T>>;
1363
+ static not(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1364
+ /**
1365
+ * @overload
1366
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1367
+ * @returns {Where}
1368
+ */
1369
+ static not(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1712
1370
  /**
1713
- * @template {TableDefine} T
1714
1371
  * @overload
1715
- * @param {T} model
1716
- * @param {object | object[]} value
1717
- * @returns {Promise<TableValue<T>[] | (T extends Build<infer R> ? R : TableValue<T>)>}
1372
+ * @param {Wheres} matches
1373
+ * @returns {Where}
1718
1374
  */
1719
- create<T extends TableDefine>(model: T, value: object | object[]): Promise<TableValue<T>[] | (T extends Build<infer R> ? R : TableValue<T>)>;
1375
+ static orNot(matches: Wheres): Where;
1720
1376
  /**
1721
1377
  *
1722
- * @template {TableDefine} T
1723
- * @param {T} sql
1724
- * @param {string[]} fields
1725
- * @param {Skip} [skip]
1726
- * @returns {Promise<T extends TableDefine<infer F> ? FieldValue<F>[] : never>}
1378
+ * @overload
1379
+ * @param {TemplateStringsArray} where
1380
+ * @param {...any} values
1381
+ * @returns {Where}
1727
1382
  */
1728
- search<T extends TableDefine>(sql: T, fields: string[], skip?: Skip): Promise<T extends TableDefine<infer F> ? FieldValue<F>[] : never>;
1383
+ static orNot(where: TemplateStringsArray, ...values: any[]): Where;
1384
+ /**
1385
+ * @overload
1386
+ * @param {string} field
1387
+ * @param {any} value
1388
+ * @returns {Where}
1389
+ */
1390
+ static orNot(field: string, value: any): Where;
1391
+ /**
1392
+ * @overload
1393
+ * @param {string[]} field
1394
+ * @param {any[]} value
1395
+ * @returns {Where}
1396
+ */
1397
+ static orNot(field: string[], value: any[]): Where;
1398
+ /**
1399
+ * @overload
1400
+ * @param {string} field
1401
+ * @param {string} operator
1402
+ * @param {any} value
1403
+ * @param {boolean} [not]
1404
+ * @returns {Where}
1405
+ */
1406
+ static orNot(field: string, operator: string, value: any, not?: boolean | undefined): Where;
1407
+ /**
1408
+ * @overload
1409
+ * @param {string[]} field
1410
+ * @param {string} operator
1411
+ * @param {any[]} value
1412
+ * @param {boolean} [not]
1413
+ * @returns {Where}
1414
+ */
1415
+ static orNot(field: string[], operator: string, value: any[], not?: boolean | undefined): Where;
1416
+ /**
1417
+ * @overload
1418
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1419
+ * @returns {Where}
1420
+ */
1421
+ static orNot(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): Where;
1729
1422
  /**
1730
1423
  *
1731
- * @template {TableDefine} T
1732
- * @param {T} sql
1733
- * @param {Skip} [skip]
1734
- * @returns {Promise<T extends Build<infer R > ? R[] : T extends TableDefine<infer F> ? FieldValue<F>[] : never>}
1424
+ * @param {...SelectItem} subquery
1425
+ * @returns {Where}
1735
1426
  */
1736
- find<T extends TableDefine>(sql: T, skip?: Skip): Promise<T extends Build<infer R> ? R[] : T extends TableDefine<infer F> ? FieldValue<F>[] : never>;
1427
+ static exists(...subquery: SelectItem[]): Where;
1737
1428
  /**
1738
1429
  *
1739
- * @template {TableDefine} T
1740
- * @param {T} sql
1741
- * @param {Skip} [skip]
1742
- * @returns {Promise<T extends Build<infer R > ? R : T extends TableDefine<infer F> ? FieldValue<F> : never>}
1430
+ * @param {...SelectItem} subquery
1431
+ * @returns {Where}
1743
1432
  */
1744
- first<T extends TableDefine>(sql: T, skip?: Skip): Promise<T extends Build<infer R> ? R : T extends TableDefine<infer F> ? FieldValue<F> : never>;
1433
+ static notExists(...subquery: SelectItem[]): Where;
1434
+ toWhereValue(): WhereValue[][];
1745
1435
  /**
1746
- * @template T
1747
- * @param {TableDefine} model
1748
- * @param {T} data
1749
- * @param {Record<string, any>?} [newData]
1750
- * @param {Skip} [skip]
1751
- * @returns {Promise<(T extends Save ? T : object)?>}
1436
+ * @overload
1437
+ * @param {Wheres} matches
1438
+ * @returns {this}
1752
1439
  */
1753
- save<T>(model: TableDefine, data: T, newData?: Record<string, any> | null, skip?: Skip): Promise<(T extends Save ? T : object) | null>;
1440
+ and(matches: Wheres): this;
1754
1441
  /**
1755
1442
  *
1756
- * @template T
1757
- * @param {TableDefine} tableDef
1758
- * @param {T} data
1759
- * @returns {Promise<(T extends Destroy ? T : object)?>}
1443
+ * @overload
1444
+ * @param {TemplateStringsArray} where
1445
+ * @param {...any} values
1446
+ * @returns {this}
1760
1447
  */
1761
- completelyDestroy<T>(tableDef: TableDefine, data: T): Promise<(T extends Destroy ? T : object) | null>;
1448
+ and(where: TemplateStringsArray, ...values: any[]): this;
1762
1449
  /**
1763
- *
1764
- * @template {object} T
1765
- * @param {TableDefine} tableDef
1766
- * @param {T} data
1767
- * @param {Record<string, SetValue>} value
1768
- * @returns {Promise<(T extends PseudoDestroy ? T : object)?>}
1450
+ * @overload
1451
+ * @param {string} field
1452
+ * @param {any} value
1453
+ * @returns {this}
1769
1454
  */
1770
- pseudoDestroy<T extends unknown>(tableDef: TableDefine, data: T, value: Record<string, SetValue>): Promise<(T extends PseudoDestroy ? T : object) | null>;
1455
+ and(field: string, value: any): this;
1771
1456
  /**
1772
- * @template {Destroy & PseudoDestroy} T
1773
1457
  * @overload
1774
- * @param {TableDefine} table
1775
- * @param {T} data
1776
- * @param {Record<string, any> | boolean} [update]
1777
- * @returns {Promise<T?>}
1458
+ * @param {string[]} field
1459
+ * @param {any[]} value
1460
+ * @returns {this}
1778
1461
  */
1779
- destroy<T extends Destroy & PseudoDestroy>(table: TableDefine, data: T, update?: boolean | Record<string, any> | undefined): Promise<T | null>;
1462
+ and(field: string[], value: any[]): this;
1780
1463
  /**
1781
- * @template {Destroy & PseudoDestroy} T
1782
1464
  * @overload
1783
- * @param {TableDefine} table
1784
- * @param {T} data
1785
- * @param {Record<string, any> | boolean} [update]
1786
- * @returns {Promise<T | object | null>}
1465
+ * @param {string} field
1466
+ * @param {string} operator
1467
+ * @param {any} value
1468
+ * @param {boolean} [not]
1469
+ * @returns {this}
1787
1470
  */
1788
- destroy<T extends Destroy & PseudoDestroy>(table: TableDefine, data: T, update?: boolean | Record<string, any> | undefined): Promise<T | object | null>;
1471
+ and(field: string, operator: string, value: any, not?: boolean | undefined): this;
1789
1472
  /**
1790
1473
  * @overload
1791
- * @param {TableDefine} table
1792
- * @param {any} data
1793
- * @param {Record<string, any> | boolean} [update]
1794
- * @returns {Promise<object?>}
1474
+ * @param {string[]} field
1475
+ * @param {string} operator
1476
+ * @param {any[]} value
1477
+ * @param {boolean} [not]
1478
+ * @returns {this}
1795
1479
  */
1796
- destroy(table: TableDefine, data: any, update?: boolean | Record<string, any> | undefined): Promise<object | null>;
1480
+ and(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1797
1481
  /**
1798
- * @param {Queryable} queryable
1799
- * @param {Record<string, SetValue> | boolean} [update]
1800
- * @returns {Promise<number>}
1482
+ * @overload
1483
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1484
+ * @returns {this}
1801
1485
  */
1802
- destroyMany(queryable: Queryable, update?: Record<string, SetValue> | boolean): Promise<number>;
1486
+ and(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1803
1487
  /**
1804
- * @template {object} T
1805
1488
  * @overload
1806
- * @param {TableDefine} tableDefine
1807
- * @param {T} data
1808
- * @param {boolean} [ignoreConflict]
1809
- * @returns {Promise<T>}
1489
+ * @param {Wheres} matches
1490
+ * @returns {this}
1810
1491
  */
1811
- insert<T extends unknown>(tableDefine: TableDefine, data: T, ignoreConflict?: boolean | undefined): Promise<T>;
1492
+ or(matches: Wheres): this;
1812
1493
  /**
1813
- * @template {object} T
1494
+ *
1814
1495
  * @overload
1815
- * @param {TableDefine} tableDefine
1816
- * @param {T[]} data
1817
- * @param {boolean} [ignoreConflict]
1818
- * @returns {Promise<T[]>}
1496
+ * @param {TemplateStringsArray} where
1497
+ * @param {...any} values
1498
+ * @returns {this}
1819
1499
  */
1820
- insert<T extends unknown>(tableDefine: TableDefine, data: T[], ignoreConflict?: boolean | undefined): Promise<T[]>;
1500
+ or(where: TemplateStringsArray, ...values: any[]): this;
1821
1501
  /**
1822
- * @template {object} T
1823
1502
  * @overload
1824
- * @param {TableDefine} tableDefine
1825
- * @param {T} data
1826
- * @param {string[]} [keys]
1827
- * @param {boolean} [ignoreConflict]
1828
- * @returns {Promise<T>}
1503
+ * @param {string} field
1504
+ * @param {any} value
1505
+ * @returns {this}
1829
1506
  */
1830
- insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T>;
1507
+ or(field: string, value: any): this;
1831
1508
  /**
1832
- * @template {object} T
1833
1509
  * @overload
1834
- * @param {TableDefine} tableDefine
1835
- * @param {T[]} data
1836
- * @param {string[]} [keys]
1837
- * @param {boolean} [ignoreConflict]
1838
- * @returns {Promise<T[]>}
1510
+ * @param {string[]} field
1511
+ * @param {any[]} value
1512
+ * @returns {this}
1839
1513
  */
1840
- insert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T[]>;
1514
+ or(field: string[], value: any[]): this;
1841
1515
  /**
1842
- * @template {object} T
1843
1516
  * @overload
1844
- * @param {TableDefine} tableDefine
1845
- * @param {T} data
1846
- * @param {string[] | boolean} [keys]
1847
- * @param {boolean} [ignoreConflict]
1848
- * @returns {Promise<T>}
1517
+ * @param {string} field
1518
+ * @param {string} operator
1519
+ * @param {any} value
1520
+ * @param {boolean} [not]
1521
+ * @returns {this}
1849
1522
  */
1850
- insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T>;
1523
+ or(field: string, operator: string, value: any, not?: boolean | undefined): this;
1851
1524
  /**
1852
- * @template {object} T
1853
1525
  * @overload
1854
- * @param {TableDefine} tableDefine
1855
- * @param {T[]} data
1856
- * @param {string[] | boolean} [keys]
1857
- * @param {boolean} [ignoreConflict]
1858
- * @returns {Promise<T[]>}
1526
+ * @param {string[]} field
1527
+ * @param {string} operator
1528
+ * @param {any[]} value
1529
+ * @param {boolean} [not]
1530
+ * @returns {this}
1859
1531
  */
1860
- insert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T[]>;
1532
+ or(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1861
1533
  /**
1862
- * @template {object} T
1863
1534
  * @overload
1864
- * @param {TableDefine} tableDefine
1865
- * @param {T | T[]} data
1866
- * @param {string[] | boolean} [keys]
1867
- * @param {boolean} [ignoreConflict]
1868
- * @returns {Promise<T | T[]>}
1535
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1536
+ * @returns {this}
1869
1537
  */
1870
- insert<T extends unknown>(tableDefine: TableDefine, data: T | T[], keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T | T[]>;
1538
+ or(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1871
1539
  /**
1872
- * @template {object} T
1873
1540
  * @overload
1874
- * @param {TableDefine} tableDefine
1875
- * @param {T} data
1876
- * @param {Record<string, SetValue>} [conflictSet]
1877
- * @returns {Promise<T>}
1541
+ * @param {Wheres} matches
1542
+ * @returns {this}
1878
1543
  */
1879
- upsert<T extends unknown>(tableDefine: TableDefine, data: T, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1544
+ not(matches: Wheres): this;
1880
1545
  /**
1881
- * @template {object} T
1546
+ *
1882
1547
  * @overload
1883
- * @param {TableDefine} tableDefine
1884
- * @param {T[]} data
1885
- * @param {Record<string, SetValue>} [conflictSet]
1886
- * @returns {Promise<T[]>}
1548
+ * @param {TemplateStringsArray} where
1549
+ * @param {...any} values
1550
+ * @returns {this}
1887
1551
  */
1888
- upsert<T extends unknown>(tableDefine: TableDefine, data: T[], conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1552
+ not(where: TemplateStringsArray, ...values: any[]): this;
1889
1553
  /**
1890
- * @template {object} T
1891
1554
  * @overload
1892
- * @param {TableDefine} tableDefine
1893
- * @param {T} data
1894
- * @param {null | string[]} [keys]
1895
- * @param {Record<string, SetValue>} [conflictSet]
1896
- * @returns {Promise<T>}
1555
+ * @param {string} field
1556
+ * @param {any} value
1557
+ * @returns {this}
1897
1558
  */
1898
- upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | null | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1559
+ not(field: string, value: any): this;
1899
1560
  /**
1900
- * @template {object} T
1901
1561
  * @overload
1902
- * @param {TableDefine} tableDefine
1903
- * @param {T[]} data
1904
- * @param {null | string[]} [keys]
1905
- * @param {Record<string, SetValue>} [conflictSet]
1906
- * @returns {Promise<T[]>}
1562
+ * @param {string[]} field
1563
+ * @param {any[]} value
1564
+ * @returns {this}
1907
1565
  */
1908
- upsert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: string[] | null | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1566
+ not(field: string[], value: any[]): this;
1909
1567
  /**
1910
- * @template {object} T
1911
1568
  * @overload
1912
- * @param {TableDefine} tableDefine
1913
- * @param {T} data
1914
- * @param {null | string[]} [keys]
1915
- * @param {string[] | boolean} [conflictKeys]
1916
- * @param {Record<string, SetValue>} [conflictSet]
1917
- * @returns {Promise<T>}
1569
+ * @param {string} field
1570
+ * @param {string} operator
1571
+ * @param {any} value
1572
+ * @param {boolean} [not]
1573
+ * @returns {this}
1918
1574
  */
1919
- upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | null | undefined, conflictKeys?: boolean | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1575
+ not(field: string, operator: string, value: any, not?: boolean | undefined): this;
1920
1576
  /**
1921
- * @template {object} T
1922
1577
  * @overload
1923
- * @param {TableDefine} tableDefine
1924
- * @param {T[]} data
1925
- * @param {null | string[]} [keys]
1926
- * @param {string[] | boolean} [conflictKeys]
1927
- * @param {Record<string, SetValue>} [conflictSet]
1928
- * @returns {Promise<T[]>}
1578
+ * @param {string[]} field
1579
+ * @param {string} operator
1580
+ * @param {any[]} value
1581
+ * @param {boolean} [not]
1582
+ * @returns {this}
1929
1583
  */
1930
- upsert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: string[] | null | undefined, conflictKeys?: boolean | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1584
+ not(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
1931
1585
  /**
1932
- * @template {object} T
1933
1586
  * @overload
1934
- * @param {TableDefine} tableDefine
1935
- * @param {T} data
1936
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
1937
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
1938
- * @param {Record<string, SetValue>} [conflictSet]
1939
- * @returns {Promise<T>}
1587
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1588
+ * @returns {this}
1940
1589
  */
1941
- upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: boolean | Record<string, SetValue> | string[] | null | undefined, conflictKeys?: boolean | Record<string, SetValue> | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1590
+ not(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
1942
1591
  /**
1943
- * @template {object} T
1944
1592
  * @overload
1945
- * @param {TableDefine} tableDefine
1946
- * @param {T[]} data
1947
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
1948
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
1949
- * @param {Record<string, SetValue>} [conflictSet]
1950
- * @returns {Promise<T[]>}
1593
+ * @param {Wheres} matches
1594
+ * @returns {this}
1951
1595
  */
1952
- upsert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: boolean | Record<string, SetValue> | string[] | null | undefined, conflictKeys?: boolean | Record<string, SetValue> | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1596
+ orNot(matches: Wheres): this;
1953
1597
  /**
1954
- * @template {object} T
1598
+ *
1955
1599
  * @overload
1956
- * @param {TableDefine} tableDefine
1957
- * @param {T | T[]} data
1958
- * @param {null | string[] | boolean | Record<string, SetValue>} [keys]
1959
- * @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
1960
- * @param {Record<string, SetValue>} [conflictSet]
1961
- * @returns {Promise<T | T[]>}
1600
+ * @param {TemplateStringsArray} where
1601
+ * @param {...any} values
1602
+ * @returns {this}
1962
1603
  */
1963
- upsert<T extends unknown>(tableDefine: TableDefine, data: T | T[], keys?: boolean | Record<string, SetValue> | string[] | null | undefined, conflictKeys?: boolean | Record<string, SetValue> | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T | T[]>;
1604
+ orNot(where: TemplateStringsArray, ...values: any[]): this;
1964
1605
  /**
1965
- * @param {TableDefine} tableDefine
1966
- * @param {Record<string, any>} update
1967
- * @param {Wheres?} [where]
1968
- * @param {boolean | Skip} [skip]
1969
- * @returns {Promise<number>}
1606
+ * @overload
1607
+ * @param {string} field
1608
+ * @param {any} value
1609
+ * @returns {this}
1970
1610
  */
1971
- update({ connect, table, fields }: TableDefine, update: Record<string, any>, where?: Wheres | null, skip?: boolean | Skip): Promise<number>;
1611
+ orNot(field: string, value: any): this;
1972
1612
  /**
1973
- * @template {Fields<MainFieldType>} T
1974
- * @param {TableDefine<T>} tableDefine
1975
- * @param {Record<string, any>} update
1976
- * @param {string[]?} [returning]
1977
- * @param {Wheres?} [where]
1978
- * @param {boolean | Skip} [skip]
1979
- * @returns {Promise<any[]>}
1613
+ * @overload
1614
+ * @param {string[]} field
1615
+ * @param {any[]} value
1616
+ * @returns {this}
1980
1617
  */
1981
- updateReturn<T extends Fields<MainFieldType>>({ connect, table, fields }: TableDefine<T>, update: Record<string, any>, returning?: string[] | null, where?: Wheres | null, skip?: boolean | Skip): Promise<any[]>;
1618
+ orNot(field: string[], value: any[]): this;
1982
1619
  /**
1983
- * @param {TableDefine} tableDefine
1984
- * @param {string[]} pKeys
1985
- * @param {string[]} setKeys
1986
- * @param {Record<string, any>[]} list
1987
- * @param {boolean | Skip} [skip]
1988
- * @returns {Promise<number>}
1620
+ * @overload
1621
+ * @param {string} field
1622
+ * @param {string} operator
1623
+ * @param {any} value
1624
+ * @param {boolean} [not]
1625
+ * @returns {this}
1989
1626
  */
1990
- updateMany({ connect, table, fields }: TableDefine, pKeys: string[], setKeys: string[], list: Record<string, any>[], skip?: boolean | Skip): Promise<number>;
1627
+ orNot(field: string, operator: string, value: any, not?: boolean | undefined): this;
1991
1628
  /**
1992
- * @template {Fields<MainFieldType>} T
1993
- * @param {TableDefine<T>} tableDefine
1994
- * @param {string[]} pKeys
1995
- * @param {string[]} setKeys
1996
- * @param {Record<string, any>[]} list
1997
- * @param {string[]?} [returning]
1998
- * @param {boolean | Skip} [skip]
1999
- * @returns {Promise<any[]>}
1629
+ * @overload
1630
+ * @param {string[]} field
1631
+ * @param {string} operator
1632
+ * @param {any[]} value
1633
+ * @param {boolean} [not]
1634
+ * @returns {this}
2000
1635
  */
2001
- updateManyReturn<T extends Fields<MainFieldType>>({ connect, table, fields }: TableDefine<T>, pKeys: string[], setKeys: string[], list: Record<string, any>[], returning?: string[] | null, skip?: boolean | Skip): Promise<any[]>;
1636
+ orNot(field: string[], operator: string, value: any[], not?: boolean | undefined): this;
2002
1637
  /**
2003
- * @param {TableDefine} tableDefine
2004
- * @param {Wheres?} [where]
2005
- * @returns {Promise<number>}
1638
+ * @overload
1639
+ * @param {[Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]} items
1640
+ * @returns {this}
2006
1641
  */
2007
- delete({ connect, table, fields }: TableDefine, where?: Wheres | null): Promise<number>;
1642
+ orNot(items: [Wheres] | [TemplateStringsArray, ...any] | [string | string[], any] | [string | string[], string, any, boolean?]): this;
2008
1643
  /**
2009
- * @template {Fields<MainFieldType>} T
2010
- * @param {TableDefine<T>} tableDefine
2011
- * @param {string[]?} [returning]
2012
- * @param {Wheres?} [where]
2013
- * @returns {Promise<any[]>}
1644
+ *
1645
+ * @param {...SelectItem} subquery
1646
+ * @returns {this}
2014
1647
  */
2015
- deleteReturn<T extends Fields<MainFieldType>>({ connect, table, fields }: TableDefine<T>, returning?: string[] | null, where?: Wheres | null): Promise<any[]>;
1648
+ exists(...subquery: SelectItem[]): this;
2016
1649
  /**
2017
1650
  *
2018
- * @param {Queryable} queryable
2019
- * @returns {Promise<number>}
1651
+ * @param {...SelectItem} subquery
1652
+ * @returns {this}
2020
1653
  */
1654
+ notExists(...subquery: SelectItem[]): this;
1655
+ #private;
1656
+ }
1657
+
1658
+ declare const Destroy: unique symbol;
1659
+ interface Destroy {
1660
+ [Destroy](connection: Connection, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
1661
+ }
1662
+ declare const PseudoDestroy: unique symbol;
1663
+ interface PseudoDestroy {
1664
+ [PseudoDestroy](connection: Connection, update: Record<string, SetValue>, run: (data: any) => Promise<object | null>, table: TableDefine<Fields<MainFieldType>>): PromiseLike<this | null>;
1665
+ }
1666
+ declare const Save: unique symbol;
1667
+ interface Save {
1668
+ [Save](connection: Connection, run: (data: any, newData?: any) => Promise<object | null>, newData: Record<string, any> | null, table: TableDefine): PromiseLike<this | null>;
1669
+ }
1670
+ declare const Create: unique symbol;
1671
+ interface Create<T = unknown> {
1672
+ [Create](connection: Connection, data: object, run: (data: any, that: any) => Promise<object>, table: TableDefine): PromiseLike<T>;
1673
+ }
1674
+ declare const Build: unique symbol;
1675
+ interface Build<T = unknown> {
1676
+ [Build](data: object, others: object | boolean): T;
1677
+ }
1678
+
1679
+ declare class Connection<E extends object = object> {
1680
+ #private;
1681
+ constructor(connection: PromiseLike<IConnection<E>> | IConnection<E>, transaction?: E | null);
1682
+ clone(): Connection<E>;
1683
+ call<T>(action: Action<T>): Promise<T>;
1684
+ dbType(): Promise<string>;
1685
+ dbVersion(): Promise<string>;
1686
+ query(...values: any[]): Promise<any[]>;
1687
+ exec(...values: any[]): Promise<number>;
1688
+ type(table: string): Promise<TableType | null>;
1689
+ build<T extends Fields>(build: Build<T>, data: object, saved?: object | boolean): T;
1690
+ build<T extends Fields>(table: TableDefine<T>, data: object, saved?: object | boolean): FieldValue<T>;
1691
+ build(p: Build | TableDefine, data: object, saved?: object | boolean): any;
1692
+ /** @deprecated */
1693
+ create<T extends TableDefine>(model: T, list: object[]): Promise<TableValue<T>[]>;
1694
+ /** @deprecated */
1695
+ create<T extends TableDefine>(model: T, value: object): Promise<T extends Build<infer R> ? R : TableValue<T>>;
1696
+ /** @deprecated */
1697
+ create<T extends TableDefine>(model: T, value: object | object[]): Promise<TableValue<T>[] | (T extends Build<infer R> ? R : TableValue<T>)>;
1698
+ /** @deprecated */
1699
+ search<T extends TableDefine>(sql: T, fields: string[], skip?: Skip): Promise<T extends TableDefine<infer F> ? FieldValue<F>[] : never>;
1700
+ /** @deprecated */
1701
+ find<T extends TableDefine>(sql: T, skip?: Skip): Promise<T extends Build<infer R> ? R[] : T extends TableDefine<infer F> ? FieldValue<F>[] : never>;
1702
+ /** @deprecated */
1703
+ first<T extends TableDefine>(sql: T, skip?: Skip): Promise<T extends Build<infer R> ? R : T extends TableDefine<infer F> ? FieldValue<F> : never>;
1704
+ /** @deprecated */
1705
+ save<T>(model: TableDefine, data: T, newData?: Record<string, any> | null, skip?: Skip): Promise<(T extends Save ? T : object) | null>;
1706
+ /** @deprecated */
1707
+ completelyDestroy<T>(tableDef: TableDefine, data: T): Promise<(T extends Destroy ? T : object) | null>;
1708
+ /** @deprecated */
1709
+ pseudoDestroy<T>(tableDef: TableDefine, data: T, value: Record<string, SetValue>): Promise<(T extends PseudoDestroy ? T : object) | null>;
1710
+ /** @deprecated */
1711
+ destroy<T extends Destroy & PseudoDestroy>(table: TableDefine, data: T, update?: boolean | Record<string, any> | undefined): Promise<T | null>;
1712
+ /** @deprecated */
1713
+ destroy<T extends Destroy & PseudoDestroy>(table: TableDefine, data: T, update?: boolean | Record<string, any> | undefined): Promise<T | object | null>;
1714
+ /** @deprecated */
1715
+ destroy(table: TableDefine, data: any, update?: boolean | Record<string, any> | undefined): Promise<object | null>;
1716
+ /** @deprecated */
1717
+ destroyMany(queryable: Queryable, update?: Record<string, SetValue> | boolean): Promise<number>;
1718
+ /** @deprecated */
1719
+ insert<T>(tableDefine: TableDefine, data: T, ignoreConflict?: boolean | undefined): Promise<T>;
1720
+ /** @deprecated */
1721
+ insert<T>(tableDefine: TableDefine, data: T[], ignoreConflict?: boolean | undefined): Promise<T[]>;
1722
+ /** @deprecated */
1723
+ insert<T>(tableDefine: TableDefine, data: T, keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T>;
1724
+ /** @deprecated */
1725
+ insert<T>(tableDefine: TableDefine, data: T[], keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T[]>;
1726
+ /** @deprecated */
1727
+ insert<T>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T>;
1728
+ /** @deprecated */
1729
+ insert<T>(tableDefine: TableDefine, data: T[], keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T[]>;
1730
+ /** @deprecated */
1731
+ insert<T>(tableDefine: TableDefine, data: T | T[], keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T | T[]>;
1732
+ /** @deprecated */
1733
+ upsert<T>(tableDefine: TableDefine, data: T, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1734
+ /** @deprecated */
1735
+ upsert<T>(tableDefine: TableDefine, data: T[], conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1736
+ /** @deprecated */
1737
+ upsert<T>(tableDefine: TableDefine, data: T, keys?: string[] | null | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1738
+ /** @deprecated */
1739
+ upsert<T>(tableDefine: TableDefine, data: T[], keys?: string[] | null | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1740
+ /** @deprecated */
1741
+ upsert<T>(tableDefine: TableDefine, data: T, keys?: string[] | null | undefined, conflictKeys?: boolean | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1742
+ /** @deprecated */
1743
+ upsert<T>(tableDefine: TableDefine, data: T[], keys?: string[] | null | undefined, conflictKeys?: boolean | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1744
+ /** @deprecated */
1745
+ upsert<T>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | Record<string, SetValue> | null | undefined, conflictKeys?: boolean | string[] | Record<string, SetValue> | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
1746
+ /** @deprecated */
1747
+ upsert<T>(tableDefine: TableDefine, data: T[], keys?: boolean | string[] | Record<string, SetValue> | null | undefined, conflictKeys?: boolean | string[] | Record<string, SetValue> | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
1748
+ /** @deprecated */
1749
+ upsert<T>(tableDefine: TableDefine, data: T | T[], keys?: boolean | string[] | Record<string, SetValue> | null | undefined, conflictKeys?: boolean | string[] | Record<string, SetValue> | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T | T[]>;
1750
+ /** @deprecated */
1751
+ update(table: TableDefine, update: Record<string, any>, where?: Wheres | null, skip?: boolean | Skip): Promise<number>;
1752
+ /** @deprecated */
1753
+ updateReturn<T extends Fields<MainFieldType>>(table: TableDefine<T>, update: Record<string, any>, returning?: string[] | null, where?: Wheres | null, skip?: boolean | Skip): Promise<any[]>;
1754
+ /** @deprecated */
1755
+ updateMany(table: TableDefine, pKeys: string[], setKeys: string[], list: Record<string, any>[], skip?: boolean | Skip): Promise<number>;
1756
+ /** @deprecated */
1757
+ updateManyReturn<T extends Fields<MainFieldType>>(table: TableDefine<T>, pKeys: string[], setKeys: string[], list: Record<string, any>[], returning?: string[] | null, skip?: boolean | Skip): Promise<any[]>;
1758
+ /** @deprecated */
1759
+ delete(table: TableDefine, where?: Wheres | null): Promise<number>;
1760
+ /** @deprecated */
1761
+ deleteReturn<T extends Fields<MainFieldType>>(table: TableDefine<T>, returning?: string[] | null, where?: Wheres | null): Promise<any[]>;
1762
+ /** @deprecated */
2021
1763
  count(queryable: Queryable): Promise<number>;
2022
- /**
2023
- * @param {Queryable} queryable
2024
- * @returns {Promise<any[]>}
2025
- */
1764
+ /** @deprecated */
2026
1765
  select(queryable: Queryable): Promise<any[]>;
2027
- /**
2028
- * @param {string} table
2029
- * @param {string} column
2030
- * @param {string} type
2031
- * @param {ColumnOptions<any>} options
2032
- * @returns {Promise<number>}
2033
- */
2034
1766
  addColumn(table: string, column: string, type: string, options: ColumnOptions<any>): Promise<number>;
2035
- /**
2036
- * @param {string} table
2037
- * @param {string} column
2038
- * @param {string} type
2039
- * @param {ColumnOptions<any>} options
2040
- * @returns {Promise<number>}
2041
- */
2042
1767
  changeColumn(table: string, column: string, type: string, options: ColumnOptions<any>): Promise<number>;
2043
- /**
2044
- * @param {string} table
2045
- * @param {string} column
2046
- * @param {boolean} nullable
2047
- * @returns {Promise<number>}
2048
- */
2049
1768
  changeColumnNull(table: string, column: string, nullable: boolean): Promise<number>;
2050
- /**
2051
- * @param {string} table
2052
- * @param {string} column
2053
- * @returns {Promise<number>}
2054
- */
2055
1769
  dropColumn(table: string, column: string): Promise<number>;
2056
- /**
2057
- * @param {string} table
2058
- * @param {string} column
2059
- * @param {string} newName
2060
- * @returns {Promise<number>}
2061
- */
2062
1770
  renameColumn(table: string, column: string, newName: string): Promise<number>;
2063
- /**
2064
- * @param {string} table
2065
- * @param {string} name
2066
- * @param {string[]} fields
2067
- * @param {IndexOptions} [options]
2068
- * @returns {Promise<number>}
2069
- */
2070
1771
  addIndex(table: string, name: string, fields: string[], options?: IndexOptions): Promise<number>;
2071
- /**
2072
- * @param {string} table
2073
- * @param {string} name
2074
- * @returns {Promise<number>}
2075
- */
2076
1772
  dropIndex(table: string, name: string): Promise<number>;
2077
- /**
2078
- * @param {string} table
2079
- * @param {Column<any>[]} fields
2080
- * @returns {Promise<number>}
2081
- */
2082
1773
  createTable(table: string, fields: Column<any>[]): Promise<number>;
2083
- /**
2084
- * @param {string} table
2085
- * @returns {Promise<number>}
2086
- */
2087
1774
  dropTable(table: string): Promise<number>;
2088
- /**
2089
- * @param {string} table
2090
- * @param {string} newName
2091
- * @returns {Promise<number>}
2092
- */
2093
1775
  renameTable(table: string, newName: string): Promise<number>;
2094
- abort(): boolean;
2095
- /**
2096
- * @param {string} table
2097
- * @returns {Promise<DBTable?>}
2098
- */
2099
1776
  loadTable(table: string): Promise<DBTable | null>;
2100
- /**
2101
- * @param {string[]} tables
2102
- * @returns {Promise<DBTable[]>}
2103
- */
2104
1777
  loadTables(tables: string[]): Promise<DBTable[]>;
2105
- /**
2106
- * @param {TableDefine | DBTable} table
2107
- * @returns {Promise<void>}
2108
- */
2109
1778
  syncTable(table: TableDefine | DBTable): Promise<void>;
2110
- /**
2111
- * @param {(TableDefine | DBTable)[]} tables
2112
- * @returns {Promise<void>}
2113
- */
2114
1779
  syncTables(tables: (TableDefine | DBTable)[]): Promise<void>;
1780
+ abort(): boolean;
1781
+ savepoint(): Promise<Savepoint>;
1782
+ [Symbol.dispose](): void;
2115
1783
  /**
2116
1784
  * @template T
2117
1785
  * @overload
2118
- * @param {(t: Connection) => PromiseLike<T> | T} fn
1786
+ * @param {Action<T> |((t: Connection, signal: AbortSignal) => PromiseLike<T> | T)} fn
2119
1787
  * @returns {Promise<T>}
2120
1788
  */
2121
- transaction<T>(fn: (t: Connection) => PromiseLike<T> | T): Promise<T>;
2122
- /**
2123
- * @overload
2124
- * @returns {TransactionHandler}
2125
- */
1789
+ transaction<T>(list: Action<T> | ((t: Connection, signal: AbortSignal) => PromiseLike<T> | T)): Promise<Awaited<T>>;
1790
+ transaction<T extends readonly [] | []>(list: {
1791
+ [P in keyof T]: Action<T[P]> | ((t: Connection, signal: AbortSignal) => PromiseLike<T[P]> | T[P]);
1792
+ }): Promise<{
1793
+ -readonly [P in keyof T]: Awaited<T[P]>;
1794
+ }>;
2126
1795
  transaction(): TransactionHandler;
2127
- [Symbol.dispose](): void;
2128
- #private;
1796
+ transaction(fn?: (Action<any> | ((t: Connection, signal: AbortSignal) => any))[] | Action<any> | ((t: Connection, signal: AbortSignal) => any)): Promise<any> | TransactionHandler;
2129
1797
  }
2130
1798
 
2131
1799
  /** @import { Fields } from './types' */
@@ -2154,8 +1822,8 @@ declare class Subquery {
2154
1822
  }
2155
1823
 
2156
1824
  type QueryOptions<T extends Fields, TB extends unknown = any> = {
2157
- connect?: TableConnect<any> | null | undefined;
2158
- table?: string | VirtualTable<object> | undefined;
1825
+ table?: string | undefined;
1826
+ connect?: TableConnect | null | undefined;
2159
1827
  fields: T;
2160
1828
  pseudo?: string | undefined;
2161
1829
  build?: ((a: object, b?: object | boolean) => TB) | null | undefined;
@@ -2164,8 +1832,8 @@ type QueryOptions<T extends Fields, TB extends unknown = any> = {
2164
1832
  * @template {Fields} T
2165
1833
  * @template {object} [TB=object]
2166
1834
  * @typedef {object} QueryOptions
2167
- * @property {TableConnect<any>?} [connect]
2168
- * @property {string | VirtualTable} [table]
1835
+ * @property {string} [table]
1836
+ * @property {TableConnect?} [connect]
2169
1837
  * @property {T} fields
2170
1838
  * @property {string} [pseudo]
2171
1839
  * @property {((a: object, b?: object | boolean) => TB)?} [build]
@@ -2191,10 +1859,10 @@ declare class Query<T extends Fields, TB extends unknown = any> extends Subquery
2191
1859
  * @param {boolean} [noBuild]
2192
1860
  */
2193
1861
  constructor(options: QueryOptions<T, TB> | Query<T, TB>, noBuild?: boolean);
1862
+ /** @readonly @type {string | undefined} */
1863
+ readonly table: string | undefined;
2194
1864
  /** @readonly @type {TableConnect | null | undefined} */
2195
1865
  readonly connect: TableConnect | null | undefined;
2196
- /** @readonly @type {string | VirtualTable | undefined} */
2197
- readonly table: string | VirtualTable | undefined;
2198
1866
  /** @readonly @type {T} */
2199
1867
  readonly fields: T;
2200
1868
  /** @readonly @type {string} */
@@ -2400,6 +2068,91 @@ declare function mergeHooks(...hooks: (Readonly<Partial<Hooks>> | Readonly<Parti
2400
2068
  */
2401
2069
  declare function bindHooks(hooks: Readonly<Partial<Hooks>>, that: any): Readonly<Partial<Hooks>>;
2402
2070
 
2071
+ declare function export_default$i<T>(tableDef: TableDefine, data: T): Action<(T extends Destroy ? T : object) | null>;
2072
+
2073
+ declare function export_default$h(queryable: Queryable): Action<number>;
2074
+
2075
+ declare function export_default$g<T extends TableDefine>(model: T, list: object[], skip?: Skip): Action<TableValue<T>[]>;
2076
+ declare function export_default$g<T extends TableDefine>(model: T, value: object, skip?: Skip): Action<T extends Build<infer R> ? R : TableValue<T>>;
2077
+ declare function export_default$g<T extends TableDefine>(model: T, p: object | object[], skip?: Skip): Action<TableValue<T>[] | (T extends Build<infer R> ? R : TableValue<T>)>;
2078
+
2079
+ declare function export_default$f({ table, connect, fields }: TableDefine, where?: Wheres | null): Action<number>;
2080
+
2081
+ declare function export_default$e({ table, connect, fields }: TableDefine, returning?: string[] | null, where?: Wheres | null): Action<any[]>;
2082
+
2083
+ declare function export_default$d(queryable: Queryable, update?: Record<string, SetValue> | boolean): Action<number>;
2084
+
2085
+ declare function export_default$c<T extends Destroy & PseudoDestroy>(tableDef: TableDefine, data: T, update?: Record<string, any> | boolean): Action<T | null>;
2086
+ declare function export_default$c<T extends Destroy & PseudoDestroy>(tableDef: TableDefine, data: any, update?: Record<string, any> | boolean): Action<T | object | null>;
2087
+ declare function export_default$c(tableDef: TableDefine, data: any, update?: Record<string, any> | boolean): Action<object | null>;
2088
+
2089
+ declare function export_default$b<T extends TableDefine>(sql: T, skip?: Skip): Action<T extends Build<infer R> ? R[] : T extends TableDefine<infer F> ? FieldValue<F>[] : never>;
2090
+
2091
+ declare function export_default$a<T extends TableDefine>(sql: T, skip?: Skip): Action<T extends Build<infer R> ? R : T extends TableDefine<infer F> ? FieldValue<F> : never>;
2092
+
2093
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T[], ignoreConflict?: boolean): Action<T[]>;
2094
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T, ignoreConflict?: boolean): Action<T>;
2095
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T | T[], ignoreConflict?: boolean): Action<T | T[]>;
2096
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T[], keys?: string[], ignoreConflict?: boolean): Action<T[]>;
2097
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T, keys?: string[], ignoreConflict?: boolean): Action<T>;
2098
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T | T[], keys?: string[], ignoreConflict?: boolean): Action<T | T[]>;
2099
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T[], keys?: string[] | boolean, ignoreConflict?: boolean): Action<T[]>;
2100
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T, keys?: string[] | boolean, ignoreConflict?: boolean): Action<T>;
2101
+ declare function export_default$9<T extends object>(tableDefine: TableDefine, data: T | T[], keys?: string[] | boolean, ignoreConflict?: boolean): Action<T | T[]>;
2102
+
2103
+ declare function export_default$8<T>(tableDef: TableDefine, data: T, value: Record<string, SetValue>): Action<(T extends PseudoDestroy ? T : object) | null>;
2104
+
2105
+ declare function export_default$7<T>(model: TableDefine, data: T, newData?: Record<string, any> | null, skip?: Skip): Action<(T extends Save ? T : object) | null>;
2106
+
2107
+ declare function export_default$6<T extends TableDefine>(sql: T, fields: string[], skip?: Skip): Action<T extends TableDefine<infer F> ? FieldValue<F>[] : never>;
2108
+
2109
+ declare function export_default$5(queryable: Queryable): Action<any[]>;
2110
+
2111
+ declare function export_default$4({ table, connect, fields }: TableDefine, pKeys: string[], setKeys: string[], list: Record<string, any>[], skip?: Skip | boolean): Action<number>;
2112
+
2113
+ declare function export_default$3({ table, connect, fields }: TableDefine, pKeys: string[], setKeys: string[], list: Record<string, any>[], returning?: string[] | null, skip?: Skip | boolean): Action<any[]>;
2114
+
2115
+ declare function export_default$2({ table, connect, fields }: TableDefine, update: Record<string, any>, where?: Wheres | null, skip?: Skip | boolean): Action<number>;
2116
+
2117
+ declare function export_default$1<T extends Fields<MainFieldType>>({ table, connect, fields }: TableDefine<T>, update: Record<string, any>, returning?: string[] | null, where?: Wheres | null, skip?: Skip | boolean): Action<any[]>;
2118
+
2119
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T[], conflictSet?: Record<string, SetValue>): Action<T[]>;
2120
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T, conflictSet?: Record<string, SetValue>): Action<T>;
2121
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T | T[], conflictSet?: Record<string, SetValue>): Action<T | T[]>;
2122
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T[], keys?: null | string[], conflictSet?: Record<string, SetValue>): Action<T[]>;
2123
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T, keys?: null | string[], conflictSet?: Record<string, SetValue>): Action<T>;
2124
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T | T[], keys?: null | string[], conflictSet?: Record<string, SetValue>): Action<T | T[]>;
2125
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T[], keys?: null | string[], conflictKeys?: string[] | boolean, conflictSet?: Record<string, SetValue>): Action<T[]>;
2126
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T, keys?: null | string[], conflictKeys?: string[] | boolean, conflictSet?: Record<string, SetValue>): Action<T>;
2127
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T | T[], keys?: null | string[], conflictKeys?: string[] | boolean, conflictSet?: Record<string, SetValue>): Action<T | T[]>;
2128
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T[], keys?: null | string[] | boolean | Record<string, SetValue>, conflictKeys?: string[] | boolean | Record<string, SetValue>, conflictSet?: Record<string, SetValue>): Action<T[]>;
2129
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T, keys?: null | string[] | boolean | Record<string, SetValue>, conflictKeys?: string[] | boolean | Record<string, SetValue>, conflictSet?: Record<string, SetValue>): Action<T>;
2130
+ declare function export_default<T extends object>(tableDefine: TableDefine, data: T | T[], keys?: null | string[] | boolean | Record<string, SetValue>, conflictKeys?: string[] | boolean | Record<string, SetValue>, conflictSet?: Record<string, SetValue>): Action<T | T[]>;
2131
+
2132
+ declare namespace index_d {
2133
+ export {
2134
+ export_default$i as completelyDestroy,
2135
+ export_default$h as count,
2136
+ export_default$g as create,
2137
+ export_default$f as delete,
2138
+ export_default$e as deleteReturn,
2139
+ export_default$c as destroy,
2140
+ export_default$d as destroyMany,
2141
+ export_default$b as find,
2142
+ export_default$a as first,
2143
+ export_default$9 as insert,
2144
+ export_default$8 as pseudoDestroy,
2145
+ export_default$7 as save,
2146
+ export_default$6 as search,
2147
+ export_default$5 as select,
2148
+ export_default$2 as update,
2149
+ export_default$4 as updateList,
2150
+ export_default$3 as updateListReturn,
2151
+ export_default$1 as updateReturn,
2152
+ export_default as upsert,
2153
+ };
2154
+ }
2155
+
2403
2156
  /**
2404
2157
  * @typedef {object} Scene.Define
2405
2158
  * @property {string} table
@@ -2814,4 +2567,5 @@ declare function toBool(v: any): boolean;
2814
2567
  declare function setDevelopment(d?: boolean): void;
2815
2568
  declare let isDevelopment: boolean;
2816
2569
 
2817
- export { Build, CheckViolationError, type ClassDecorator, type Column, type ColumnOptions, Connection, ConnectionError, type Constraint, Create, type DBColumn, type DBIndex, type DBTable, Destroy, type Environment, type FieldDecorator, type FieldDefine, type FieldDefineOption, type FieldDefineType, type FieldSpecific, type FieldSpecificValue, type FieldType, type FieldTypeDefine, type FieldValue, type Fields, type FindArg, type FindRange, ForeignKeyViolationError, type GetName, type Hook, type Hooks, type IConnection, type Index, type IndexInfo, type IndexOptions, InvalidInputSyntaxError, type JOIN, type Join, type JoinType, type LockType, type MainFieldType, type MaybePromise, type MethodDecorator, Model, NotNullViolationError, OperatorMismatchError, type Options, PseudoDestroy, Query, type QueryOptions, type Queryable, Save, Scene, Select, type SelectItem, SetValue, type Skip, Submodel, type Support, type TableConnect, type TableConnection, type TableDefine, type TableType, type TableValue, type ToFieldType, type ToType, type TransactionFn, type TransactionHandler, type TransactionHandlerArray, UniqueViolationError, type VirtualTable, Where, type WhereExists, type WhereItem, type WhereLike, type WhereOr, type WhereRaw, type WhereValue, type Wheres, afterCreate, afterCreateMany, afterDelete, afterUpdate, beforeCreate, beforeCreateMany, beforeDelete, beforeUpdate, bindHooks, coefficient, column, creating, decrement, defaultValue, field as define, deleted, deleting, divide, field$1 as field, getPrimaryFields, getPrimaryKeys, hooks, immutable, increment, index, isDevelopment, isPseudo, mergeHooks, model, multiply, now, primary, prop, pseudo, setDevelopment, sort, model as submodel, toBool, toNot, toPrimaries, toPrimary, uncreatable, undeleted, updating, uuid, values, where, withDeleted };
2570
+ export { Build, CheckViolationError, Connection, ConnectionError, Create, Destroy, ForeignKeyViolationError, InvalidInputSyntaxError, Model, NotNullViolationError, OperatorMismatchError, PseudoDestroy, Query, Save, Scene, Select, SetValue, Submodel, UniqueViolationError, Where, index_d as actions, afterCreate, afterCreateMany, afterDelete, afterUpdate, beforeCreate, beforeCreateMany, beforeDelete, beforeUpdate, bindHooks, coefficient, column, export_default$i as completelyDestroy, export_default$h as count, export_default$g as create, creating, decrement, defaultValue, field as define, export_default$f as delete, export_default$e as deleteReturn, deleted, deleting, export_default$c as destroy, export_default$d as destroyMany, divide, field$1 as field, export_default$b as find, export_default$a as first, getPrimaryFields, getPrimaryKeys, hooks, immutable, increment, index, export_default$9 as insert, isDevelopment, isPseudo, mergeHooks, model, multiply, now, primary, prop, pseudo, export_default$8 as pseudoDestroy, export_default$7 as save, export_default$6 as search, export_default$5 as select, setDevelopment, sort, model as submodel, toBool, toNot, toPrimaries, toPrimary, uncreatable, undeleted, export_default$2 as update, export_default$4 as updateList, export_default$3 as updateListReturn, export_default$1 as updateReturn, updating, export_default as upsert, uuid, values, where, withDeleted };
2571
+ export type { Action, BaseEnvironment, ClassDecorator, Column, ColumnOptions, ConnectionInterface, Constraint, DBColumn, DBIndex, DBTable, Environment, FieldDecorator, FieldDefine, FieldDefineOption, FieldDefineType, FieldSpecific, FieldSpecificValue, FieldType, FieldTypeDefine, FieldValue, Fields, FindArg, FindRange, GetName, Hook, Hooks, IConnection, IDBTable, Index, IndexInfo, IndexOptions, JOIN, Join, JoinType, LockType, MainFieldType, MaybePromise, MethodDecorator, Options, QueryOptions, Queryable, Savepoint, SelectItem, Skip, Support, TableConnect, TableConnection, TableDefine, TableType, TableValue, ToFieldType, ToType, TransactionFn, TransactionHandler, TransactionHandlerArray, WhereExists, WhereItem, WhereLike, WhereOr, WhereRaw, WhereValue, Wheres };