-
Notifications
You must be signed in to change notification settings - Fork 280
/
update-query-node.ts
76 lines (69 loc) · 2.08 KB
/
update-query-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
import { freeze } from '../util/object-utils.js'
import { ColumnUpdateNode } from './column-update-node.js'
import { JoinNode } from './join-node.js'
import { OperationNode } from './operation-node.js'
import { PrimitiveValueListNode } from './primitive-value-list-node.js'
import { ReturningNode } from './returning-node.js'
import { ValueListNode } from './value-list-node.js'
import { WhereNode } from './where-node.js'
import { WithNode } from './with-node.js'
import { FromNode } from './from-node.js'
import { ExplainNode } from './explain-node.js'
export type UpdateValuesNode = ValueListNode | PrimitiveValueListNode
export interface UpdateQueryNode extends OperationNode {
readonly kind: 'UpdateQueryNode'
readonly table: OperationNode
readonly from?: FromNode
readonly joins?: ReadonlyArray<JoinNode>
readonly where?: WhereNode
readonly updates?: ReadonlyArray<ColumnUpdateNode>
readonly returning?: ReturningNode
readonly with?: WithNode
readonly explain?: ExplainNode
}
/**
* @internal
*/
export const UpdateQueryNode = freeze({
is(node: OperationNode): node is UpdateQueryNode {
return node.kind === 'UpdateQueryNode'
},
create(table: OperationNode, withNode?: WithNode): UpdateQueryNode {
return freeze({
kind: 'UpdateQueryNode',
table,
...(withNode && { with: withNode }),
})
},
cloneWithFromItems(
updateQuery: UpdateQueryNode,
fromItems: ReadonlyArray<OperationNode>
): UpdateQueryNode {
return freeze({
...updateQuery,
from: updateQuery.from
? FromNode.cloneWithFroms(updateQuery.from, fromItems)
: FromNode.create(fromItems),
})
},
cloneWithUpdates(
updateQuery: UpdateQueryNode,
updates: ReadonlyArray<ColumnUpdateNode>
): UpdateQueryNode {
return freeze({
...updateQuery,
updates: updateQuery.updates
? freeze([...updateQuery.updates, ...updates])
: updates,
})
},
cloneWithExplain(
updateQuery: UpdateQueryNode,
explain: ExplainNode
): UpdateQueryNode {
return freeze({
...updateQuery,
explain,
})
},
})