-
Notifications
You must be signed in to change notification settings - Fork 280
/
on-conflict-node.ts
92 lines (83 loc) · 2.31 KB
/
on-conflict-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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { freeze } from '../util/object-utils.js'
import { ColumnNode } from './column-node.js'
import { ColumnUpdateNode } from './column-update-node.js'
import { IdentifierNode } from './identifier-node.js'
import { OperationNode } from './operation-node.js'
import { WhereNode } from './where-node.js'
export type OnConflictNodeProps = Omit<
OnConflictNode,
'kind' | 'indexWhere' | 'updateWhere'
>
export interface OnConflictNode extends OperationNode {
readonly kind: 'OnConflictNode'
readonly columns?: ReadonlyArray<ColumnNode>
readonly constraint?: IdentifierNode
readonly indexExpression?: OperationNode
readonly indexWhere?: WhereNode
readonly updates?: ReadonlyArray<ColumnUpdateNode>
readonly updateWhere?: WhereNode
readonly doNothing?: boolean
}
/**
* @internal
*/
export const OnConflictNode = freeze({
is(node: OperationNode): node is OnConflictNode {
return node.kind === 'OnConflictNode'
},
create(): OnConflictNode {
return freeze({
kind: 'OnConflictNode',
})
},
cloneWith(node: OnConflictNode, props: OnConflictNodeProps): OnConflictNode {
return freeze({
...node,
...props,
})
},
cloneWithIndexWhere(
node: OnConflictNode,
operation: OperationNode
): OnConflictNode {
return freeze({
...node,
indexWhere: node.indexWhere
? WhereNode.cloneWithOperation(node.indexWhere, 'And', operation)
: WhereNode.create(operation),
})
},
cloneWithIndexOrWhere(
node: OnConflictNode,
operation: OperationNode
): OnConflictNode {
return freeze({
...node,
indexWhere: node.indexWhere
? WhereNode.cloneWithOperation(node.indexWhere, 'Or', operation)
: WhereNode.create(operation),
})
},
cloneWithUpdateWhere(
node: OnConflictNode,
operation: OperationNode
): OnConflictNode {
return freeze({
...node,
updateWhere: node.updateWhere
? WhereNode.cloneWithOperation(node.updateWhere, 'And', operation)
: WhereNode.create(operation),
})
},
cloneWithUpdateOrWhere(
node: OnConflictNode,
operation: OperationNode
): OnConflictNode {
return freeze({
...node,
updateWhere: node.updateWhere
? WhereNode.cloneWithOperation(node.updateWhere, 'Or', operation)
: WhereNode.create(operation),
})
},
})