UNPKG

3.45 kBTypeScriptView Raw
1/**
2 * Can be used to
3 * make foreign key constraints deferrable and to set the constaints within a
4 * transaction. This is only supported in PostgreSQL.
5 *
6 * The foreign keys can be configured like this. It will create a foreign key
7 * that will check the constraints immediately when the data was inserted.
8 *
9 * ```js
10 * class MyModel extends Model {}
11 * MyModel.init({
12 * foreign_id: {
13 * type: Sequelize.INTEGER,
14 * references: {
15 * model: OtherModel,
16 * key: 'id',
17 * deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE
18 * }
19 * }
20 * }, { sequelize });
21 * ```
22 *
23 * The constraints can be configured in a transaction like this. It will
24 * trigger a query once the transaction has been started and set the constraints
25 * to be checked at the very end of the transaction.
26 *
27 * ```js
28 * sequelize.transaction({
29 * deferrable: Sequelize.Deferrable.SET_DEFERRED
30 * });
31 * ```
32 */
33
34/**
35 *
36 */
37export interface AbstractDeferrableStatic {
38 new (): Deferrable;
39 (): Deferrable;
40}
41export interface Deferrable {
42 toString(): string;
43 toSql(): string;
44}
45
46export interface InitiallyDeferredDeferrableStatic extends AbstractDeferrableStatic {
47 new (): InitiallyDeferredDeferrable;
48 (): InitiallyDeferredDeferrable;
49}
50export interface InitiallyDeferredDeferrable extends Deferrable {}
51export const INITIALLY_DEFERRED: InitiallyDeferredDeferrableStatic;
52
53export interface InitiallyImmediateDeferrableStatic extends AbstractDeferrableStatic {
54 new (): InitiallyImmediateDeferrable;
55 (): InitiallyImmediateDeferrable;
56}
57export interface InitiallyImmediateDeferrable extends Deferrable {}
58export const INITIALLY_IMMEDIATE: InitiallyImmediateDeferrableStatic;
59
60export interface NotDeferrableStatic extends AbstractDeferrableStatic {
61 new (): NotDeferrable;
62 (): NotDeferrable;
63}
64export interface NotDeferrable extends Deferrable {}
65/**
66 * Will set the constraints to not deferred. This is the default in PostgreSQL and it make
67 * it impossible to dynamically defer the constraints within a transaction.
68 */
69export const NOT: NotDeferrableStatic;
70
71export interface SetDeferredDeferrableStatic extends AbstractDeferrableStatic {
72 /**
73 * @param constraints An array of constraint names. Will defer all constraints by default.
74 */
75 new (constraints: string[]): SetDeferredDeferrable;
76 /**
77 * @param constraints An array of constraint names. Will defer all constraints by default.
78 */
79 (constraints: string[]): SetDeferredDeferrable;
80}
81export interface SetDeferredDeferrable extends Deferrable {}
82/**
83 * Will trigger an additional query at the beginning of a
84 * transaction which sets the constraints to deferred.
85 */
86export const SET_DEFERRED: SetDeferredDeferrableStatic;
87
88export interface SetImmediateDeferrableStatic extends AbstractDeferrableStatic {
89 /**
90 * @param constraints An array of constraint names. Will defer all constraints by default.
91 */
92 new (constraints: string[]): SetImmediateDeferrable;
93 /**
94 * @param constraints An array of constraint names. Will defer all constraints by default.
95 */
96 (constraints: string[]): SetImmediateDeferrable;
97}
98export interface SetImmediateDeferrable extends Deferrable {}
99/**
100 * Will trigger an additional query at the beginning of a
101 * transaction which sets the constraints to immediately.
102 *
103 * @param constraints An array of constraint names. Will defer all constraints by default.
104 */
105export const SET_IMMEDIATE: SetImmediateDeferrableStatic;