-
Notifications
You must be signed in to change notification settings - Fork 280
/
update-query-node.ts
51 lines (46 loc) · 1.53 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
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 { TableExpressionNode } from './operation-node-utils.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'
export type UpdateValuesNode = ValueListNode | PrimitiveValueListNode
export interface UpdateQueryNode extends OperationNode {
readonly kind: 'UpdateQueryNode'
readonly table: TableExpressionNode
readonly joins?: ReadonlyArray<JoinNode>
readonly where?: WhereNode
readonly updates?: ReadonlyArray<ColumnUpdateNode>
readonly returning?: ReturningNode
readonly with?: WithNode
}
/**
* @internal
*/
export const UpdateQueryNode = freeze({
is(node: OperationNode): node is UpdateQueryNode {
return node.kind === 'UpdateQueryNode'
},
create(table: TableExpressionNode, withNode?: WithNode): UpdateQueryNode {
return {
kind: 'UpdateQueryNode',
table,
...(withNode && { with: withNode }),
}
},
cloneWithUpdates(
updateQuery: UpdateQueryNode,
updates: ReadonlyArray<ColumnUpdateNode>
): UpdateQueryNode {
return freeze({
...updateQuery,
updates: updateQuery.updates
? freeze([...updateQuery.updates, ...updates])
: updates,
})
},
})