/
foreign-key-constraint-error.ts
43 lines (37 loc) · 1.17 KB
/
foreign-key-constraint-error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { DatabaseErrorSubclassOptions } from '../database-error';
import DatabaseError from '../database-error';
export enum RelationshipType {
parent = 'parent',
child = 'child',
}
interface ForeignKeyConstraintErrorOptions {
table?: string;
fields?: { [field: string]: string };
value?: unknown;
index?: string;
reltype?: RelationshipType;
}
/**
* Thrown when a foreign key constraint is violated in the database
*/
class ForeignKeyConstraintError extends DatabaseError {
table: string | undefined;
fields: { [field: string]: string } | undefined;
value: unknown;
index: string | undefined;
reltype: RelationshipType | undefined;
constructor(
options: ForeignKeyConstraintErrorOptions & DatabaseErrorSubclassOptions,
) {
options = options || {};
options.parent = options.parent || { sql: '', name: '', message: '' };
super(options.parent, { stack: options.stack });
this.name = 'SequelizeForeignKeyConstraintError';
this.fields = options.fields;
this.table = options.table;
this.value = options.value;
this.index = options.index;
this.reltype = options.reltype;
}
}
export default ForeignKeyConstraintError;