1 | import IndexHints = require('./index-hints');
|
2 | import { Association, BelongsTo, BelongsToMany, BelongsToManyOptions, BelongsToOptions, HasMany, HasManyOptions, HasOne, HasOneOptions } from './associations/index';
|
3 | import { DataType } from './data-types';
|
4 | import { Deferrable } from './deferrable';
|
5 | import { HookReturn, Hooks, ModelHooks } from './hooks';
|
6 | import { ValidationOptions } from './instance-validator';
|
7 | import { IndexesOptions, QueryOptions, TableName } from './dialects/abstract/query-interface';
|
8 | import { Sequelize, SyncOptions } from './sequelize';
|
9 | import { Col, Fn, Literal, Where, MakeNullishOptional, AnyFunction, Cast, Json } from './utils';
|
10 | import { LOCK, Transaction, Op, Optional } from './index';
|
11 | import { SetRequired } from './utils/set-required';
|
12 |
|
13 |
|
14 | export type AllowReadonlyArray<T> = T | readonly T[];
|
15 |
|
16 | export interface Logging {
|
17 | |
18 |
|
19 |
|
20 | logging?: boolean | ((sql: string, timing?: number) => void);
|
21 |
|
22 | /**
|
23 | * Pass query execution time in milliseconds as second argument to logging function (options.logging).
|
24 | */
|
25 | benchmark?: boolean;
|
26 | }
|
27 |
|
28 | export interface Poolable {
|
29 | /**
|
30 | * Force the query to use the write pool, regardless of the query type.
|
31 | *
|
32 | * @default false
|
33 | */
|
34 | useMaster?: boolean;
|
35 | }
|
36 |
|
37 | export interface Transactionable {
|
38 | /**
|
39 | * Transaction to run query under
|
40 | */
|
41 | transaction?: Transaction | null;
|
42 | }
|
43 |
|
44 | export interface SearchPathable {
|
45 | /**
|
46 | * An optional parameter to specify the schema search_path (Postgres only)
|
47 | */
|
48 | searchPath?: string;
|
49 | }
|
50 |
|
51 | export interface Filterable<TAttributes = any> {
|
52 | /**
|
53 | * Attribute has to be matched for rows to be selected for the given action.
|
54 | */
|
55 | where?: WhereOptions<TAttributes>;
|
56 | }
|
57 |
|
58 | export interface Projectable {
|
59 | /**
|
60 | * A list of the attributes that you want to select. To rename an attribute, you can pass an array, with
|
61 | * two elements - the first is the name of the attribute in the DB (or some kind of expression such as
|
62 | * `Sequelize.literal`, `Sequelize.fn` and so on), and the second is the name you want the attribute to
|
63 | * have in the returned instance
|
64 | */
|
65 | attributes?: FindAttributeOptions;
|
66 | }
|
67 |
|
68 | export interface Paranoid {
|
69 | /**
|
70 | * If true, only non-deleted records will be returned. If false, both deleted and non-deleted records will
|
71 | * be returned. Only applies if `options.paranoid` is true for the model.
|
72 | */
|
73 | paranoid?: boolean;
|
74 | }
|
75 |
|
76 | export type GroupOption = string | Fn | Col | (string | Fn | Col)[];
|
77 |
|
78 | /**
|
79 | * Options to pass to Model on drop
|
80 | */
|
81 | export interface DropOptions extends Logging {
|
82 | /**
|
83 | * Also drop all objects depending on this table, such as views. Only works in postgres
|
84 | */
|
85 | cascade?: boolean;
|
86 | }
|
87 |
|
88 | /**
|
89 | * Schema Options provided for applying a schema to a model
|
90 | */
|
91 | export interface SchemaOptions extends Logging {
|
92 | /**
|
93 | * The character(s) that separates the schema name from the table name
|
94 | */
|
95 | schemaDelimiter?: string;
|
96 | }
|
97 |
|
98 | /**
|
99 | * Scope Options for Model.scope
|
100 | */
|
101 | export interface ScopeOptions {
|
102 | /**
|
103 | * The scope(s) to apply. Scopes can either be passed as consecutive arguments, or as an array of arguments.
|
104 | * To apply simple scopes and scope functions with no arguments, pass them as strings. For scope function,
|
105 | * pass an object, with a `method` property. The value can either be a string, if the method does not take
|
106 | * any arguments, or an array, where the first element is the name of the method, and consecutive elements
|
107 | * are arguments to that method. Pass null to remove all scopes, including the default.
|
108 | */
|
109 | method: string | readonly [string, ...unknown[]];
|
110 | }
|
111 |
|
112 | type InvalidInSqlArray = ColumnReference | Fn | Cast | null | Literal;
|
113 |
|
114 | /**
|
115 | * This type allows using `Op.or`, `Op.and`, and `Op.not` recursively around another type.
|
116 | * It also supports using a plain Array as an alias for `Op.and`. (unlike {@link AllowNotOrAndRecursive}).
|
117 | *
|
118 | * Example of plain-array treated as `Op.and`:
|
119 | * User.findAll({ where: [{ id: 1 }, { id: 2 }] });
|
120 | *
|
121 | * Meant to be used by {@link WhereOptions}.
|
122 | */
|
123 | type AllowNotOrAndWithImplicitAndArrayRecursive<T> = AllowArray<
|
124 | // this is the equivalent of Op.and
|
125 | | T
|
126 | | { [Op.or]: AllowArray<AllowNotOrAndWithImplicitAndArrayRecursive<T>> }
|
127 | | { [Op.and]: AllowArray<AllowNotOrAndWithImplicitAndArrayRecursive<T>> }
|
128 | | { [Op.not]: AllowNotOrAndWithImplicitAndArrayRecursive<T> }
|
129 | >;
|
130 |
|
131 | /**
|
132 | * This type allows using `Op.or`, `Op.and`, and `Op.not` recursively around another type.
|
133 | * Unlike {@link AllowNotOrAndWithImplicitAndArrayRecursive}, it does not allow the 'implicit AND Array'.
|
134 | *
|
135 | * Example of plain-array NOT treated as Op.and:
|
136 | * User.findAll({ where: { id: [1, 2] } });
|
137 | *
|
138 | * Meant to be used by {@link WhereAttributeHashValue}.
|
139 | */
|
140 | type AllowNotOrAndRecursive<T> =
|
141 | | T
|
142 | | { [Op.or]: AllowArray<AllowNotOrAndRecursive<T>> }
|
143 | | { [Op.and]: AllowArray<AllowNotOrAndRecursive<T>> }
|
144 | | { [Op.not]: AllowNotOrAndRecursive<T> };
|
145 |
|
146 | type AllowArray<T> = T | T[];
|
147 | type AllowAnyAll<T> =
|
148 | | T
|
149 | // Op.all: [x, z] results in ALL (ARRAY[x, z])
|
150 | // Some things cannot go in ARRAY. Op.values must be used to support them.
|
151 | | { [Op.all]: Exclude<T, InvalidInSqlArray>[] | Literal | { [Op.values]: Array<T | DynamicValues<T>> } }
|
152 | | { [Op.any]: Exclude<T, InvalidInSqlArray>[] | Literal | { [Op.values]: Array<T | DynamicValues<T>> } };
|
153 |
|
154 | /**
|
155 | * The type accepted by every `where` option
|
156 | */
|
157 | export type WhereOptions<TAttributes = any> = AllowNotOrAndWithImplicitAndArrayRecursive<
|
158 | | WhereAttributeHash<TAttributes>
|
159 | | Literal
|
160 | | Fn
|
161 | | Where
|
162 | | Json
|
163 | >;
|
164 |
|
165 | /**
|
166 | * @deprecated unused
|
167 | */
|
168 | export interface AnyOperator {
|
169 | [Op.any]: readonly (string | number | Date | Literal)[] | Literal;
|
170 | }
|
171 |
|
172 | /** @deprecated unused */
|
173 | export interface AllOperator {
|
174 | [Op.all]: readonly (string | number | Date | Literal)[] | Literal;
|
175 | }
|
176 |
|
177 | // number is always allowed because -Infinity & +Infinity are valid
|
178 | export type Rangable<T> = readonly [
|
179 | lower: T | RangePart<T | number> | number | null,
|
180 | higher: T | RangePart<T | number> | number | null
|
181 | ] | EmptyRange;
|
182 |
|
183 | /**
|
184 | * This type represents the output of the {@link RANGE} data type.
|
185 | */
|
186 | // number is always allowed because -Infinity & +Infinity are valid
|
187 | export type Range<T> = readonly [lower: RangePart<T | number>, higher: RangePart<T | number>] | EmptyRange;
|
188 |
|
189 | type EmptyRange = [];
|
190 |
|
191 | type RangePart<T> = { value: T, inclusive: boolean };
|
192 |
|
193 | /**
|
194 | * Internal type - prone to changes. Do not export.
|
195 | * @private
|
196 | */
|
197 | export type ColumnReference = Col | { [Op.col]: string };
|
198 |
|
199 | /**
|
200 | * Internal type - prone to changes. Do not export.
|
201 | * @private
|
202 | */
|
203 | type WhereSerializableValue = boolean | string | number | Buffer | Date;
|
204 |
|
205 | /**
|
206 | * Internal type - prone to changes. Do not export.
|
207 | * @private
|
208 | */
|
209 | type OperatorValues<AcceptableValues> =
|
210 | | StaticValues<AcceptableValues>
|
211 | | DynamicValues<AcceptableValues>;
|
212 |
|
213 | /**
|
214 | * Represents acceptable Dynamic values.
|
215 | *
|
216 | * Dynamic values, as opposed to {@link StaticValues}. i.e. column references, functions, etc...
|
217 | */
|
218 | type DynamicValues<AcceptableValues> =
|
219 | | Literal
|
220 | | ColumnReference
|
221 | | Fn
|
222 | | Cast
|
223 | // where() can only be used on boolean attributes
|
224 | | (AcceptableValues extends boolean ? Where : never)
|
225 |
|
226 | /**
|
227 | * Represents acceptable Static values.
|
228 | *
|
229 | * Static values, as opposed to {@link DynamicValues}. i.e. booleans, strings, etc...
|
230 | */
|
231 | type StaticValues<Type> =
|
232 | Type extends Range<infer RangeType> ? [lower: RangeType | RangePart<RangeType>, higher: RangeType | RangePart<RangeType>]
|
233 | : Type extends any[] ? { readonly [Key in keyof Type]: StaticValues<Type[Key]>}
|
234 | : Type extends null ? Type | WhereSerializableValue | null
|
235 | : Type | WhereSerializableValue;
|
236 |
|
237 | /**
|
238 | * Operators that can be used in {@link WhereOptions}
|
239 | *
|
240 | * @typeParam AttributeType - The JS type of the attribute the operator is operating on.
|
241 | *
|
242 | * See https://sequelize.org/master/en/v3/docs/querying/#operators
|
243 | */
|
244 | // TODO: default to something more strict than `any` which lists serializable values
|
245 | export interface WhereOperators<AttributeType = any> {
|
246 | /**
|
247 | * @example: `[Op.eq]: 6,` becomes `= 6`
|
248 | * @example: `[Op.eq]: [6, 7]` becomes `= ARRAY[6, 7]`
|
249 | * @example: `[Op.eq]: null` becomes `IS NULL`
|
250 | * @example: `[Op.eq]: true` becomes `= true`
|
251 | * @example: `[Op.eq]: literal('raw sql')` becomes `= raw sql`
|
252 | * @example: `[Op.eq]: col('column')` becomes `= "column"`
|
253 | * @example: `[Op.eq]: fn('NOW')` becomes `= NOW()`
|
254 | */
|
255 | [Op.eq]?: AllowAnyAll<OperatorValues<AttributeType>>;
|
256 |
|
257 | /**
|
258 | * @example: `[Op.ne]: 20,` becomes `!= 20`
|
259 | * @example: `[Op.ne]: [20, 21]` becomes `!= ARRAY[20, 21]`
|
260 | * @example: `[Op.ne]: null` becomes `IS NOT NULL`
|
261 | * @example: `[Op.ne]: true` becomes `!= true`
|
262 | * @example: `[Op.ne]: literal('raw sql')` becomes `!= raw sql`
|
263 | * @example: `[Op.ne]: col('column')` becomes `!= "column"`
|
264 | * @example: `[Op.ne]: fn('NOW')` becomes `!= NOW()`
|
265 | */
|
266 | [Op.ne]?: WhereOperators<AttributeType>[typeof Op.eq]; // accepts the same types as Op.eq
|
267 |
|
268 | /**
|
269 | * @example: `[Op.is]: null` becomes `IS NULL`
|
270 | * @example: `[Op.is]: true` becomes `IS TRUE`
|
271 | * @example: `[Op.is]: literal('value')` becomes `IS value`
|
272 | */
|
273 | [Op.is]?: Extract<AttributeType, null | boolean> | Literal;
|
274 |
|
275 | /**
|
276 | * @example: `[Op.not]: true` becomes `IS NOT TRUE`
|
277 | * @example: `{ col: { [Op.not]: { [Op.gt]: 5 } } }` becomes `NOT (col > 5)`
|
278 | */
|
279 | [Op.not]?: WhereOperators<AttributeType>[typeof Op.eq]; // accepts the same types as Op.eq ('Op.not' is not strictly the opposite of 'Op.is' due to legacy reasons)
|
280 |
|
281 | /** @example: `[Op.gte]: 6` becomes `>= 6` */
|
282 | [Op.gte]?: AllowAnyAll<OperatorValues<NonNullable<AttributeType>>>;
|
283 |
|
284 | /** @example: `[Op.lte]: 10` becomes `<= 10` */
|
285 | [Op.lte]?: WhereOperators<AttributeType>[typeof Op.gte]; // accepts the same types as Op.gte
|
286 |
|
287 | /** @example: `[Op.lt]: 10` becomes `< 10` */
|
288 | [Op.lt]?: WhereOperators<AttributeType>[typeof Op.gte]; // accepts the same types as Op.gte
|
289 |
|
290 | /** @example: `[Op.gt]: 6` becomes `> 6` */
|
291 | [Op.gt]?: WhereOperators<AttributeType>[typeof Op.gte]; // accepts the same types as Op.gte
|
292 |
|
293 | /**
|
294 | * @example: `[Op.between]: [6, 10],` becomes `BETWEEN 6 AND 10`
|
295 | */
|
296 | [Op.between]?:
|
297 | | [
|
298 | lowerInclusive: OperatorValues<NonNullable<AttributeType>>,
|
299 | higherInclusive: OperatorValues<NonNullable<AttributeType>>,
|
300 | ]
|
301 | | Literal;
|
302 |
|
303 | /** @example: `[Op.notBetween]: [11, 15],` becomes `NOT BETWEEN 11 AND 15` */
|
304 | [Op.notBetween]?: WhereOperators<AttributeType>[typeof Op.between];
|
305 |
|
306 | /** @example: `[Op.in]: [1, 2],` becomes `IN (1, 2)` */
|
307 | [Op.in]?: ReadonlyArray<OperatorValues<NonNullable<AttributeType>>> | Literal;
|
308 |
|
309 | /** @example: `[Op.notIn]: [1, 2],` becomes `NOT IN (1, 2)` */
|
310 | [Op.notIn]?: WhereOperators<AttributeType>[typeof Op.in];
|
311 |
|
312 | /**
|
313 | * @example: `[Op.like]: '%hat',` becomes `LIKE '%hat'`
|
314 | * @example: `[Op.like]: { [Op.any]: ['cat', 'hat'] }` becomes `LIKE ANY ARRAY['cat', 'hat']`
|
315 | */
|
316 | [Op.like]?: AllowAnyAll<OperatorValues<Extract<AttributeType, string>>>;
|
317 |
|
318 | /**
|
319 | * @example: `[Op.notLike]: '%hat'` becomes `NOT LIKE '%hat'`
|
320 | * @example: `[Op.notLike]: { [Op.any]: ['cat', 'hat']}` becomes `NOT LIKE ANY ARRAY['cat', 'hat']`
|
321 | */
|
322 | [Op.notLike]?: WhereOperators<AttributeType>[typeof Op.like];
|
323 |
|
324 | /**
|
325 | * case insensitive PG only
|
326 | *
|
327 | * @example: `[Op.iLike]: '%hat'` becomes `ILIKE '%hat'`
|
328 | * @example: `[Op.iLike]: { [Op.any]: ['cat', 'hat']}` becomes `ILIKE ANY ARRAY['cat', 'hat']`
|
329 | */
|
330 | [Op.iLike]?: WhereOperators<AttributeType>[typeof Op.like];
|
331 |
|
332 | /**
|
333 | * PG only
|
334 | *
|
335 | * @example: `[Op.notILike]: '%hat'` becomes `NOT ILIKE '%hat'`
|
336 | * @example: `[Op.notLike]: ['cat', 'hat']` becomes `LIKE ANY ARRAY['cat', 'hat']`
|
337 | */
|
338 | [Op.notILike]?: WhereOperators<AttributeType>[typeof Op.like];
|
339 |
|
340 | /**
|
341 | * PG array & range 'overlaps' operator
|
342 | *
|
343 | * @example: `[Op.overlap]: [1, 2]` becomes `&& [1, 2]`
|
344 | */
|
345 | // https://www.postgresql.org/docs/14/functions-range.html range && range
|
346 | // https://www.postgresql.org/docs/14/functions-array.html array && array
|
347 | [Op.overlap]?: AllowAnyAll<
|
348 | | (
|
349 |
|
350 | AttributeType extends Range<infer RangeType> ? Rangable<RangeType>
|
351 |
|
352 | : AttributeType extends any[] ? StaticValues<NonNullable<AttributeType>>
|
353 | : never
|
354 | )
|
355 | | DynamicValues<AttributeType>
|
356 | >;
|
357 |
|
358 | /**
|
359 | * PG array & range 'contains' operator
|
360 | *
|
361 | * @example: `[Op.contains]: [1, 2]` becomes `@> [1, 2]`
|
362 | */
|
363 | // https://www.postgresql.org/docs/14/functions-json.html jsonb @> jsonb
|
364 | // https://www.postgresql.org/docs/14/functions-range.html range @> range ; range @> element
|
365 | // https://www.postgresql.org/docs/14/functions-array.html array @> array
|
366 | [Op.contains]?:
|
367 | // RANGE @> ELEMENT
|
368 | | AttributeType extends Range<infer RangeType> ? OperatorValues<OperatorValues<NonNullable<RangeType>>> : never
|
369 | // ARRAY @> ARRAY ; RANGE @> RANGE
|
370 | | WhereOperators<AttributeType>[typeof Op.overlap];
|
371 |
|
372 | /**
|
373 | * PG array & range 'contained by' operator
|
374 | *
|
375 | * @example: `[Op.contained]: [1, 2]` becomes `<@ [1, 2]`
|
376 | */
|
377 | [Op.contained]?:
|
378 | AttributeType extends any[]
|
379 | // ARRAY <@ ARRAY ; RANGE <@ RANGE
|
380 | ? WhereOperators<AttributeType>[typeof Op.overlap]
|
381 | // ELEMENT <@ RANGE
|
382 | : AllowAnyAll<OperatorValues<Rangable<AttributeType>>>;
|
383 |
|
384 | /**
|
385 | * Strings starts with value.
|
386 | */
|
387 | [Op.startsWith]?: OperatorValues<Extract<AttributeType, string>>;
|
388 |
|
389 | /**
|
390 | * String ends with value.
|
391 | */
|
392 | [Op.endsWith]?: WhereOperators<AttributeType>[typeof Op.startsWith];
|
393 | /**
|
394 | * String contains value.
|
395 | */
|
396 | [Op.substring]?: WhereOperators<AttributeType>[typeof Op.startsWith];
|
397 |
|
398 | /**
|
399 | * MySQL/PG only
|
400 | *
|
401 | * Matches regular expression, case sensitive
|
402 | *
|
403 | * @example: `[Op.regexp]: '^[h|a|t]'` becomes `REGEXP/~ '^[h|a|t]'`
|
404 | */
|
405 | [Op.regexp]?: AllowAnyAll<OperatorValues<Extract<AttributeType, string>>>;
|
406 |
|
407 | /**
|
408 | * MySQL/PG only
|
409 | *
|
410 | * Does not match regular expression, case sensitive
|
411 | *
|
412 | * @example: `[Op.notRegexp]: '^[h|a|t]'` becomes `NOT REGEXP/!~ '^[h|a|t]'`
|
413 | */
|
414 | [Op.notRegexp]?: WhereOperators<AttributeType>[typeof Op.regexp];
|
415 |
|
416 | /**
|
417 | * PG only
|
418 | *
|
419 | * Matches regular expression, case insensitive
|
420 | *
|
421 | * @example: `[Op.iRegexp]: '^[h|a|t]'` becomes `~* '^[h|a|t]'`
|
422 | */
|
423 | [Op.iRegexp]?: WhereOperators<AttributeType>[typeof Op.regexp];
|
424 |
|
425 | /**
|
426 | * PG only
|
427 | *
|
428 | * Does not match regular expression, case insensitive
|
429 | *
|
430 | * @example: `[Op.notIRegexp]: '^[h|a|t]'` becomes `!~* '^[h|a|t]'`
|
431 | */
|
432 | [Op.notIRegexp]?: WhereOperators<AttributeType>[typeof Op.regexp];
|
433 |
|
434 | /** @example: `[Op.match]: Sequelize.fn('to_tsquery', 'fat & rat')` becomes `@@ to_tsquery('fat & rat')` */
|
435 | [Op.match]?: AllowAnyAll<DynamicValues<AttributeType>>;
|
436 |
|
437 | /**
|
438 | * PG only
|
439 | *
|
440 | * Whether the range is strictly left of the other range.
|
441 | *
|
442 | * @example:
|
443 | * ```typescript
|
444 | * { rangeAttribute: { [Op.strictLeft]: [1, 2] } }
|
445 | * // results in
|
446 | * // "rangeAttribute" << [1, 2)
|
447 | * ```
|
448 | *
|
449 | * https://www.postgresql.org/docs/14/functions-range.html
|
450 | */
|
451 | [Op.strictLeft]?:
|
452 | | AttributeType extends Range<infer RangeType> ? Rangable<RangeType> : never
|
453 | | DynamicValues<AttributeType>;
|
454 |
|
455 | /**
|
456 | * PG only
|
457 | *
|
458 | * Whether the range is strictly right of the other range.
|
459 | *
|
460 | * @example:
|
461 | * ```typescript
|
462 | * { rangeAttribute: { [Op.strictRight]: [1, 2] } }
|
463 | * // results in
|
464 | * // "rangeAttribute" >> [1, 2)
|
465 | * ```
|
466 | *
|
467 | * https://www.postgresql.org/docs/14/functions-range.html
|
468 | */
|
469 | [Op.strictRight]?: WhereOperators<AttributeType>[typeof Op.strictLeft];
|
470 |
|
471 | /**
|
472 | * PG only
|
473 | *
|
474 | * Whether the range extends to the left of the other range.
|
475 | *
|
476 | * @example:
|
477 | * ```typescript
|
478 | * { rangeAttribute: { [Op.noExtendLeft]: [1, 2] } }
|
479 | * // results in
|
480 | * // "rangeAttribute" &> [1, 2)
|
481 | * ```
|
482 | *
|
483 | * https://www.postgresql.org/docs/14/functions-range.html
|
484 | */
|
485 | [Op.noExtendLeft]?: WhereOperators<AttributeType>[typeof Op.strictLeft];
|
486 |
|
487 | /**
|
488 | * PG only
|
489 | *
|
490 | * Whether the range extends to the right of the other range.
|
491 | *
|
492 | * @example:
|
493 | * ```typescript
|
494 | * { rangeAttribute: { [Op.noExtendRight]: [1, 2] } }
|
495 | * // results in
|
496 | * // "rangeAttribute" &< [1, 2)
|
497 | * ```
|
498 | *
|
499 | * https://www.postgresql.org/docs/14/functions-range.html
|
500 | */
|
501 | [Op.noExtendRight]?: WhereOperators<AttributeType>[typeof Op.strictLeft];
|
502 |
|
503 | /**
|
504 | * PG only
|
505 | *
|
506 | * Whether the two ranges are adjacent.
|
507 | *
|
508 | * @example:
|
509 | * ```typescript
|
510 | * { rangeAttribute: { [Op.adjacent]: [1, 2] } }
|
511 | * // results in
|
512 | * // "rangeAttribute" -|- [1, 2)
|
513 | * ```
|
514 | *
|
515 | * https://www.postgresql.org/docs/14/functions-range.html
|
516 | */
|
517 | [Op.adjacent]?: WhereOperators<AttributeType>[typeof Op.strictLeft];
|
518 | }
|
519 |
|
520 | /**
|
521 | * Example: `[Op.or]: [{a: 5}, {a: 6}]` becomes `(a = 5 OR a = 6)`
|
522 | *
|
523 | * @deprecated do not use me!
|
524 | */
|
525 | // TODO [>6]: Remove me
|
526 | export interface OrOperator<TAttributes = any> {
|
527 | [Op.or]: WhereOptions<TAttributes> | readonly WhereOptions<TAttributes>[] | WhereValue<TAttributes> | readonly WhereValue<TAttributes>[];
|
528 | }
|
529 |
|
530 | /**
|
531 | * Example: `[Op.and]: {a: 5}` becomes `AND (a = 5)`
|
532 | *
|
533 | * @deprecated do not use me!
|
534 | */
|
535 | // TODO [>6]: Remove me
|
536 | export interface AndOperator<TAttributes = any> {
|
537 | [Op.and]: WhereOptions<TAttributes> | readonly WhereOptions<TAttributes>[] | WhereValue<TAttributes> | readonly WhereValue<TAttributes>[];
|
538 | }
|
539 |
|
540 | /**
|
541 | * Where Geometry Options
|
542 | */
|
543 | export interface WhereGeometryOptions {
|
544 | type: string;
|
545 | coordinates: readonly (number[] | number)[];
|
546 | }
|
547 |
|
548 | /**
|
549 | * Used for the right hand side of WhereAttributeHash.
|
550 | * WhereAttributeHash is in there for JSON columns.
|
551 | *
|
552 | * @deprecated do not use me
|
553 | */
|
554 | // TODO [>6]: remove this
|
555 | export type WhereValue<TAttributes = any> =
|
556 | | string
|
557 | | number
|
558 | | bigint
|
559 | | boolean
|
560 | | Date
|
561 | | Buffer
|
562 | | null
|
563 | | WhereAttributeHash<any> // for JSON columns
|
564 | | Col // reference another column
|
565 | | Fn
|
566 | | WhereGeometryOptions
|
567 |
|
568 | /**
|
569 | * A hash of attributes to describe your search.
|
570 | *
|
571 | * Possible key values:
|
572 | *
|
573 | * - An attribute name: `{ id: 1 }`
|
574 | * - A nested attribute: `{ '$projects.id$': 1 }`
|
575 | * - A JSON key: `{ 'object.key': 1 }`
|
576 | * - A cast: `{ 'id::integer': 1 }`
|
577 | *
|
578 | * - A combination of the above: `{ '$join.attribute$.json.path::integer': 1 }`
|
579 | */
|
580 | export type WhereAttributeHash<TAttributes = any> = {
|
581 | // support 'attribute' & '$attribute$'
|
582 | [AttributeName in keyof TAttributes as AttributeName extends string ? AttributeName | `$${AttributeName}$` : never]?: WhereAttributeHashValue<TAttributes[AttributeName]>;
|
583 | } & {
|
584 | [AttributeName in keyof TAttributes as AttributeName extends string ?
|
585 | // support 'json.path', '$json$.path'
|
586 | | `${AttributeName}.${string}` | `$${AttributeName}$.${string}`
|
587 | // support 'attribute::cast', '$attribute$::cast', 'json.path::cast' & '$json$.path::cast'
|
588 | | `${AttributeName | `$${AttributeName}$` | `${AttributeName}.${string}` | `$${AttributeName}$.${string}`}::${string}`
|
589 | : never]?: WhereAttributeHashValue<any>;
|
590 | } & {
|
591 | // support '$nested.attribute$', '$nested.attribute$::cast', '$nested.attribute$.json.path', & '$nested.attribute$.json.path::cast'
|
592 | // TODO [2022-05-26]: Remove this ts-ignore once we drop support for TS < 4.4
|
593 | // TypeScript < 4.4 does not support using a Template Literal Type as a key.
|
594 | // note: this *must* be a ts-ignore, as it works in ts >= 4.4
|
595 | // @ts-ignore
|
596 | [attribute: `$${string}.${string}$` | `$${string}.${string}$::${string}` | `$${string}.${string}$.${string}` | `$${string}.${string}$.${string}::${string}`]: WhereAttributeHashValue<any>;
|
597 | }
|
598 |
|
599 | /**
|
600 | * Types that can be compared to an attribute in a WHERE context.
|
601 | */
|
602 | export type WhereAttributeHashValue<AttributeType> =
|
603 | | AllowNotOrAndRecursive<
|
604 | // if the right-hand side is an array, it will be equal to Op.in
|
605 | // otherwise it will be equal to Op.eq
|
606 | // Exception: array attribtues always use Op.eq, never Op.in.
|
607 | | AttributeType extends any[]
|
608 | ? WhereOperators<AttributeType>[typeof Op.eq] | WhereOperators<AttributeType>
|
609 | : (
|
610 | | WhereOperators<AttributeType>[typeof Op.in]
|
611 | | WhereOperators<AttributeType>[typeof Op.eq]
|
612 | | WhereOperators<AttributeType>
|
613 | )
|
614 | >
|
615 | // TODO: this needs a simplified version just for JSON columns
|
616 | | WhereAttributeHash<any> // for JSON columns
|
617 |
|
618 | /**
|
619 | * Through options for Include Options
|
620 | */
|
621 | export interface IncludeThroughOptions extends Filterable<any>, Projectable {
|
622 | /**
|
623 | * The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` /
|
624 | * `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural
|
625 | */
|
626 | as?: string;
|
627 |
|
628 | /**
|
629 | * If true, only non-deleted records will be returned from the join table.
|
630 | * If false, both deleted and non-deleted records will be returned.
|
631 | * Only applies if through model is paranoid.
|
632 | */
|
633 | paranoid?: boolean;
|
634 | }
|
635 |
|
636 | /**
|
637 | * Options for eager-loading associated models, also allowing for all associations to be loaded at once
|
638 | */
|
639 | export type Includeable = ModelType | Association | IncludeOptions | { all: true, nested?: true } | string;
|
640 |
|
641 | /**
|
642 | * Complex include options
|
643 | */
|
644 | export interface IncludeOptions extends Filterable<any>, Projectable, Paranoid {
|
645 | /**
|
646 | * Mark the include as duplicating, will prevent a subquery from being used.
|
647 | */
|
648 | duplicating?: boolean;
|
649 | /**
|
650 | * The model you want to eagerly load
|
651 | */
|
652 | model?: ModelType;
|
653 |
|
654 | /**
|
655 | * The alias of the relation, in case the model you want to eagerly load is aliassed. For `hasOne` /
|
656 | * `belongsTo`, this should be the singular name, and for `hasMany`, it should be the plural
|
657 | */
|
658 | as?: string;
|
659 |
|
660 | /**
|
661 | * The association you want to eagerly load. (This can be used instead of providing a model/as pair)
|
662 | */
|
663 | association?: Association | string;
|
664 |
|
665 | /**
|
666 | * Custom `on` clause, overrides default.
|
667 | */
|
668 | on?: WhereOptions<any>;
|
669 |
|
670 | /**
|
671 | * Note that this converts the eager load to an inner join,
|
672 | * unless you explicitly set `required: false`
|
673 | */
|
674 | where?: WhereOptions<any>;
|
675 |
|
676 | /**
|
677 | * If true, converts to an inner join, which means that the parent model will only be loaded if it has any
|
678 | * matching children. True if `include.where` is set, false otherwise.
|
679 | */
|
680 | required?: boolean;
|
681 |
|
682 | /**
|
683 | * If true, converts to a right join if dialect support it. Ignored if `include.required` is true.
|
684 | */
|
685 | right?: boolean;
|
686 |
|
687 | /**
|
688 | * Limit include. Only available when setting `separate` to true.
|
689 | */
|
690 | limit?: number;
|
691 |
|
692 | /**
|
693 | * Run include in separate queries.
|
694 | */
|
695 | separate?: boolean;
|
696 |
|
697 | /**
|
698 | * Through Options
|
699 | */
|
700 | through?: IncludeThroughOptions;
|
701 |
|
702 | /**
|
703 | * Load further nested related models
|
704 | */
|
705 | include?: Includeable[];
|
706 |
|
707 | /**
|
708 | * Order include. Only available when setting `separate` to true.
|
709 | */
|
710 | order?: Order;
|
711 |
|
712 | /**
|
713 | * Use sub queries. This should only be used if you know for sure the query does not result in a cartesian product.
|
714 | */
|
715 | subQuery?: boolean;
|
716 | }
|
717 |
|
718 | type OrderItemAssociation = Association | ModelStatic<Model> | { model: ModelStatic<Model>; as: string } | string
|
719 | type OrderItemColumn = string | Col | Fn | Literal
|
720 | export type OrderItem =
|
721 | | string
|
722 | | Fn
|
723 | | Col
|
724 | | Literal
|
725 | | [OrderItemColumn, string]
|
726 | | [OrderItemAssociation, OrderItemColumn]
|
727 | | [OrderItemAssociation, OrderItemColumn, string]
|
728 | | [OrderItemAssociation, OrderItemAssociation, OrderItemColumn]
|
729 | | [OrderItemAssociation, OrderItemAssociation, OrderItemColumn, string]
|
730 | | [OrderItemAssociation, OrderItemAssociation, OrderItemAssociation, OrderItemColumn]
|
731 | | [OrderItemAssociation, OrderItemAssociation, OrderItemAssociation, OrderItemColumn, string]
|
732 | | [OrderItemAssociation, OrderItemAssociation, OrderItemAssociation, OrderItemAssociation, OrderItemColumn]
|
733 | | [OrderItemAssociation, OrderItemAssociation, OrderItemAssociation, OrderItemAssociation, OrderItemColumn, string]
|
734 | export type Order = Fn | Col | Literal | OrderItem[];
|
735 |
|
736 | /**
|
737 | * Please note if this is used the aliased property will not be available on the model instance
|
738 | * as a property but only via `instance.get('alias')`.
|
739 | */
|
740 | export type ProjectionAlias = readonly [string | Literal | Fn | Col, string];
|
741 |
|
742 | export type FindAttributeOptions =
|
743 | | (string | ProjectionAlias)[]
|
744 | | {
|
745 | exclude: string[];
|
746 | include?: (string | ProjectionAlias)[];
|
747 | }
|
748 | | {
|
749 | exclude?: string[];
|
750 | include: (string | ProjectionAlias)[];
|
751 | };
|
752 |
|
753 | export interface IndexHint {
|
754 | type: IndexHints;
|
755 | values: string[];
|
756 | }
|
757 |
|
758 | export interface IndexHintable {
|
759 | /**
|
760 | * MySQL only.
|
761 | */
|
762 | indexHints?: IndexHint[];
|
763 | }
|
764 |
|
765 | /**
|
766 | * Options that are passed to any model creating a SELECT query
|
767 | *
|
768 | * A hash of options to describe the scope of the search
|
769 | */
|
770 | export interface FindOptions<TAttributes = any>
|
771 | extends QueryOptions, Filterable<TAttributes>, Projectable, Paranoid, IndexHintable
|
772 | {
|
773 | /**
|
774 | * A list of associations to eagerly load using a left join (a single association is also supported). Supported is either
|
775 | * `{ include: Model1 }`, `{ include: [ Model1, Model2, ...]}`, `{ include: [{ model: Model1, as: 'Alias' }]}` or
|
776 | * `{ include: [{ all: true }]}`.
|
777 | * If your association are set up with an `as` (eg. `X.hasMany(Y, { as: 'Z' }`, you need to specify Z in
|
778 | * the as attribute when eager loading Y).
|
779 | */
|
780 | include?: Includeable | Includeable[];
|
781 |
|
782 | |
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 | order?: Order;
|
789 |
|
790 | |
791 |
|
792 |
|
793 | group?: GroupOption;
|
794 |
|
795 | |
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 | limit?: number;
|
823 |
|
824 |
|
825 | groupedLimit?: unknown;
|
826 |
|
827 | |
828 |
|
829 |
|
830 | offset?: number;
|
831 |
|
832 | |
833 |
|
834 |
|
835 |
|
836 |
|
837 | lock?:
|
838 | | LOCK
|
839 | | { level: LOCK; of: ModelStatic<Model> }
|
840 | | boolean;
|
841 | |
842 |
|
843 |
|
844 | skipLocked?: boolean;
|
845 |
|
846 | |
847 |
|
848 |
|
849 | raw?: boolean;
|
850 |
|
851 | |
852 |
|
853 |
|
854 | having?: WhereOptions<any>;
|
855 |
|
856 | |
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 | subQuery?: boolean;
|
863 | }
|
864 |
|
865 | export interface NonNullFindOptions<TAttributes = any> extends FindOptions<TAttributes> {
|
866 | |
867 |
|
868 |
|
869 | rejectOnEmpty: boolean | Error;
|
870 | }
|
871 |
|
872 |
|
873 |
|
874 |
|
875 | export interface CountOptions<TAttributes = any>
|
876 | extends Logging, Transactionable, Filterable<TAttributes>, Projectable, Paranoid, Poolable
|
877 | {
|
878 | |
879 |
|
880 |
|
881 | include?: Includeable | Includeable[];
|
882 |
|
883 | |
884 |
|
885 |
|
886 | distinct?: boolean;
|
887 |
|
888 | |
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 | group?: GroupOption;
|
895 |
|
896 | |
897 |
|
898 |
|
899 | col?: string;
|
900 | }
|
901 |
|
902 |
|
903 |
|
904 |
|
905 | export type CountWithOptions<TAttributes = any> = SetRequired<CountOptions<TAttributes>, 'group'>
|
906 |
|
907 | export interface FindAndCountOptions<TAttributes = any> extends CountOptions<TAttributes>, FindOptions<TAttributes> { }
|
908 |
|
909 | export interface GroupedCountResultItem {
|
910 | [key: string]: unknown
|
911 | count: number
|
912 | }
|
913 |
|
914 |
|
915 |
|
916 |
|
917 | export interface BuildOptions {
|
918 | |
919 |
|
920 |
|
921 | raw?: boolean;
|
922 |
|
923 | |
924 |
|
925 |
|
926 | isNewRecord?: boolean;
|
927 |
|
928 | |
929 |
|
930 |
|
931 |
|
932 |
|
933 | include?: Includeable | Includeable[];
|
934 | }
|
935 |
|
936 | export interface Silent {
|
937 | |
938 |
|
939 |
|
940 |
|
941 |
|
942 | silent?: boolean;
|
943 | }
|
944 |
|
945 |
|
946 |
|
947 |
|
948 | export interface CreateOptions<TAttributes = any> extends BuildOptions, Logging, Silent, Transactionable, Hookable {
|
949 | |
950 |
|
951 |
|
952 | fields?: (keyof TAttributes)[];
|
953 |
|
954 | |
955 |
|
956 |
|
957 | ignoreDuplicates?: boolean;
|
958 |
|
959 | |
960 |
|
961 |
|
962 | returning?: boolean | (keyof TAttributes)[];
|
963 |
|
964 | |
965 |
|
966 |
|
967 |
|
968 |
|
969 | validate?: boolean;
|
970 |
|
971 | }
|
972 |
|
973 | export interface Hookable {
|
974 |
|
975 | |
976 |
|
977 |
|
978 |
|
979 | hooks?: boolean
|
980 |
|
981 | }
|
982 |
|
983 |
|
984 |
|
985 |
|
986 | export interface FindOrCreateOptions<TAttributes = any, TCreationAttributes = TAttributes>
|
987 | extends FindOptions<TAttributes>, CreateOptions<TAttributes>
|
988 | {
|
989 | |
990 |
|
991 |
|
992 | defaults?: TCreationAttributes;
|
993 | }
|
994 |
|
995 |
|
996 |
|
997 |
|
998 | export interface FindOrBuildOptions<TAttributes = any, TCreationAttributes = TAttributes>
|
999 | extends FindOptions<TAttributes>, BuildOptions
|
1000 | {
|
1001 | |
1002 |
|
1003 |
|
1004 | defaults?: TCreationAttributes;
|
1005 | }
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 | export interface UpsertOptions<TAttributes = any> extends Logging, Transactionable, SearchPathable, Hookable {
|
1011 | |
1012 |
|
1013 |
|
1014 | fields?: (keyof TAttributes)[];
|
1015 |
|
1016 | |
1017 |
|
1018 |
|
1019 | returning?: boolean | (keyof TAttributes)[];
|
1020 |
|
1021 | |
1022 |
|
1023 |
|
1024 | validate?: boolean;
|
1025 | |
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 | conflictWhere?: WhereOptions<TAttributes>;
|
1031 | |
1032 |
|
1033 |
|
1034 |
|
1035 | conflictFields?: (keyof TAttributes)[];
|
1036 | }
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 | export interface BulkCreateOptions<TAttributes = any> extends Logging, Transactionable, Hookable, SearchPathable {
|
1042 | |
1043 |
|
1044 |
|
1045 | fields?: (keyof TAttributes)[];
|
1046 |
|
1047 | |
1048 |
|
1049 |
|
1050 |
|
1051 | validate?: boolean;
|
1052 |
|
1053 | |
1054 |
|
1055 |
|
1056 |
|
1057 | individualHooks?: boolean;
|
1058 |
|
1059 | |
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 | ignoreDuplicates?: boolean;
|
1065 |
|
1066 | |
1067 |
|
1068 |
|
1069 |
|
1070 | updateOnDuplicate?: (keyof TAttributes)[];
|
1071 |
|
1072 | |
1073 |
|
1074 |
|
1075 | include?: Includeable | Includeable[];
|
1076 |
|
1077 | |
1078 |
|
1079 |
|
1080 | returning?: boolean | (keyof TAttributes)[];
|
1081 | |
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 | conflictWhere?: WhereOptions<TAttributes>;
|
1087 | |
1088 |
|
1089 |
|
1090 |
|
1091 | conflictAttributes?: Array<keyof TAttributes>;
|
1092 | }
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 | export interface TruncateOptions<TAttributes = any> extends Logging, Transactionable, Filterable<TAttributes>, Hookable {
|
1098 | |
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 | cascade?: boolean;
|
1105 |
|
1106 | |
1107 |
|
1108 |
|
1109 |
|
1110 | individualHooks?: boolean;
|
1111 |
|
1112 | |
1113 |
|
1114 |
|
1115 | limit?: number;
|
1116 |
|
1117 | |
1118 |
|
1119 |
|
1120 | force?: boolean;
|
1121 |
|
1122 | |
1123 |
|
1124 |
|
1125 |
|
1126 | restartIdentity?: boolean;
|
1127 | }
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 | export interface DestroyOptions<TAttributes = any> extends TruncateOptions<TAttributes> {
|
1133 | |
1134 |
|
1135 |
|
1136 |
|
1137 | truncate?: boolean;
|
1138 | }
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | export interface RestoreOptions<TAttributes = any> extends Logging, Transactionable, Filterable<TAttributes>, Hookable {
|
1144 |
|
1145 | |
1146 |
|
1147 |
|
1148 |
|
1149 | individualHooks?: boolean;
|
1150 |
|
1151 | |
1152 |
|
1153 |
|
1154 | limit?: number;
|
1155 | }
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 | export interface UpdateOptions<TAttributes = any> extends Logging, Transactionable, Paranoid, Hookable {
|
1161 | |
1162 |
|
1163 |
|
1164 | where: WhereOptions<TAttributes>;
|
1165 |
|
1166 | |
1167 |
|
1168 |
|
1169 | fields?: (keyof TAttributes)[];
|
1170 |
|
1171 | |
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 | validate?: boolean;
|
1178 |
|
1179 | |
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 | sideEffects?: boolean;
|
1185 |
|
1186 | |
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 | individualHooks?: boolean;
|
1193 |
|
1194 | |
1195 |
|
1196 |
|
1197 | returning?: boolean | (keyof TAttributes)[];
|
1198 |
|
1199 | |
1200 |
|
1201 |
|
1202 | limit?: number;
|
1203 |
|
1204 | |
1205 |
|
1206 |
|
1207 | silent?: boolean;
|
1208 | }
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 | export interface AggregateOptions<T extends DataType | unknown, TAttributes = any>
|
1214 | extends QueryOptions, Filterable<TAttributes>, Paranoid
|
1215 | {
|
1216 | |
1217 |
|
1218 |
|
1219 |
|
1220 | dataType?: string | T;
|
1221 |
|
1222 | |
1223 |
|
1224 |
|
1225 | distinct?: boolean;
|
1226 | }
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 | export interface IncrementDecrementOptions<TAttributes = any>
|
1234 | extends Logging, Transactionable, Silent, SearchPathable, Filterable<TAttributes> { }
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 | export interface IncrementDecrementOptionsWithBy<TAttributes = any> extends IncrementDecrementOptions<TAttributes> {
|
1240 | |
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 | by?: number;
|
1246 | }
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 | export interface InstanceRestoreOptions extends Logging, Transactionable { }
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 | export interface InstanceDestroyOptions extends Logging, Transactionable, Hookable {
|
1257 | |
1258 |
|
1259 |
|
1260 | force?: boolean;
|
1261 | }
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 | export interface InstanceUpdateOptions<TAttributes = any> extends
|
1267 | SaveOptions<TAttributes>, SetOptions, Filterable<TAttributes> { }
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 | export interface SetOptions {
|
1273 | |
1274 |
|
1275 |
|
1276 | raw?: boolean;
|
1277 |
|
1278 | |
1279 |
|
1280 |
|
1281 | reset?: boolean;
|
1282 | }
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 | export interface SaveOptions<TAttributes = any> extends Logging, Transactionable, Silent, Hookable {
|
1288 | |
1289 |
|
1290 |
|
1291 |
|
1292 | fields?: (keyof TAttributes)[];
|
1293 |
|
1294 | |
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 | validate?: boolean;
|
1300 |
|
1301 | |
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 | omitNull?: boolean;
|
1307 |
|
1308 | |
1309 |
|
1310 |
|
1311 | returning?: boolean | Array<keyof TAttributes>;
|
1312 | }
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 | export interface ModelValidateOptions {
|
1324 | |
1325 |
|
1326 |
|
1327 |
|
1328 | is?: string | readonly (string | RegExp)[] | RegExp | { msg: string; args: string | readonly (string | RegExp)[] | RegExp };
|
1329 |
|
1330 | |
1331 |
|
1332 |
|
1333 | not?: string | readonly (string | RegExp)[] | RegExp | { msg: string; args: string | readonly (string | RegExp)[] | RegExp };
|
1334 |
|
1335 | |
1336 |
|
1337 |
|
1338 | isEmail?: boolean | { msg: string };
|
1339 |
|
1340 | |
1341 |
|
1342 |
|
1343 | isUrl?: boolean | { msg: string };
|
1344 |
|
1345 | |
1346 |
|
1347 |
|
1348 | isIP?: boolean | { msg: string };
|
1349 |
|
1350 | |
1351 |
|
1352 |
|
1353 | isIPv4?: boolean | { msg: string };
|
1354 |
|
1355 | |
1356 |
|
1357 |
|
1358 | isIPv6?: boolean | { msg: string };
|
1359 |
|
1360 | |
1361 |
|
1362 |
|
1363 | isAlpha?: boolean | { msg: string };
|
1364 |
|
1365 | |
1366 |
|
1367 |
|
1368 | isAlphanumeric?: boolean | { msg: string };
|
1369 |
|
1370 | |
1371 |
|
1372 |
|
1373 | isNumeric?: boolean | { msg: string };
|
1374 |
|
1375 | |
1376 |
|
1377 |
|
1378 | isInt?: boolean | { msg: string };
|
1379 |
|
1380 | |
1381 |
|
1382 |
|
1383 | isFloat?: boolean | { msg: string };
|
1384 |
|
1385 | |
1386 |
|
1387 |
|
1388 | isDecimal?: boolean | { msg: string };
|
1389 |
|
1390 | |
1391 |
|
1392 |
|
1393 | isLowercase?: boolean | { msg: string };
|
1394 |
|
1395 | |
1396 |
|
1397 |
|
1398 | isUppercase?: boolean | { msg: string };
|
1399 |
|
1400 | |
1401 |
|
1402 |
|
1403 | notNull?: boolean | { msg: string };
|
1404 |
|
1405 | |
1406 |
|
1407 |
|
1408 | isNull?: boolean | { msg: string };
|
1409 |
|
1410 | |
1411 |
|
1412 |
|
1413 | notEmpty?: boolean | { msg: string };
|
1414 |
|
1415 | |
1416 |
|
1417 |
|
1418 | equals?: string | { msg: string };
|
1419 |
|
1420 | |
1421 |
|
1422 |
|
1423 | contains?: string | { msg: string };
|
1424 |
|
1425 | |
1426 |
|
1427 |
|
1428 | notIn?: ReadonlyArray<readonly any[]> | { msg: string; args: ReadonlyArray<readonly any[]> };
|
1429 |
|
1430 | |
1431 |
|
1432 |
|
1433 | isIn?: ReadonlyArray<readonly any[]> | { msg: string; args: ReadonlyArray<readonly any[]> };
|
1434 |
|
1435 | |
1436 |
|
1437 |
|
1438 | notContains?: readonly string[] | string | { msg: string; args: readonly string[] | string };
|
1439 |
|
1440 | |
1441 |
|
1442 |
|
1443 | len?: readonly [number, number] | { msg: string; args: readonly [number, number] };
|
1444 |
|
1445 | |
1446 |
|
1447 |
|
1448 | isUUID?: number | { msg: string; args: number };
|
1449 |
|
1450 | |
1451 |
|
1452 |
|
1453 | isDate?: boolean | { msg: string; args: boolean };
|
1454 |
|
1455 | |
1456 |
|
1457 |
|
1458 | isAfter?: string | { msg: string; args: string };
|
1459 |
|
1460 | |
1461 |
|
1462 |
|
1463 | isBefore?: string | { msg: string; args: string };
|
1464 |
|
1465 | |
1466 |
|
1467 |
|
1468 | max?: number | { msg: string; args: readonly [number] };
|
1469 |
|
1470 | |
1471 |
|
1472 |
|
1473 | min?: number | { msg: string; args: readonly [number] };
|
1474 |
|
1475 | |
1476 |
|
1477 |
|
1478 | isArray?: boolean | { msg: string; args: boolean };
|
1479 |
|
1480 | |
1481 |
|
1482 |
|
1483 | isCreditCard?: boolean | { msg: string; args: boolean };
|
1484 |
|
1485 |
|
1486 |
|
1487 | |
1488 |
|
1489 |
|
1490 | [name: string]: unknown;
|
1491 | }
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 | export type ModelIndexesOptions = IndexesOptions
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 | export interface ModelNameOptions {
|
1502 | |
1503 |
|
1504 |
|
1505 | singular?: string;
|
1506 |
|
1507 | |
1508 |
|
1509 |
|
1510 | plural?: string;
|
1511 | }
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 | export interface ModelGetterOptions<M extends Model = Model> {
|
1517 | [name: string]: (this: M) => unknown;
|
1518 | }
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 | export interface ModelSetterOptions<M extends Model = Model> {
|
1524 | [name: string]: (this: M, val: any) => void;
|
1525 | }
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 | export interface ModelScopeOptions<TAttributes = any> {
|
1531 | |
1532 |
|
1533 |
|
1534 | [scopeName: string]: FindOptions<TAttributes> | ((...args: readonly any[]) => FindOptions<TAttributes>);
|
1535 | }
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 | export interface ColumnOptions {
|
1541 | |
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 | allowNull?: boolean;
|
1548 |
|
1549 | |
1550 |
|
1551 |
|
1552 | field?: string;
|
1553 |
|
1554 | |
1555 |
|
1556 |
|
1557 | defaultValue?: unknown;
|
1558 | }
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 | export interface ModelAttributeColumnReferencesOptions {
|
1564 | |
1565 |
|
1566 |
|
1567 | model?: TableName | ModelType;
|
1568 |
|
1569 | |
1570 |
|
1571 |
|
1572 | key?: string;
|
1573 |
|
1574 | |
1575 |
|
1576 |
|
1577 |
|
1578 |
|
1579 | deferrable?: Deferrable;
|
1580 | }
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 | export interface ModelAttributeColumnOptions<M extends Model = Model> extends ColumnOptions {
|
1586 | |
1587 |
|
1588 |
|
1589 | type: DataType;
|
1590 |
|
1591 | |
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 | unique?: boolean | string | { name: string; msg: string };
|
1597 |
|
1598 | |
1599 |
|
1600 |
|
1601 | primaryKey?: boolean;
|
1602 |
|
1603 | |
1604 |
|
1605 |
|
1606 | autoIncrement?: boolean;
|
1607 |
|
1608 | |
1609 |
|
1610 |
|
1611 | autoIncrementIdentity?: boolean;
|
1612 |
|
1613 | |
1614 |
|
1615 |
|
1616 | comment?: string;
|
1617 |
|
1618 | |
1619 |
|
1620 |
|
1621 | references?: string | ModelAttributeColumnReferencesOptions;
|
1622 |
|
1623 | |
1624 |
|
1625 |
|
1626 |
|
1627 | onUpdate?: string;
|
1628 |
|
1629 | |
1630 |
|
1631 |
|
1632 |
|
1633 | onDelete?: string;
|
1634 |
|
1635 |
|
1636 | |
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 | validate?: ModelValidateOptions;
|
1646 |
|
1647 | |
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 | values?: readonly string[];
|
1661 |
|
1662 | |
1663 |
|
1664 |
|
1665 |
|
1666 | get?(this: M): unknown;
|
1667 |
|
1668 | |
1669 |
|
1670 |
|
1671 |
|
1672 | set?(this: M, val: unknown): void;
|
1673 | }
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 | export type ModelAttributes<M extends Model = Model, TAttributes = any> = {
|
1679 | |
1680 |
|
1681 |
|
1682 | [name in keyof TAttributes]: DataType | ModelAttributeColumnOptions<M>;
|
1683 | }
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 | export type Identifier = number | bigint | string | Buffer;
|
1689 |
|
1690 |
|
1691 |
|
1692 |
|
1693 | export interface ModelOptions<M extends Model = Model> {
|
1694 | |
1695 |
|
1696 |
|
1697 |
|
1698 | defaultScope?: FindOptions<Attributes<M>>;
|
1699 |
|
1700 | |
1701 |
|
1702 |
|
1703 |
|
1704 | scopes?: ModelScopeOptions<Attributes<M>>;
|
1705 |
|
1706 | |
1707 |
|
1708 |
|
1709 | omitNull?: boolean;
|
1710 |
|
1711 | |
1712 |
|
1713 |
|
1714 | timestamps?: boolean;
|
1715 |
|
1716 | |
1717 |
|
1718 |
|
1719 |
|
1720 | paranoid?: boolean;
|
1721 |
|
1722 | |
1723 |
|
1724 |
|
1725 | underscored?: boolean;
|
1726 |
|
1727 | |
1728 |
|
1729 |
|
1730 | hasTrigger?: boolean;
|
1731 |
|
1732 | |
1733 |
|
1734 |
|
1735 |
|
1736 | freezeTableName?: boolean;
|
1737 |
|
1738 | |
1739 |
|
1740 |
|
1741 |
|
1742 | name?: ModelNameOptions;
|
1743 |
|
1744 | |
1745 |
|
1746 |
|
1747 | modelName?: string;
|
1748 |
|
1749 | |
1750 |
|
1751 |
|
1752 | indexes?: readonly ModelIndexesOptions[];
|
1753 |
|
1754 | |
1755 |
|
1756 |
|
1757 |
|
1758 | createdAt?: string | boolean;
|
1759 |
|
1760 | |
1761 |
|
1762 |
|
1763 |
|
1764 | deletedAt?: string | boolean;
|
1765 |
|
1766 | |
1767 |
|
1768 |
|
1769 |
|
1770 | updatedAt?: string | boolean;
|
1771 |
|
1772 | |
1773 |
|
1774 |
|
1775 |
|
1776 | tableName?: string;
|
1777 |
|
1778 | schema?: string;
|
1779 |
|
1780 | |
1781 |
|
1782 |
|
1783 | engine?: string;
|
1784 |
|
1785 | charset?: string;
|
1786 |
|
1787 | |
1788 |
|
1789 |
|
1790 | comment?: string;
|
1791 |
|
1792 | collate?: string;
|
1793 |
|
1794 | |
1795 |
|
1796 |
|
1797 | initialAutoIncrement?: string;
|
1798 |
|
1799 | |
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 | hooks?: Partial<ModelHooks<M, Attributes<M>>>;
|
1805 |
|
1806 | |
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 | validate?: ModelValidateOptions;
|
1812 |
|
1813 | |
1814 |
|
1815 |
|
1816 | setterMethods?: ModelSetterOptions<M>;
|
1817 |
|
1818 | |
1819 |
|
1820 |
|
1821 | getterMethods?: ModelGetterOptions<M>;
|
1822 |
|
1823 | |
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 | version?: boolean | string;
|
1833 |
|
1834 | |
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 | whereMergeStrategy?: 'and' | 'overwrite';
|
1846 | }
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 | export interface InitOptions<M extends Model = Model> extends ModelOptions<M> {
|
1852 | |
1853 |
|
1854 |
|
1855 | sequelize: Sequelize;
|
1856 | }
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 | export interface AddScopeOptions {
|
1862 | |
1863 |
|
1864 |
|
1865 | override: boolean;
|
1866 | }
|
1867 |
|
1868 | export abstract class Model<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes>
|
1869 | extends Hooks<Model<TModelAttributes, TCreationAttributes>, TModelAttributes, TCreationAttributes>
|
1870 | {
|
1871 | |
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 | _attributes: TModelAttributes;
|
1890 |
|
1891 | |
1892 |
|
1893 |
|
1894 | dataValues: TModelAttributes;
|
1895 |
|
1896 | |
1897 |
|
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 | _creationAttributes: TCreationAttributes;
|
1904 |
|
1905 |
|
1906 | public static readonly tableName: string;
|
1907 |
|
1908 | |
1909 |
|
1910 |
|
1911 | public static readonly primaryKeyAttribute: string;
|
1912 |
|
1913 | |
1914 |
|
1915 |
|
1916 | public static readonly primaryKeyAttributes: readonly string[];
|
1917 |
|
1918 | |
1919 |
|
1920 |
|
1921 | public static readonly associations: {
|
1922 | [key: string]: Association;
|
1923 | };
|
1924 |
|
1925 | |
1926 |
|
1927 |
|
1928 | public static readonly options: InitOptions;
|
1929 |
|
1930 |
|
1931 | |
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 | public static readonly rawAttributes: { [attribute: string]: ModelAttributeColumnOptions };
|
1937 |
|
1938 | |
1939 |
|
1940 |
|
1941 | public static getAttributes<M extends Model>(this: ModelStatic<M>): {
|
1942 | readonly [Key in keyof Attributes<M>]: ModelAttributeColumnOptions
|
1943 | };
|
1944 |
|
1945 | |
1946 |
|
1947 |
|
1948 | public static readonly sequelize?: Sequelize;
|
1949 |
|
1950 | |
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 | public static init<MS extends ModelStatic<Model>, M extends InstanceType<MS>>(
|
1994 | this: MS,
|
1995 | attributes: ModelAttributes<
|
1996 | M,
|
1997 |
|
1998 | Optional<Attributes<M>, BrandedKeysOf<Attributes<M>, typeof ForeignKeyBrand>>
|
1999 | >,
|
2000 | options: InitOptions<M>
|
2001 | ): MS;
|
2002 |
|
2003 | |
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 | public static removeAttribute(attribute: string): void;
|
2009 |
|
2010 | |
2011 |
|
2012 |
|
2013 |
|
2014 | public static sync<M extends Model>(options?: SyncOptions): Promise<M>;
|
2015 |
|
2016 | |
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 | public static drop(options?: DropOptions): Promise<void>;
|
2022 |
|
2023 | |
2024 |
|
2025 |
|
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 | public static schema<M extends Model>(
|
2033 | this: ModelStatic<M>,
|
2034 | schema: string,
|
2035 | options?: SchemaOptions
|
2036 | ): ModelCtor<M>;
|
2037 |
|
2038 | |
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 | public static getTableName(): string | {
|
2048 | tableName: string;
|
2049 | schema: string;
|
2050 | delimiter: string;
|
2051 | };
|
2052 |
|
2053 | |
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 | public static scope<M extends Model>(
|
2103 | this: ModelStatic<M>,
|
2104 | options?: string | ScopeOptions | readonly (string | ScopeOptions)[] | WhereAttributeHash<M>
|
2105 | ): ModelCtor<M>;
|
2106 |
|
2107 | |
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 | public static addScope<M extends Model>(
|
2116 | this: ModelStatic<M>,
|
2117 | name: string,
|
2118 | scope: FindOptions<Attributes<M>>,
|
2119 | options?: AddScopeOptions
|
2120 | ): void;
|
2121 | public static addScope<M extends Model>(
|
2122 | this: ModelStatic<M>,
|
2123 | name: string,
|
2124 | scope: (...args: readonly any[]) => FindOptions<Attributes<M>>,
|
2125 | options?: AddScopeOptions
|
2126 | ): void;
|
2127 |
|
2128 | |
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 |
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 | public static findAll<M extends Model>(
|
2191 | this: ModelStatic<M>,
|
2192 | options?: FindOptions<Attributes<M>>): Promise<M[]>;
|
2193 |
|
2194 | |
2195 |
|
2196 |
|
2197 |
|
2198 | public static findByPk<M extends Model>(
|
2199 | this: ModelStatic<M>,
|
2200 | identifier: Identifier,
|
2201 | options: Omit<NonNullFindOptions<Attributes<M>>, 'where'>
|
2202 | ): Promise<M>;
|
2203 | public static findByPk<M extends Model>(
|
2204 | this: ModelStatic<M>,
|
2205 | identifier?: Identifier,
|
2206 | options?: Omit<FindOptions<Attributes<M>>, 'where'>
|
2207 | ): Promise<M | null>;
|
2208 |
|
2209 | |
2210 |
|
2211 |
|
2212 | public static findOne<M extends Model>(
|
2213 | this: ModelStatic<M>,
|
2214 | options: NonNullFindOptions<Attributes<M>>
|
2215 | ): Promise<M>;
|
2216 | public static findOne<M extends Model>(
|
2217 | this: ModelStatic<M>,
|
2218 | options?: FindOptions<Attributes<M>>
|
2219 | ): Promise<M | null>;
|
2220 |
|
2221 | |
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 | public static aggregate<T, M extends Model>(
|
2231 | this: ModelStatic<M>,
|
2232 | field: keyof Attributes<M> | '*',
|
2233 | aggregateFunction: string,
|
2234 | options?: AggregateOptions<T, Attributes<M>>
|
2235 | ): Promise<T>;
|
2236 |
|
2237 | |
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 | public static count<M extends Model>(
|
2243 | this: ModelStatic<M>,
|
2244 | options: CountWithOptions<Attributes<M>>
|
2245 | ): Promise<GroupedCountResultItem[]>;
|
2246 |
|
2247 | |
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 | public static count<M extends Model>(
|
2255 | this: ModelStatic<M>,
|
2256 | options?: Omit<CountOptions<Attributes<M>>, 'group'>
|
2257 | ): Promise<number>;
|
2258 |
|
2259 | |
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 |
|
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 | public static findAndCountAll<M extends Model>(
|
2303 | this: ModelStatic<M>,
|
2304 | options?: Omit<FindAndCountOptions<Attributes<M>>, 'group'>
|
2305 | ): Promise<{ rows: M[]; count: number }>;
|
2306 | public static findAndCountAll<M extends Model>(
|
2307 | this: ModelStatic<M>,
|
2308 | options: SetRequired<FindAndCountOptions<Attributes<M>>, 'group'>
|
2309 | ): Promise<{ rows: M[]; count: GroupedCountResultItem[] }>;
|
2310 |
|
2311 | |
2312 |
|
2313 |
|
2314 | public static max<T extends DataType | unknown, M extends Model>(
|
2315 | this: ModelStatic<M>,
|
2316 | field: keyof Attributes<M>,
|
2317 | options?: AggregateOptions<T, Attributes<M>>
|
2318 | ): Promise<T>;
|
2319 |
|
2320 | |
2321 |
|
2322 |
|
2323 | public static min<T extends DataType | unknown, M extends Model>(
|
2324 | this: ModelStatic<M>,
|
2325 | field: keyof Attributes<M>,
|
2326 | options?: AggregateOptions<T, Attributes<M>>
|
2327 | ): Promise<T>;
|
2328 |
|
2329 | |
2330 |
|
2331 |
|
2332 | public static sum<T extends DataType | unknown, M extends Model>(
|
2333 | this: ModelStatic<M>,
|
2334 | field: keyof Attributes<M>,
|
2335 | options?: AggregateOptions<T, Attributes<M>>
|
2336 | ): Promise<number>;
|
2337 |
|
2338 | |
2339 |
|
2340 |
|
2341 | public static build<M extends Model>(
|
2342 | this: ModelStatic<M>,
|
2343 | record?: CreationAttributes<M>,
|
2344 | options?: BuildOptions
|
2345 | ): M;
|
2346 |
|
2347 | |
2348 |
|
2349 |
|
2350 | public static bulkBuild<M extends Model>(
|
2351 | this: ModelStatic<M>,
|
2352 | records: ReadonlyArray<CreationAttributes<M>>,
|
2353 | options?: BuildOptions
|
2354 | ): M[];
|
2355 |
|
2356 | |
2357 |
|
2358 |
|
2359 | public static create<
|
2360 | M extends Model,
|
2361 | O extends CreateOptions<Attributes<M>> = CreateOptions<Attributes<M>>
|
2362 | >(
|
2363 | this: ModelStatic<M>,
|
2364 | values?: CreationAttributes<M>,
|
2365 | options?: O
|
2366 | ): Promise<O extends { returning: false } | { ignoreDuplicates: true } ? void : M>;
|
2367 |
|
2368 | |
2369 |
|
2370 |
|
2371 |
|
2372 | public static findOrBuild<M extends Model>(
|
2373 | this: ModelStatic<M>,
|
2374 | options: FindOrBuildOptions<
|
2375 | Attributes<M>,
|
2376 | CreationAttributes<M>
|
2377 | >
|
2378 | ): Promise<[M, boolean]>;
|
2379 |
|
2380 | |
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 | public static findOrCreate<M extends Model>(
|
2392 | this: ModelStatic<M>,
|
2393 | options: FindOrCreateOptions<Attributes<M>, CreationAttributes<M>>
|
2394 | ): Promise<[M, boolean]>;
|
2395 |
|
2396 | |
2397 |
|
2398 |
|
2399 |
|
2400 | public static findCreateFind<M extends Model>(
|
2401 | this: ModelStatic<M>,
|
2402 | options: FindOrCreateOptions<Attributes<M>, CreationAttributes<M>>
|
2403 | ): Promise<[M, boolean]>;
|
2404 |
|
2405 | |
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 | public static upsert<M extends Model>(
|
2425 | this: ModelStatic<M>,
|
2426 | values: CreationAttributes<M>,
|
2427 | options?: UpsertOptions<Attributes<M>>
|
2428 | ): Promise<[M, boolean | null]>;
|
2429 |
|
2430 | |
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 | public static bulkCreate<M extends Model>(
|
2442 | this: ModelStatic<M>,
|
2443 | records: ReadonlyArray<CreationAttributes<M>>,
|
2444 | options?: BulkCreateOptions<Attributes<M>>
|
2445 | ): Promise<M[]>;
|
2446 |
|
2447 | |
2448 |
|
2449 |
|
2450 | public static truncate<M extends Model>(
|
2451 | this: ModelStatic<M>,
|
2452 | options?: TruncateOptions<Attributes<M>>
|
2453 | ): Promise<void>;
|
2454 |
|
2455 | |
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 | public static destroy<M extends Model>(
|
2461 | this: ModelStatic<M>,
|
2462 | options?: DestroyOptions<Attributes<M>>
|
2463 | ): Promise<number>;
|
2464 |
|
2465 | |
2466 |
|
2467 |
|
2468 | public static restore<M extends Model>(
|
2469 | this: ModelStatic<M>,
|
2470 | options?: RestoreOptions<Attributes<M>>
|
2471 | ): Promise<void>;
|
2472 |
|
2473 | |
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 | public static update<M extends Model>(
|
2479 | this: ModelStatic<M>,
|
2480 | values: {
|
2481 | [key in keyof Attributes<M>]?: Attributes<M>[key] | Fn | Col | Literal;
|
2482 | },
|
2483 | options: Omit<UpdateOptions<Attributes<M>>, 'returning'>
|
2484 | & { returning: Exclude<UpdateOptions<Attributes<M>>['returning'], undefined | false> }
|
2485 | ): Promise<[affectedCount: number, affectedRows: M[]]>;
|
2486 |
|
2487 | |
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 | public static update<M extends Model>(
|
2493 | this: ModelStatic<M>,
|
2494 | values: {
|
2495 | [key in keyof Attributes<M>]?: Attributes<M>[key] | Fn | Col | Literal;
|
2496 | },
|
2497 | options: UpdateOptions<Attributes<M>>
|
2498 | ): Promise<[affectedCount: number]>;
|
2499 |
|
2500 | |
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 |
|
2507 |
|
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 |
|
2524 |
|
2525 |
|
2526 |
|
2527 | static increment<M extends Model>(
|
2528 | this: ModelStatic<M>,
|
2529 | fields: AllowReadonlyArray<keyof Attributes<M>>,
|
2530 | options: IncrementDecrementOptionsWithBy<Attributes<M>>
|
2531 | ): Promise<[affectedRows: M[], affectedCount?: number]>;
|
2532 | static increment<M extends Model>(
|
2533 | this: ModelStatic<M>,
|
2534 | fields: { [key in keyof Attributes<M>]?: number },
|
2535 | options: IncrementDecrementOptions<Attributes<M>>
|
2536 | ): Promise<[affectedRows: M[], affectedCount?: number]>;
|
2537 |
|
2538 | |
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 | static decrement<M extends Model>(
|
2552 | this: ModelStatic<M>,
|
2553 | fields: AllowReadonlyArray<keyof Attributes<M>>,
|
2554 | options: IncrementDecrementOptionsWithBy<Attributes<M>>
|
2555 | ): Promise<[affectedRows: M[], affectedCount?: number]>;
|
2556 | static decrement<M extends Model>(
|
2557 | this: ModelStatic<M>,
|
2558 | fields: { [key in keyof Attributes<M>]?: number },
|
2559 | options: IncrementDecrementOptions<Attributes<M>>
|
2560 | ): Promise<[affectedRows: M[], affectedCount?: number]>;
|
2561 |
|
2562 | |
2563 |
|
2564 |
|
2565 |
|
2566 | public static describe(): Promise<object>;
|
2567 |
|
2568 | |
2569 |
|
2570 |
|
2571 | public static unscoped<M extends ModelType>(this: M): M;
|
2572 |
|
2573 | |
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 | public static beforeValidate<M extends Model>(
|
2580 | this: ModelStatic<M>,
|
2581 | name: string,
|
2582 | fn: (instance: M, options: ValidationOptions) => HookReturn
|
2583 | ): void;
|
2584 | public static beforeValidate<M extends Model>(
|
2585 | this: ModelStatic<M>,
|
2586 | fn: (instance: M, options: ValidationOptions) => HookReturn
|
2587 | ): void;
|
2588 |
|
2589 | |
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 | public static afterValidate<M extends Model>(
|
2596 | this: ModelStatic<M>,
|
2597 | name: string,
|
2598 | fn: (instance: M, options: ValidationOptions) => HookReturn
|
2599 | ): void;
|
2600 | public static afterValidate<M extends Model>(
|
2601 | this: ModelStatic<M>,
|
2602 | fn: (instance: M, options: ValidationOptions) => HookReturn
|
2603 | ): void;
|
2604 |
|
2605 | |
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 | public static beforeCreate<M extends Model>(
|
2612 | this: ModelStatic<M>,
|
2613 | name: string,
|
2614 | fn: (instance: M, options: CreateOptions<Attributes<M>>) => HookReturn
|
2615 | ): void;
|
2616 | public static beforeCreate<M extends Model>(
|
2617 | this: ModelStatic<M>,
|
2618 | fn: (instance: M, options: CreateOptions<Attributes<M>>) => HookReturn
|
2619 | ): void;
|
2620 |
|
2621 | |
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 |
|
2627 | public static afterCreate<M extends Model>(
|
2628 | this: ModelStatic<M>,
|
2629 | name: string,
|
2630 | fn: (instance: M, options: CreateOptions<Attributes<M>>) => HookReturn
|
2631 | ): void;
|
2632 | public static afterCreate<M extends Model>(
|
2633 | this: ModelStatic<M>,
|
2634 | fn: (instance: M, options: CreateOptions<Attributes<M>>) => HookReturn
|
2635 | ): void;
|
2636 |
|
2637 | |
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 | public static beforeDestroy<M extends Model>(
|
2644 | this: ModelStatic<M>,
|
2645 | name: string,
|
2646 | fn: (instance: M, options: InstanceDestroyOptions) => HookReturn
|
2647 | ): void;
|
2648 | public static beforeDestroy<M extends Model>(
|
2649 | this: ModelStatic<M>,
|
2650 | fn: (instance: M, options: InstanceDestroyOptions) => HookReturn
|
2651 | ): void;
|
2652 |
|
2653 | |
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 | public static afterDestroy<M extends Model>(
|
2660 | this: ModelStatic<M>,
|
2661 | name: string,
|
2662 | fn: (instance: M, options: InstanceDestroyOptions) => HookReturn
|
2663 | ): void;
|
2664 | public static afterDestroy<M extends Model>(
|
2665 | this: ModelStatic<M>,
|
2666 | fn: (instance: M, options: InstanceDestroyOptions) => HookReturn
|
2667 | ): void;
|
2668 |
|
2669 | |
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 | public static beforeUpdate<M extends Model>(
|
2676 | this: ModelStatic<M>,
|
2677 | name: string,
|
2678 | fn: (instance: M, options: UpdateOptions<Attributes<M>>) => HookReturn
|
2679 | ): void;
|
2680 | public static beforeUpdate<M extends Model>(
|
2681 | this: ModelStatic<M>,
|
2682 | fn: (instance: M, options: UpdateOptions<Attributes<M>>) => HookReturn
|
2683 | ): void;
|
2684 |
|
2685 | |
2686 |
|
2687 |
|
2688 |
|
2689 |
|
2690 |
|
2691 | public static afterUpdate<M extends Model>(
|
2692 | this: ModelStatic<M>,
|
2693 | name: string,
|
2694 | fn: (instance: M, options: UpdateOptions<Attributes<M>>) => HookReturn
|
2695 | ): void;
|
2696 | public static afterUpdate<M extends Model>(
|
2697 | this: ModelStatic<M>,
|
2698 | fn: (instance: M, options: UpdateOptions<Attributes<M>>) => HookReturn
|
2699 | ): void;
|
2700 |
|
2701 | |
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 | public static beforeSave<M extends Model>(
|
2708 | this: ModelStatic<M>,
|
2709 | name: string,
|
2710 | fn: (instance: M, options: UpdateOptions<Attributes<M>> | SaveOptions<Attributes<M>>) => HookReturn
|
2711 | ): void;
|
2712 | public static beforeSave<M extends Model>(
|
2713 | this: ModelStatic<M>,
|
2714 | fn: (instance: M, options: UpdateOptions<Attributes<M>> | SaveOptions<Attributes<M>>) => HookReturn
|
2715 | ): void;
|
2716 |
|
2717 | |
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 | public static afterSave<M extends Model>(
|
2724 | this: ModelStatic<M>,
|
2725 | name: string,
|
2726 | fn: (instance: M, options: UpdateOptions<Attributes<M>> | SaveOptions<Attributes<M>>) => HookReturn
|
2727 | ): void;
|
2728 | public static afterSave<M extends Model>(
|
2729 | this: ModelStatic<M>,
|
2730 | fn: (instance: M, options: UpdateOptions<Attributes<M>> | SaveOptions<Attributes<M>>) => HookReturn
|
2731 | ): void;
|
2732 |
|
2733 | |
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 | public static beforeBulkCreate<M extends Model>(
|
2740 | this: ModelStatic<M>,
|
2741 | name: string,
|
2742 | fn: (instances: M[], options: BulkCreateOptions<Attributes<M>>) => HookReturn
|
2743 | ): void;
|
2744 | public static beforeBulkCreate<M extends Model>(
|
2745 | this: ModelStatic<M>,
|
2746 | fn: (instances: M[], options: BulkCreateOptions<Attributes<M>>) => HookReturn
|
2747 | ): void;
|
2748 |
|
2749 | |
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 | public static afterBulkCreate<M extends Model>(
|
2756 | this: ModelStatic<M>,
|
2757 | name: string,
|
2758 | fn: (instances: readonly M[], options: BulkCreateOptions<Attributes<M>>) => HookReturn
|
2759 | ): void;
|
2760 | public static afterBulkCreate<M extends Model>(
|
2761 | this: ModelStatic<M>,
|
2762 | fn: (instances: readonly M[], options: BulkCreateOptions<Attributes<M>>) => HookReturn
|
2763 | ): void;
|
2764 |
|
2765 | |
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 | public static beforeBulkDestroy<M extends Model>(
|
2772 | this: ModelStatic<M>,
|
2773 | name: string, fn: (options: BulkCreateOptions<Attributes<M>>) => HookReturn): void;
|
2774 | public static beforeBulkDestroy<M extends Model>(
|
2775 | this: ModelStatic<M>,
|
2776 | fn: (options: BulkCreateOptions<Attributes<M>>) => HookReturn
|
2777 | ): void;
|
2778 |
|
2779 | |
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 | public static afterBulkDestroy<M extends Model>(
|
2786 | this: ModelStatic<M>,
|
2787 | name: string, fn: (options: DestroyOptions<Attributes<M>>) => HookReturn
|
2788 | ): void;
|
2789 | public static afterBulkDestroy<M extends Model>(
|
2790 | this: ModelStatic<M>,
|
2791 | fn: (options: DestroyOptions<Attributes<M>>) => HookReturn
|
2792 | ): void;
|
2793 |
|
2794 | |
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 | public static beforeBulkUpdate<M extends Model>(
|
2801 | this: ModelStatic<M>,
|
2802 | name: string, fn: (options: UpdateOptions<Attributes<M>>) => HookReturn
|
2803 | ): void;
|
2804 | public static beforeBulkUpdate<M extends Model>(
|
2805 | this: ModelStatic<M>,
|
2806 | fn: (options: UpdateOptions<Attributes<M>>) => HookReturn
|
2807 | ): void;
|
2808 |
|
2809 | |
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 | public static afterBulkUpdate<M extends Model>(
|
2816 | this: ModelStatic<M>,
|
2817 | name: string, fn: (options: UpdateOptions<Attributes<M>>) => HookReturn
|
2818 | ): void;
|
2819 | public static afterBulkUpdate<M extends Model>(
|
2820 | this: ModelStatic<M>,
|
2821 | fn: (options: UpdateOptions<Attributes<M>>) => HookReturn
|
2822 | ): void;
|
2823 |
|
2824 | |
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 | public static beforeFind<M extends Model>(
|
2831 | this: ModelStatic<M>,
|
2832 | name: string, fn: (options: FindOptions<Attributes<M>>) => HookReturn
|
2833 | ): void;
|
2834 | public static beforeFind<M extends Model>(
|
2835 | this: ModelStatic<M>,
|
2836 | fn: (options: FindOptions<Attributes<M>>) => HookReturn
|
2837 | ): void;
|
2838 |
|
2839 | |
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 |
|
2845 | public static beforeCount<M extends Model>(
|
2846 | this: ModelStatic<M>,
|
2847 | name: string, fn: (options: CountOptions<Attributes<M>>) => HookReturn
|
2848 | ): void;
|
2849 | public static beforeCount<M extends Model>(
|
2850 | this: ModelStatic<M>,
|
2851 | fn: (options: CountOptions<Attributes<M>>) => HookReturn
|
2852 | ): void;
|
2853 |
|
2854 | |
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 | public static beforeFindAfterExpandIncludeAll<M extends Model>(
|
2861 | this: ModelStatic<M>,
|
2862 | name: string, fn: (options: FindOptions<Attributes<M>>) => HookReturn
|
2863 | ): void;
|
2864 | public static beforeFindAfterExpandIncludeAll<M extends Model>(
|
2865 | this: ModelStatic<M>,
|
2866 | fn: (options: FindOptions<Attributes<M>>) => HookReturn
|
2867 | ): void;
|
2868 |
|
2869 | |
2870 |
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 | public static beforeFindAfterOptions<M extends Model>(
|
2876 | this: ModelStatic<M>,
|
2877 | name: string, fn: (options: FindOptions<Attributes<M>>) => HookReturn
|
2878 | ): void;
|
2879 | public static beforeFindAfterOptions<M extends Model>(
|
2880 | this: ModelStatic<M>,
|
2881 | fn: (options: FindOptions<Attributes<M>>) => void
|
2882 | ): HookReturn;
|
2883 |
|
2884 | |
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 | public static afterFind<M extends Model>(
|
2891 | this: ModelStatic<M>,
|
2892 | name: string,
|
2893 | fn: (instancesOrInstance: readonly M[] | M | null, options: FindOptions<Attributes<M>>) => HookReturn
|
2894 | ): void;
|
2895 | public static afterFind<M extends Model>(
|
2896 | this: ModelStatic<M>,
|
2897 | fn: (instancesOrInstance: readonly M[] | M | null, options: FindOptions<Attributes<M>>) => HookReturn
|
2898 | ): void;
|
2899 |
|
2900 | |
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 | public static beforeBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
2906 | public static beforeBulkSync(fn: (options: SyncOptions) => HookReturn): void;
|
2907 |
|
2908 | |
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 | public static afterBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
2914 | public static afterBulkSync(fn: (options: SyncOptions) => HookReturn): void;
|
2915 |
|
2916 | |
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 | public static beforeSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
2922 | public static beforeSync(fn: (options: SyncOptions) => HookReturn): void;
|
2923 |
|
2924 | |
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 | public static afterSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
2930 | public static afterSync(fn: (options: SyncOptions) => HookReturn): void;
|
2931 |
|
2932 | |
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 | public static hasOne<M extends Model, T extends Model>(
|
2942 | this: ModelStatic<M>, target: ModelStatic<T>, options?: HasOneOptions
|
2943 | ): HasOne<M, T>;
|
2944 |
|
2945 | |
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 | public static belongsTo<M extends Model, T extends Model>(
|
2955 | this: ModelStatic<M>, target: ModelStatic<T>, options?: BelongsToOptions
|
2956 | ): BelongsTo<M, T>;
|
2957 |
|
2958 | |
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 |
|
2984 |
|
2985 |
|
2986 |
|
2987 |
|
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 |
|
2997 |
|
2998 |
|
2999 |
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 | public static hasMany<M extends Model, T extends Model>(
|
3012 | this: ModelStatic<M>, target: ModelStatic<T>, options?: HasManyOptions
|
3013 | ): HasMany<M, T>;
|
3014 |
|
3015 | |
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 |
|
3030 |
|
3031 |
|
3032 |
|
3033 |
|
3034 |
|
3035 |
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 |
|
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 | public static belongsToMany<M extends Model, T extends Model>(
|
3065 | this: ModelStatic<M>, target: ModelStatic<T>, options: BelongsToManyOptions
|
3066 | ): BelongsToMany<M, T>;
|
3067 |
|
3068 | |
3069 |
|
3070 |
|
3071 | public isNewRecord: boolean;
|
3072 |
|
3073 | |
3074 |
|
3075 |
|
3076 | public sequelize: Sequelize;
|
3077 |
|
3078 | |
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 | constructor(values?: MakeNullishOptional<TCreationAttributes>, options?: BuildOptions);
|
3084 |
|
3085 | |
3086 |
|
3087 |
|
3088 | public where(): object;
|
3089 |
|
3090 | |
3091 |
|
3092 |
|
3093 | public getDataValue<K extends keyof TModelAttributes>(key: K): TModelAttributes[K];
|
3094 |
|
3095 | |
3096 |
|
3097 |
|
3098 | public setDataValue<K extends keyof TModelAttributes>(key: K, value: TModelAttributes[K]): void;
|
3099 |
|
3100 | |
3101 |
|
3102 |
|
3103 |
|
3104 |
|
3105 |
|
3106 |
|
3107 |
|
3108 | public get(options?: { plain?: boolean; clone?: boolean }): TModelAttributes;
|
3109 | public get<K extends keyof this>(key: K, options?: { plain?: boolean; clone?: boolean }): this[K];
|
3110 | public get(key: string, options?: { plain?: boolean; clone?: boolean }): unknown;
|
3111 |
|
3112 | |
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 | public set<K extends keyof TModelAttributes>(key: K, value: TModelAttributes[K], options?: SetOptions): this;
|
3137 | public set(keys: Partial<TModelAttributes>, options?: SetOptions): this;
|
3138 | public setAttributes<K extends keyof TModelAttributes>(key: K, value: TModelAttributes[K], options?: SetOptions): this;
|
3139 | public setAttributes(keys: Partial<TModelAttributes>, options?: SetOptions): this;
|
3140 |
|
3141 | |
3142 |
|
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 | public changed<K extends keyof this>(key: K): boolean;
|
3152 | public changed<K extends keyof this>(key: K, dirty: boolean): void;
|
3153 | public changed(): false | string[];
|
3154 |
|
3155 | |
3156 |
|
3157 |
|
3158 | public previous(): Partial<TModelAttributes>;
|
3159 | public previous<K extends keyof TModelAttributes>(key: K): TModelAttributes[K] | undefined;
|
3160 |
|
3161 | |
3162 |
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 | public save(options?: SaveOptions<TModelAttributes>): Promise<this>;
|
3171 |
|
3172 | |
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 | public reload(options?: FindOptions<TModelAttributes>): Promise<this>;
|
3179 |
|
3180 | |
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 | public validate(options?: ValidationOptions): Promise<void>;
|
3189 |
|
3190 | |
3191 |
|
3192 |
|
3193 | public update<K extends keyof TModelAttributes>(key: K, value: TModelAttributes[K] | Col | Fn | Literal, options?: InstanceUpdateOptions<TModelAttributes>): Promise<this>;
|
3194 | public update(
|
3195 | keys: {
|
3196 | [key in keyof TModelAttributes]?: TModelAttributes[key] | Fn | Col | Literal;
|
3197 | },
|
3198 | options?: InstanceUpdateOptions<TModelAttributes>
|
3199 | ): Promise<this>;
|
3200 |
|
3201 | |
3202 |
|
3203 |
|
3204 |
|
3205 | public destroy(options?: InstanceDestroyOptions): Promise<void>;
|
3206 |
|
3207 | |
3208 |
|
3209 |
|
3210 | public restore(options?: InstanceRestoreOptions): Promise<void>;
|
3211 |
|
3212 | |
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 | public increment<K extends keyof TModelAttributes>(
|
3233 | fields: K | readonly K[] | Partial<TModelAttributes>,
|
3234 | options?: IncrementDecrementOptionsWithBy<TModelAttributes>
|
3235 | ): Promise<this>;
|
3236 |
|
3237 | |
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 | public decrement<K extends keyof TModelAttributes>(
|
3258 | fields: K | readonly K[] | Partial<TModelAttributes>,
|
3259 | options?: IncrementDecrementOptionsWithBy<TModelAttributes>
|
3260 | ): Promise<this>;
|
3261 |
|
3262 | |
3263 |
|
3264 |
|
3265 | public equals(other: this): boolean;
|
3266 |
|
3267 | |
3268 |
|
3269 |
|
3270 | public equalsOneOf(others: readonly this[]): boolean;
|
3271 |
|
3272 | |
3273 |
|
3274 |
|
3275 |
|
3276 | public toJSON<T extends TModelAttributes>(): T;
|
3277 | public toJSON(): object;
|
3278 |
|
3279 | |
3280 |
|
3281 |
|
3282 |
|
3283 |
|
3284 |
|
3285 |
|
3286 | public isSoftDeleted(): boolean;
|
3287 | }
|
3288 |
|
3289 |
|
3290 | export type ModelType<TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes> = new () => Model<TModelAttributes, TCreationAttributes>;
|
3291 |
|
3292 | type NonConstructorKeys<T> = ({[P in keyof T]: T[P] extends new () => any ? never : P })[keyof T];
|
3293 | type NonConstructor<T> = Pick<T, NonConstructorKeys<T>>;
|
3294 |
|
3295 |
|
3296 | export type ModelCtor<M extends Model> = ModelStatic<M>;
|
3297 |
|
3298 | export type ModelDefined<S extends {}, T extends {}> = ModelStatic<Model<S, T>>;
|
3299 |
|
3300 |
|
3301 | export type ModelStatic<M extends Model> = NonConstructor<typeof Model> & { new(): M };
|
3302 |
|
3303 | export default Model;
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 | type IsBranded<T, Brand extends symbol> = keyof NonNullable<T> extends keyof Omit<NonNullable<T>, Brand>
|
3315 | ? false
|
3316 | : true;
|
3317 |
|
3318 | type BrandedKeysOf<T, Brand extends symbol> = {
|
3319 | [P in keyof T]-?: IsBranded<T[P], Brand> extends true ? P : never
|
3320 | }[keyof T];
|
3321 |
|
3322 |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 | declare const NonAttributeBrand: unique symbol;
|
3328 |
|
3329 |
|
3330 |
|
3331 |
|
3332 |
|
3333 |
|
3334 | export type NonAttribute<T> =
|
3335 |
|
3336 |
|
3337 |
|
3338 | T extends null | undefined ? T
|
3339 | : (T & { [NonAttributeBrand]?: true });
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 | declare const ForeignKeyBrand: unique symbol;
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 | export type ForeignKey<T> =
|
3354 |
|
3355 |
|
3356 |
|
3357 | T extends null | undefined ? T
|
3358 | : (T & { [ForeignKeyBrand]?: true });
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 | type InferAttributesOptions<Excluded, > = { omit?: Excluded };
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 |
|
3400 |
|
3401 |
|
3402 |
|
3403 |
|
3404 |
|
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 |
|
3412 | export type InferAttributes<
|
3413 | M extends Model,
|
3414 | Options extends InferAttributesOptions<keyof M | never | ''> = { omit: never }
|
3415 | > = {
|
3416 | [Key in keyof M as InternalInferAttributeKeysFromFields<M, Key, Options>]: M[Key]
|
3417 | };
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 | declare const CreationAttributeBrand: unique symbol;
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 | export type CreationOptional<T> =
|
3433 |
|
3434 |
|
3435 |
|
3436 | T extends null | undefined ? T
|
3437 | : (T & { [CreationAttributeBrand]?: true });
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 | export type InferCreationAttributes<
|
3455 | M extends Model,
|
3456 | Options extends InferAttributesOptions<keyof M | never | ''> = { omit: never }
|
3457 | > = {
|
3458 | [Key in keyof M as InternalInferAttributeKeysFromFields<M, Key, Options>]: IsBranded<M[Key], typeof CreationAttributeBrand> extends true
|
3459 | ? (M[Key] | undefined)
|
3460 | : M[Key]
|
3461 | };
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 | type InternalInferAttributeKeysFromFields<M extends Model, Key extends keyof M, Options extends InferAttributesOptions<keyof M | never | ''>> =
|
3474 |
|
3475 | Key extends keyof Model ? never
|
3476 |
|
3477 | : M[Key] extends AnyFunction ? never
|
3478 |
|
3479 | : IsBranded<M[Key], typeof NonAttributeBrand> extends true ? never
|
3480 |
|
3481 | : Options['omit'] extends string ? (Key extends Options['omit'] ? never : Key)
|
3482 | : Key;
|
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 |
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 | export type CreationAttributes<M extends Model | Hooks> = MakeNullishOptional<M['_creationAttributes']>;
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 | export type Attributes<M extends Model | Hooks> = M['_attributes'];
|
3507 |
|
\ | No newline at end of file |