-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathreferences-node.ts
56 lines (50 loc) · 1.25 KB
/
references-node.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
44
45
46
47
48
49
50
51
52
53
54
55
56
import { OperationNode } from './operation-node.js'
import { ColumnNode } from './column-node.js'
import { TableNode } from './table-node.js'
import { freeze } from '../util/object-utils.js'
export type OnModifyForeignAction =
| 'no action'
| 'restrict'
| 'cascade'
| 'set null'
| 'set default'
export interface ReferencesNode extends OperationNode {
readonly kind: 'ReferencesNode'
readonly table: TableNode
readonly columns: ReadonlyArray<ColumnNode>
readonly onDelete?: OnModifyForeignAction
readonly onUpdate?: OnModifyForeignAction
}
/**
* @internal
*/
export const ReferencesNode = freeze({
is(node: OperationNode): node is ReferencesNode {
return node.kind === 'ReferencesNode'
},
create(table: TableNode, columns: ReadonlyArray<ColumnNode>): ReferencesNode {
return freeze({
kind: 'ReferencesNode',
table,
columns: freeze([...columns]),
})
},
cloneWithOnDelete(
references: ReferencesNode,
onDelete: OnModifyForeignAction
): ReferencesNode {
return freeze({
...references,
onDelete,
})
},
cloneWithOnUpdate(
references: ReferencesNode,
onUpdate: OnModifyForeignAction
): ReferencesNode {
return freeze({
...references,
onUpdate,
})
},
})