1 | import type { Options as RetryAsPromisedOptions } from 'retry-as-promised';
|
2 | import { HookReturn, Hooks, SequelizeHooks } from './hooks';
|
3 | import { ValidationOptions } from './instance-validator';
|
4 | import {
|
5 | AndOperator,
|
6 | BulkCreateOptions,
|
7 | CreateOptions,
|
8 | DestroyOptions,
|
9 | DropOptions,
|
10 | FindOptions,
|
11 | InstanceDestroyOptions,
|
12 | Logging,
|
13 | Model,
|
14 | ModelAttributeColumnOptions,
|
15 | ModelAttributes,
|
16 | ModelOptions,
|
17 | OrOperator,
|
18 | UpdateOptions,
|
19 | WhereOperators,
|
20 | ModelCtor,
|
21 | Hookable,
|
22 | ModelType,
|
23 | CreationAttributes,
|
24 | Attributes,
|
25 | ColumnReference, WhereAttributeHashValue,
|
26 | } from './model';
|
27 | import { ModelManager } from './model-manager';
|
28 | import { QueryInterface, QueryOptions, QueryOptionsWithModel, QueryOptionsWithType, ColumnsDescription } from './dialects/abstract/query-interface';
|
29 | import QueryTypes = require('./query-types');
|
30 | import { Transaction, TransactionOptions } from './transaction';
|
31 | import { Op } from './index';
|
32 | import { Cast, Col, DeepWriteable, Fn, Json, Literal, Where } from './utils';
|
33 | import { Connection, ConnectionManager, GetConnectionOptions } from './dialects/abstract/connection-manager';
|
34 |
|
35 | export type RetryOptions = RetryAsPromisedOptions;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | export interface SyncAlterOptions {
|
41 | |
42 |
|
43 |
|
44 | drop?: boolean;
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export interface SyncOptions extends Logging, Hookable {
|
51 | |
52 |
|
53 |
|
54 | force?: boolean;
|
55 |
|
56 | |
57 |
|
58 |
|
59 |
|
60 | alter?: boolean | SyncAlterOptions;
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 | match?: RegExp;
|
67 |
|
68 | |
69 |
|
70 |
|
71 | schema?: string;
|
72 |
|
73 | |
74 |
|
75 |
|
76 | searchPath?: string;
|
77 |
|
78 | }
|
79 |
|
80 | export interface DefaultSetOptions { }
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export interface PoolOptions {
|
86 | |
87 |
|
88 |
|
89 | max?: number;
|
90 |
|
91 | |
92 |
|
93 |
|
94 | min?: number;
|
95 |
|
96 | |
97 |
|
98 |
|
99 | idle?: number;
|
100 |
|
101 | |
102 |
|
103 |
|
104 | acquire?: number;
|
105 |
|
106 | |
107 |
|
108 |
|
109 | evict?: number;
|
110 |
|
111 | |
112 |
|
113 |
|
114 | maxUses?: number;
|
115 |
|
116 | |
117 |
|
118 |
|
119 |
|
120 | validate?(client?: unknown): boolean;
|
121 | }
|
122 |
|
123 | export interface ConnectionOptions {
|
124 | host?: string;
|
125 | port?: string | number;
|
126 | username?: string;
|
127 | password?: string;
|
128 | database?: string;
|
129 | }
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | export interface ReplicationOptions {
|
135 | read: ConnectionOptions[];
|
136 |
|
137 | write: ConnectionOptions;
|
138 | }
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | export interface OperatorsAliases {
|
144 | [K: string]: symbol;
|
145 | }
|
146 |
|
147 |
|
148 |
|
149 |
|
150 | export interface Config {
|
151 | readonly database: string;
|
152 | readonly dialectModule?: object;
|
153 | readonly host?: string;
|
154 | readonly port?: string;
|
155 | readonly username: string;
|
156 | readonly password: string | null;
|
157 | readonly pool?: {
|
158 | readonly acquire: number;
|
159 | readonly idle: number;
|
160 | readonly max: number;
|
161 | readonly min: number;
|
162 | };
|
163 | readonly protocol: 'tcp';
|
164 | readonly native: boolean;
|
165 | readonly ssl: boolean;
|
166 | readonly replication: ReplicationOptions | false;
|
167 | readonly dialectModulePath: null | string;
|
168 | readonly keepDefaultTimezone?: boolean;
|
169 | readonly dialectOptions?: {
|
170 | readonly charset?: string;
|
171 | readonly timeout?: number;
|
172 | };
|
173 | }
|
174 |
|
175 | export type Dialect = 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' | 'db2' | 'snowflake' | 'oracle';
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | export interface Options extends Logging {
|
181 | |
182 |
|
183 |
|
184 |
|
185 |
|
186 | dialect?: Dialect;
|
187 |
|
188 | |
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | dialectModule?: object;
|
195 |
|
196 |
|
197 | |
198 |
|
199 |
|
200 |
|
201 | dialectModulePath?: string;
|
202 |
|
203 | |
204 |
|
205 |
|
206 | dialectOptions?: object;
|
207 |
|
208 | |
209 |
|
210 |
|
211 |
|
212 |
|
213 | storage?: string;
|
214 |
|
215 | |
216 |
|
217 |
|
218 | database?: string;
|
219 |
|
220 | |
221 |
|
222 |
|
223 | username?: string;
|
224 |
|
225 | |
226 |
|
227 |
|
228 | password?: string;
|
229 |
|
230 | |
231 |
|
232 |
|
233 |
|
234 |
|
235 | host?: string;
|
236 |
|
237 | |
238 |
|
239 |
|
240 | port?: number;
|
241 |
|
242 | |
243 |
|
244 |
|
245 | ssl?: boolean;
|
246 |
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 | protocol?: string;
|
253 |
|
254 | |
255 |
|
256 |
|
257 | define?: ModelOptions;
|
258 |
|
259 | |
260 |
|
261 |
|
262 | query?: QueryOptions;
|
263 |
|
264 | |
265 |
|
266 |
|
267 | set?: DefaultSetOptions;
|
268 |
|
269 | |
270 |
|
271 |
|
272 | sync?: SyncOptions;
|
273 |
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | timezone?: string;
|
285 |
|
286 | |
287 |
|
288 |
|
289 |
|
290 |
|
291 | omitNull?: boolean;
|
292 |
|
293 | |
294 |
|
295 |
|
296 |
|
297 |
|
298 | native?: boolean;
|
299 |
|
300 | |
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 | replication?: ReplicationOptions | false;
|
309 |
|
310 | |
311 |
|
312 |
|
313 | pool?: PoolOptions;
|
314 |
|
315 | |
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 | quoteIdentifiers?: boolean;
|
322 |
|
323 | |
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | isolationLevel?: string;
|
330 |
|
331 | |
332 |
|
333 |
|
334 |
|
335 |
|
336 | transactionType?: Transaction.TYPES;
|
337 |
|
338 | |
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 | typeValidation?: boolean;
|
345 |
|
346 | |
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 | operatorsAliases?: OperatorsAliases;
|
354 |
|
355 |
|
356 | |
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | standardConformingStrings?: boolean;
|
363 |
|
364 | |
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | clientMinMessages?: string | boolean;
|
374 |
|
375 | |
376 |
|
377 |
|
378 | hooks?: Partial<SequelizeHooks<Model, any, any>>;
|
379 |
|
380 | |
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 | minifyAliases?: boolean;
|
387 |
|
388 | |
389 |
|
390 |
|
391 |
|
392 |
|
393 | logQueryParameters?: boolean;
|
394 |
|
395 | retry?: RetryOptions;
|
396 |
|
397 | |
398 |
|
399 |
|
400 | schema?: string;
|
401 |
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 | attributeBehavior?: 'escape' | 'throw' | 'unsafe-legacy';
|
408 | }
|
409 |
|
410 | export interface QueryOptionsTransactionRequired { }
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 | export class Sequelize extends Hooks {
|
425 |
|
426 |
|
427 |
|
428 | |
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | public static fn: typeof fn;
|
445 | public fn: typeof fn;
|
446 |
|
447 | |
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 | public static col: typeof col;
|
454 | public col: typeof col;
|
455 |
|
456 | |
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | public static cast: typeof cast;
|
463 | public cast: typeof cast;
|
464 |
|
465 | |
466 |
|
467 |
|
468 |
|
469 |
|
470 | public static literal: typeof literal;
|
471 | public literal: typeof literal;
|
472 |
|
473 | |
474 |
|
475 |
|
476 |
|
477 |
|
478 | public static and: typeof and;
|
479 | public and: typeof and;
|
480 |
|
481 | |
482 |
|
483 |
|
484 |
|
485 |
|
486 | public static or: typeof or;
|
487 | public or: typeof or;
|
488 |
|
489 | |
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 | public static json: typeof json;
|
498 | public json: typeof json;
|
499 |
|
500 | |
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 | public static where: typeof where;
|
519 | public where: typeof where;
|
520 |
|
521 | |
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 | public static beforeValidate(name: string, fn: (instance: Model, options: ValidationOptions) => void): void;
|
528 | public static beforeValidate(fn: (instance: Model, options: ValidationOptions) => void): void;
|
529 |
|
530 | |
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 | public static afterValidate(name: string, fn: (instance: Model, options: ValidationOptions) => void): void;
|
537 | public static afterValidate(fn: (instance: Model, options: ValidationOptions) => void): void;
|
538 |
|
539 | |
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 | public static beforeCreate(name: string, fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
546 | public static beforeCreate(fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
547 |
|
548 | |
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 | public static afterCreate(name: string, fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
555 | public static afterCreate(fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
556 |
|
557 | |
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 | public static beforeDestroy(name: string, fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
564 | public static beforeDestroy(fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
565 |
|
566 | |
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 | public static afterDestroy(name: string, fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
573 | public static afterDestroy(fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
574 |
|
575 | |
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | public static beforeUpdate(name: string, fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
582 | public static beforeUpdate(fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
583 |
|
584 | |
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 | public static afterUpdate(name: string, fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
591 | public static afterUpdate(fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
592 |
|
593 | |
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 | public static beforeSave(
|
600 | name: string,
|
601 | fn: (instance: Model, options: UpdateOptions<any> | CreateOptions<any>) => void
|
602 | ): void;
|
603 | public static beforeSave(fn: (instance: Model, options: UpdateOptions<any> | CreateOptions<any>) => void): void;
|
604 |
|
605 | |
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 | public static afterSave(
|
612 | name: string,
|
613 | fn: (instance: Model, options: UpdateOptions<any> | CreateOptions<any>) => void
|
614 | ): void;
|
615 | public static afterSave(
|
616 | fn: (instance: Model, options: UpdateOptions<any> | CreateOptions<any>) => void
|
617 | ): void;
|
618 |
|
619 | |
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 | public static beforeBulkCreate(
|
626 | name: string,
|
627 | fn: (instances: Model[], options: BulkCreateOptions<any>) => void
|
628 | ): void;
|
629 | public static beforeBulkCreate(fn: (instances: Model[], options: BulkCreateOptions<any>) => void): void;
|
630 |
|
631 | |
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 | public static afterBulkCreate(
|
638 | name: string, fn: (instances: Model[], options: BulkCreateOptions<any>) => void
|
639 | ): void;
|
640 | public static afterBulkCreate(fn: (instances: Model[], options: BulkCreateOptions<any>) => void): void;
|
641 |
|
642 | |
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 | public static beforeBulkDestroy(name: string, fn: (options: BulkCreateOptions<any>) => void): void;
|
649 | public static beforeBulkDestroy(fn: (options: BulkCreateOptions<any>) => void): void;
|
650 |
|
651 | |
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 | public static afterBulkDestroy(name: string, fn: (options: DestroyOptions<any>) => void): void;
|
658 | public static afterBulkDestroy(fn: (options: DestroyOptions<any>) => void): void;
|
659 |
|
660 | |
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 | public static beforeBulkUpdate(name: string, fn: (options: UpdateOptions<any>) => void): void;
|
667 | public static beforeBulkUpdate(fn: (options: UpdateOptions<any>) => void): void;
|
668 |
|
669 | |
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 | public static afterBulkUpdate(name: string, fn: (options: UpdateOptions<any>) => void): void;
|
676 | public static afterBulkUpdate(fn: (options: UpdateOptions<any>) => void): void;
|
677 |
|
678 | |
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 | public static beforeFind(name: string, fn: (options: FindOptions<any>) => void): void;
|
685 | public static beforeFind(fn: (options: FindOptions<any>) => void): void;
|
686 |
|
687 | |
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 | public static beforeConnect(name: string, fn: (options: DeepWriteable<Config>) => void): void;
|
694 | public static beforeConnect(fn: (options: DeepWriteable<Config>) => void): void;
|
695 |
|
696 | |
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 | public static afterConnect(name: string, fn: (connection: unknown, options: Config) => void): void;
|
703 | public static afterConnect(fn: (connection: unknown, options: Config) => void): void;
|
704 |
|
705 | |
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 | public static beforeDisconnect(name: string, fn: (connection: unknown) => void): void;
|
712 | public static beforeDisconnect(fn: (connection: unknown) => void): void;
|
713 |
|
714 | |
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 | public static afterDisconnect(name: string, fn: (connection: unknown) => void): void;
|
721 | public static afterDisconnect(fn: (connection: unknown) => void): void;
|
722 |
|
723 |
|
724 | |
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 | public static beforePoolAcquire(name: string, fn: (options: GetConnectionOptions) => void): void;
|
731 | public static beforePoolAcquire(fn: (options: GetConnectionOptions) => void): void;
|
732 |
|
733 | |
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 | public static afterPoolAcquire(name: string, fn: (connection: Connection, options: GetConnectionOptions) => void): void;
|
740 | public static afterPoolAcquire(fn: (connection: Connection, options: GetConnectionOptions) => void): void;
|
741 |
|
742 |
|
743 | |
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 | public static beforeFindAfterExpandIncludeAll(name: string, fn: (options: FindOptions<any>) => void): void;
|
750 | public static beforeFindAfterExpandIncludeAll(fn: (options: FindOptions<any>) => void): void;
|
751 |
|
752 | |
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 | public static beforeFindAfterOptions(name: string, fn: (options: FindOptions<any>) => void): void;
|
759 | public static beforeFindAfterOptions(fn: (options: FindOptions<any>) => void): void;
|
760 |
|
761 | |
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 | public static afterFind(
|
768 | name: string,
|
769 | fn: (instancesOrInstance: Model[] | Model | null, options: FindOptions<any>) => void
|
770 | ): void;
|
771 | public static afterFind(
|
772 | fn: (instancesOrInstance: Model[] | Model | null, options: FindOptions<any>) => void
|
773 | ): void;
|
774 |
|
775 | |
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 | public static beforeDefine<M extends Model>(
|
782 | name: string,
|
783 | fn: (attributes: ModelAttributes<M, CreationAttributes<M>>, options: ModelOptions<M>) => void
|
784 | ): void;
|
785 | public static beforeDefine<M extends Model>(
|
786 | fn: (attributes: ModelAttributes<M, CreationAttributes<M>>, options: ModelOptions<M>) => void
|
787 | ): void;
|
788 |
|
789 | |
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 | public static afterDefine(name: string, fn: (model: ModelType) => void): void;
|
796 | public static afterDefine(fn: (model: ModelType) => void): void;
|
797 |
|
798 | |
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 | public static beforeInit(name: string, fn: (config: Config, options: Options) => void): void;
|
805 | public static beforeInit(fn: (config: Config, options: Options) => void): void;
|
806 |
|
807 | |
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 | public static afterInit(name: string, fn: (sequelize: Sequelize) => void): void;
|
814 | public static afterInit(fn: (sequelize: Sequelize) => void): void;
|
815 |
|
816 | |
817 |
|
818 |
|
819 |
|
820 |
|
821 | public static beforeBulkSync(dname: string, fn: (options: SyncOptions) => HookReturn): void;
|
822 | public static beforeBulkSync(fn: (options: SyncOptions) => HookReturn): void;
|
823 |
|
824 | |
825 |
|
826 |
|
827 |
|
828 |
|
829 | public static afterBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
830 | public static afterBulkSync(fn: (options: SyncOptions) => HookReturn): void;
|
831 |
|
832 | |
833 |
|
834 |
|
835 |
|
836 |
|
837 | public static beforeSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
838 | public static beforeSync(fn: (options: SyncOptions) => HookReturn): void;
|
839 |
|
840 | |
841 |
|
842 |
|
843 |
|
844 |
|
845 | public static afterSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
846 | public static afterSync(fn: (options: SyncOptions) => HookReturn): void;
|
847 |
|
848 | |
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 | public static useCLS(namespace: object): typeof Sequelize;
|
856 |
|
857 | |
858 |
|
859 |
|
860 | public Sequelize: typeof Sequelize;
|
861 |
|
862 | |
863 |
|
864 |
|
865 | public readonly config: Config;
|
866 |
|
867 | public readonly modelManager: ModelManager;
|
868 |
|
869 | public readonly connectionManager: ConnectionManager;
|
870 |
|
871 | |
872 |
|
873 |
|
874 | public readonly models: {
|
875 | [key: string]: ModelCtor<Model>;
|
876 | };
|
877 |
|
878 | |
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 | constructor(database: string, username: string, password?: string, options?: Options);
|
908 | constructor(database: string, username: string, options?: Options);
|
909 | constructor(options?: Options);
|
910 |
|
911 | /**
|
912 | * Instantiate sequelize with an URI
|
913 | *
|
914 | * @param uri A full database URI
|
915 | * @param options See above for possible options
|
916 | */
|
917 | constructor(uri: string, options?: Options);
|
918 |
|
919 | /**
|
920 | * A hook that is run before validation
|
921 | *
|
922 | * @param name
|
923 | * @param fn A callback function that is called with instance, options
|
924 | */
|
925 | public beforeValidate(name: string, fn: (instance: Model, options: ValidationOptions) => void): void;
|
926 | public beforeValidate(fn: (instance: Model, options: ValidationOptions) => void): void;
|
927 |
|
928 | /**
|
929 | * A hook that is run after validation
|
930 | *
|
931 | * @param name
|
932 | * @param fn A callback function that is called with instance, options
|
933 | */
|
934 | public afterValidate(name: string, fn: (instance: Model, options: ValidationOptions) => void): void;
|
935 | public afterValidate(fn: (instance: Model, options: ValidationOptions) => void): void;
|
936 |
|
937 | /**
|
938 | * A hook that is run before creating a single instance
|
939 | *
|
940 | * @param name
|
941 | * @param fn A callback function that is called with attributes, options
|
942 | */
|
943 | public beforeCreate(name: string, fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
944 | public beforeCreate(fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
945 |
|
946 | /**
|
947 | * A hook that is run after creating a single instance
|
948 | *
|
949 | * @param name
|
950 | * @param fn A callback function that is called with attributes, options
|
951 | */
|
952 | public afterCreate(name: string, fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
953 | public afterCreate(fn: (attributes: Model, options: CreateOptions<any>) => void): void;
|
954 |
|
955 | /**
|
956 | * A hook that is run before destroying a single instance
|
957 | *
|
958 | * @param name
|
959 | * @param fn A callback function that is called with instance, options
|
960 | */
|
961 | public beforeDestroy(name: string, fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
962 | public beforeDestroy(fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
963 |
|
964 | /**
|
965 | * A hook that is run after destroying a single instance
|
966 | *
|
967 | * @param name
|
968 | * @param fn A callback function that is called with instance, options
|
969 | */
|
970 | public afterDestroy(name: string, fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
971 | public afterDestroy(fn: (instance: Model, options: InstanceDestroyOptions) => void): void;
|
972 |
|
973 | /**
|
974 | * A hook that is run before updating a single instance
|
975 | *
|
976 | * @param name
|
977 | * @param fn A callback function that is called with instance, options
|
978 | */
|
979 | public beforeUpdate(name: string, fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
980 | public beforeUpdate(fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
981 |
|
982 | /**
|
983 | * A hook that is run after updating a single instance
|
984 | *
|
985 | * @param name
|
986 | * @param fn A callback function that is called with instance, options
|
987 | */
|
988 | public afterUpdate(name: string, fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
989 | public afterUpdate(fn: (instance: Model, options: UpdateOptions<any>) => void): void;
|
990 |
|
991 | /**
|
992 | * A hook that is run before creating instances in bulk
|
993 | *
|
994 | * @param name
|
995 | * @param fn A callback function that is called with instances, options
|
996 | */
|
997 | public beforeBulkCreate(name: string, fn: (instances: Model[], options: BulkCreateOptions<any>) => void): void;
|
998 | public beforeBulkCreate(fn: (instances: Model[], options: BulkCreateOptions<any>) => void): void;
|
999 |
|
1000 | /**
|
1001 | * A hook that is run after creating instances in bulk
|
1002 | *
|
1003 | * @param name
|
1004 | * @param fn A callback function that is called with instances, options
|
1005 | */
|
1006 | public afterBulkCreate(name: string, fn: (instances: Model[], options: BulkCreateOptions<any>) => void): void;
|
1007 | public afterBulkCreate(fn: (instances: Model[], options: BulkCreateOptions<any>) => void): void;
|
1008 |
|
1009 | /**
|
1010 | * A hook that is run before destroying instances in bulk
|
1011 | *
|
1012 | * @param name
|
1013 | * @param fn A callback function that is called with options
|
1014 | */
|
1015 | public beforeBulkDestroy(name: string, fn: (options: BulkCreateOptions<any>) => void): void;
|
1016 | public beforeBulkDestroy(fn: (options: BulkCreateOptions<any>) => void): void;
|
1017 |
|
1018 | /**
|
1019 | * A hook that is run after destroying instances in bulk
|
1020 | *
|
1021 | * @param name
|
1022 | * @param fn A callback function that is called with options
|
1023 | */
|
1024 | public afterBulkDestroy(name: string, fn: (options: DestroyOptions<any>) => void): void;
|
1025 | public afterBulkDestroy(fn: (options: DestroyOptions<any>) => void): void;
|
1026 |
|
1027 | /**
|
1028 | * A hook that is run after updating instances in bulk
|
1029 | *
|
1030 | * @param name
|
1031 | * @param fn A callback function that is called with options
|
1032 | */
|
1033 | public beforeBulkUpdate(name: string, fn: (options: UpdateOptions<any>) => void): void;
|
1034 | public beforeBulkUpdate(fn: (options: UpdateOptions<any>) => void): void;
|
1035 |
|
1036 | /**
|
1037 | * A hook that is run after updating instances in bulk
|
1038 | *
|
1039 | * @param name
|
1040 | * @param fn A callback function that is called with options
|
1041 | */
|
1042 | public afterBulkUpdate(name: string, fn: (options: UpdateOptions<any>) => void): void;
|
1043 | public afterBulkUpdate(fn: (options: UpdateOptions<any>) => void): void;
|
1044 |
|
1045 | /**
|
1046 | * A hook that is run before a find (select) query
|
1047 | *
|
1048 | * @param name
|
1049 | * @param fn A callback function that is called with options
|
1050 | */
|
1051 | public beforeFind(name: string, fn: (options: FindOptions<any>) => void): void;
|
1052 | public beforeFind(fn: (options: FindOptions<any>) => void): void;
|
1053 |
|
1054 | /**
|
1055 | * A hook that is run before a find (select) query, after any { include: {all: ...} } options are expanded
|
1056 | *
|
1057 | * @param name
|
1058 | * @param fn A callback function that is called with options
|
1059 | */
|
1060 | public beforeFindAfterExpandIncludeAll(name: string, fn: (options: FindOptions<any>) => void): void;
|
1061 | public beforeFindAfterExpandIncludeAll(fn: (options: FindOptions<any>) => void): void;
|
1062 |
|
1063 | /**
|
1064 | * A hook that is run before a find (select) query, after all option parsing is complete
|
1065 | *
|
1066 | * @param name
|
1067 | * @param fn A callback function that is called with options
|
1068 | */
|
1069 | public beforeFindAfterOptions(name: string, fn: (options: FindOptions<any>) => void): void;
|
1070 | public beforeFindAfterOptions(fn: (options: FindOptions<any>) => void): void;
|
1071 |
|
1072 | /**
|
1073 | * A hook that is run after a find (select) query
|
1074 | *
|
1075 | * @param name
|
1076 | * @param fn A callback function that is called with instance(s), options
|
1077 | */
|
1078 | public afterFind(
|
1079 | name: string,
|
1080 | fn: (instancesOrInstance: Model[] | Model | null, options: FindOptions<any>) => void
|
1081 | ): void;
|
1082 | public afterFind(fn: (instancesOrInstance: Model[] | Model | null, options: FindOptions<any>) => void): void;
|
1083 |
|
1084 | /**
|
1085 | * A hook that is run before a define call
|
1086 | *
|
1087 | * @param name
|
1088 | * @param fn A callback function that is called with attributes, options
|
1089 | */
|
1090 | public beforeDefine(name: string, fn: (attributes: ModelAttributes<Model, any>, options: ModelOptions) => void): void;
|
1091 | public beforeDefine(fn: (attributes: ModelAttributes<Model, any>, options: ModelOptions) => void): void;
|
1092 |
|
1093 | /**
|
1094 | * A hook that is run after a define call
|
1095 | *
|
1096 | * @param name
|
1097 | * @param fn A callback function that is called with factory
|
1098 | */
|
1099 | public afterDefine(name: string, fn: (model: ModelType) => void): void;
|
1100 | public afterDefine(fn: (model: ModelType) => void): void;
|
1101 |
|
1102 | /**
|
1103 | * A hook that is run before Sequelize() call
|
1104 | *
|
1105 | * @param name
|
1106 | * @param fn A callback function that is called with config, options
|
1107 | */
|
1108 | public beforeInit(name: string, fn: (config: Config, options: Options) => void): void;
|
1109 | public beforeInit(fn: (config: Config, options: Options) => void): void;
|
1110 |
|
1111 | /**
|
1112 | * A hook that is run after Sequelize() call
|
1113 | *
|
1114 | * @param name
|
1115 | * @param fn A callback function that is called with sequelize
|
1116 | */
|
1117 | public afterInit(name: string, fn: (sequelize: Sequelize) => void): void;
|
1118 | public afterInit(fn: (sequelize: Sequelize) => void): void;
|
1119 |
|
1120 | /**
|
1121 | * A hook that is run before sequelize.sync call
|
1122 | *
|
1123 | * @param fn A callback function that is called with options passed to sequelize.sync
|
1124 | */
|
1125 | public beforeBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
1126 | public beforeBulkSync(fn: (options: SyncOptions) => HookReturn): void;
|
1127 |
|
1128 | /**
|
1129 | * A hook that is run after sequelize.sync call
|
1130 | *
|
1131 | * @param fn A callback function that is called with options passed to sequelize.sync
|
1132 | */
|
1133 | public afterBulkSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
1134 | public afterBulkSync(fn: (options: SyncOptions) => HookReturn): void;
|
1135 |
|
1136 | /**
|
1137 | * A hook that is run before Model.sync call
|
1138 | *
|
1139 | * @param fn A callback function that is called with options passed to Model.sync
|
1140 | */
|
1141 | public beforeSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
1142 | public beforeSync(fn: (options: SyncOptions) => HookReturn): void;
|
1143 |
|
1144 | /**
|
1145 | * A hook that is run after Model.sync call
|
1146 | *
|
1147 | * @param fn A callback function that is called with options passed to Model.sync
|
1148 | */
|
1149 | public afterSync(name: string, fn: (options: SyncOptions) => HookReturn): void;
|
1150 | public afterSync(fn: (options: SyncOptions) => HookReturn): void;
|
1151 |
|
1152 | /**
|
1153 | * Returns the specified dialect.
|
1154 | */
|
1155 | public getDialect(): string;
|
1156 |
|
1157 | /**
|
1158 | * Returns the database name.
|
1159 | */
|
1160 |
|
1161 | public getDatabaseName(): string;
|
1162 |
|
1163 | /**
|
1164 | * Returns an instance of QueryInterface.
|
1165 | */
|
1166 | public getQueryInterface(): QueryInterface;
|
1167 |
|
1168 | /**
|
1169 | * Define a new model, representing a table in the DB.
|
1170 | *
|
1171 | * The table columns are defined by the hash that is given as the second argument. Each attribute of the
|
1172 | * hash
|
1173 | * represents a column. A short table definition might look like this:
|
1174 | *
|
1175 | * ```js
|
1176 | * class MyModel extends Model {}
|
1177 | * MyModel.init({
|
1178 | * columnA: {
|
1179 | * type: Sequelize.BOOLEAN,
|
1180 | * validate: {
|
1181 | * is: ["[a-z]",'i'],
|
1182 | * max: 23,
|
1183 | * isIn: {
|
1184 | * args: [['en', 'zh']],
|
1185 | * msg: "Must be English or Chinese"
|
1186 | * }
|
1187 | * },
|
1188 | * field: 'column_a'
|
1189 | *
|
1190 | * },
|
1191 | * columnB: Sequelize.STRING,
|
1192 | * columnC: 'MY VERY OWN COLUMN TYPE'
|
1193 | * }, { sequelize })
|
1194 | *
|
1195 | * sequelize.models.modelName // The model will now be available in models under the name given to define
|
1196 | * ```
|
1197 | *
|
1198 | * As shown above, column definitions can be either strings, a reference to one of the datatypes that are
|
1199 | * predefined on the Sequelize constructor, or an object that allows you to specify both the type of the
|
1200 | * column, and other attributes such as default values, foreign key constraints and custom setters and
|
1201 | * getters.
|
1202 | *
|
1203 | * For a list of possible data types, see
|
1204 | * https://sequelize.org/master/en/latest/docs/models-definition/#data-types
|
1205 | *
|
1206 | * For more about getters and setters, see
|
1207 | * https://sequelize.org/master/en/latest/docs/models-definition/#getters-setters
|
1208 | *
|
1209 | * For more about instance and class methods, see
|
1210 | * https://sequelize.org/master/en/latest/docs/models-definition/#expansion-of-models
|
1211 | *
|
1212 | * For more about validation, see
|
1213 | * https://sequelize.org/master/en/latest/docs/models-definition/#validations
|
1214 | *
|
1215 | * @param modelName The name of the model. The model will be stored in `sequelize.models` under this name
|
1216 | * @param attributes An object, where each attribute is a column of the table. Each column can be either a
|
1217 | * DataType, a string or a type-description object, with the properties described below:
|
1218 | * @param options These options are merged with the default define options provided to the Sequelize
|
1219 | * constructor
|
1220 | */
|
1221 | public define<M extends Model, TAttributes = Attributes<M>>(
|
1222 | modelName: string,
|
1223 | attributes: ModelAttributes<M, TAttributes>,
|
1224 | options?: ModelOptions<M>
|
1225 | ): ModelCtor<M>;
|
1226 |
|
1227 | /**
|
1228 | * Fetch a Model which is already defined
|
1229 | *
|
1230 | * @param modelName The name of a model defined with Sequelize.define
|
1231 | */
|
1232 | public model(modelName: string): ModelCtor<Model>;
|
1233 |
|
1234 | /**
|
1235 | * Checks whether a model with the given name is defined
|
1236 | *
|
1237 | * @param modelName The name of a model defined with Sequelize.define
|
1238 | */
|
1239 | public isDefined(modelName: string): boolean;
|
1240 |
|
1241 | /**
|
1242 | * Execute a query on the DB, optionally bypassing all the Sequelize goodness.
|
1243 | *
|
1244 | * By default, the function will return two arguments: an array of results, and a metadata object,
|
1245 | * containing number of affected rows etc. Use `const [results, meta] = await ...` to access the results.
|
1246 | *
|
1247 | * If you are running a type of query where you don't need the metadata, for example a `SELECT` query, you
|
1248 | * can pass in a query type to make sequelize format the results:
|
1249 | *
|
1250 | * ```js
|
1251 | * const [results, metadata] = await sequelize.query('SELECT...'); // Raw query - use array destructuring
|
1252 | *
|
1253 | * const results = await sequelize.query('SELECT...', { type: sequelize.QueryTypes.SELECT }); // SELECT query - no destructuring
|
1254 | * ```
|
1255 | *
|
1256 | * @param sql
|
1257 | * @param options Query options
|
1258 | */
|
1259 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.UPDATE>): Promise<[undefined, number]>;
|
1260 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.BULKUPDATE>): Promise<number>;
|
1261 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.INSERT>): Promise<[number, number]>;
|
1262 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.UPSERT>): Promise<number>;
|
1263 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.DELETE>): Promise<void>;
|
1264 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.BULKDELETE>): Promise<number>;
|
1265 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SHOWTABLES>): Promise<string[]>;
|
1266 | public query(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.DESCRIBE>): Promise<ColumnsDescription>;
|
1267 | public query<M extends Model>(
|
1268 | sql: string | { query: string; values: unknown[] },
|
1269 | options: QueryOptionsWithModel<M> & { plain: true }
|
1270 | ): Promise<M | null>;
|
1271 | public query<M extends Model>(
|
1272 | sql: string | { query: string; values: unknown[] },
|
1273 | options: QueryOptionsWithModel<M>
|
1274 | ): Promise<M[]>;
|
1275 | public query<T extends object>(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SELECT> & { plain: true }): Promise<T | null>;
|
1276 | public query<T extends object>(sql: string | { query: string; values: unknown[] }, options: QueryOptionsWithType<QueryTypes.SELECT>): Promise<T[]>;
|
1277 | public query(sql: string | { query: string; values: unknown[] }, options: (QueryOptions | QueryOptionsWithType<QueryTypes.RAW>) & { plain: true }): Promise<{ [key: string]: unknown } | null>;
|
1278 | public query(sql: string | { query: string; values: unknown[] }, options?: QueryOptions | QueryOptionsWithType<QueryTypes.RAW>): Promise<[unknown[], unknown]>;
|
1279 |
|
1280 | /**
|
1281 | * Get the fn for random based on the dialect
|
1282 | */
|
1283 | public random(): Fn;
|
1284 |
|
1285 | /**
|
1286 | * Execute a query which would set an environment or user variable. The variables are set per connection,
|
1287 | * so this function needs a transaction.
|
1288 | *
|
1289 | * Only works for MySQL.
|
1290 | *
|
1291 | * @param variables object with multiple variables.
|
1292 | * @param options Query options.
|
1293 | */
|
1294 | public set(variables: object, options: QueryOptionsTransactionRequired): Promise<unknown>;
|
1295 |
|
1296 | /**
|
1297 | * Escape value.
|
1298 | *
|
1299 | * @param value Value that needs to be escaped
|
1300 | */
|
1301 | public escape(value: string | number | Date): string;
|
1302 |
|
1303 | /**
|
1304 | * Create a new database schema.
|
1305 | *
|
1306 | * Note,that this is a schema in the
|
1307 | * [postgres sense of the word](http:
|
1308 | * not a database table. In mysql and sqlite, this command will do nothing.
|
1309 | *
|
1310 | * @param schema Name of the schema
|
1311 | * @param options Options supplied
|
1312 | */
|
1313 | public createSchema(schema: string, options: Logging): Promise<unknown>;
|
1314 |
|
1315 | |
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 | public showAllSchemas(options: Logging): Promise<object[]>;
|
1325 |
|
1326 | |
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 | public dropSchema(schema: string, options: Logging): Promise<unknown[]>;
|
1337 |
|
1338 | |
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 | public dropAllSchemas(options: Logging): Promise<unknown[]>;
|
1348 |
|
1349 | |
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 | public sync(options?: SyncOptions): Promise<this>;
|
1355 |
|
1356 | |
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 | public truncate(options?: DestroyOptions<any>): Promise<unknown[]>;
|
1363 |
|
1364 | |
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 | public drop(options?: DropOptions): Promise<unknown[]>;
|
1370 |
|
1371 | |
1372 |
|
1373 |
|
1374 |
|
1375 |
|
1376 | public authenticate(options?: QueryOptions): Promise<void>;
|
1377 | public validate(options?: QueryOptions): Promise<void>;
|
1378 |
|
1379 | |
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 |
|
1389 |
|
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 | public transaction<T>(options: TransactionOptions, autoCallback: (t: Transaction) => PromiseLike<T>): Promise<T>;
|
1427 | public transaction<T>(autoCallback: (t: Transaction) => PromiseLike<T>): Promise<T>;
|
1428 | public transaction(options?: TransactionOptions): Promise<Transaction>;
|
1429 |
|
1430 | |
1431 |
|
1432 |
|
1433 |
|
1434 |
|
1435 |
|
1436 |
|
1437 | public close(): Promise<void>;
|
1438 |
|
1439 | |
1440 |
|
1441 |
|
1442 | public databaseVersion(): Promise<string>;
|
1443 | }
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 | export function fn(fn: string, ...args: unknown[]): Fn;
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 | export function col(col: string): Col;
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 | export function cast(val: unknown, type: string): Cast;
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 | export function literal(val: string): Literal;
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 | export function and<T extends Array<any>>(...args: T): { [Op.and]: T };
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 | export function or<T extends Array<any>>(...args: T): { [Op.or]: T };
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 | export function json(conditionsOrPath: string | object, value?: string | number | boolean): Json;
|
1511 |
|
1512 | export type WhereLeftOperand = Fn | ColumnReference | Literal | Cast | ModelAttributeColumnOptions;
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 | export type AttributeType = WhereLeftOperand;
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 | export type LogicType = Fn | Col | Literal | OrOperator<any> | AndOperator<any> | WhereOperators | string | symbol | null;
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 | export function where<Op extends keyof WhereOperators>(leftOperand: WhereLeftOperand | Where, operator: Op, rightOperand: WhereOperators[Op]): Where;
|
1562 | export function where<Op extends keyof WhereOperators>(leftOperand: any, operator: string, rightOperand: any): Where;
|
1563 | export function where(leftOperand: WhereLeftOperand, rightOperand: WhereAttributeHashValue<any>): Where;
|
1564 |
|
1565 | export default Sequelize;
|
1566 |
|
\ | No newline at end of file |