-
Notifications
You must be signed in to change notification settings - Fork 280
/
alter-table-node.ts
71 lines (64 loc) · 1.98 KB
/
alter-table-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
import { OperationNode } from './operation-node.js'
import { freeze } from '../util/object-utils.js'
import { AddColumnNode } from './add-column-node.js'
import { DropColumnNode } from './drop-column-node.js'
import { TableNode } from './table-node.js'
import { IdentifierNode } from './identifier-node.js'
import { RenameColumnNode } from './rename-column-node.js'
import { AlterColumnNode } from './alter-column-node.js'
import { AddConstraintNode } from './add-constraint-node.js'
import { DropConstraintNode } from './drop-constraint-node.js'
import { ModifyColumnNode } from './modify-column-node.js'
export type AlterTableNodeTableProps = Pick<
AlterTableNode,
'renameTo' | 'setSchema' | 'addConstraint' | 'dropConstraint'
>
export type AlterTableColumnAlterationNode =
| RenameColumnNode
| AddColumnNode
| DropColumnNode
| AlterColumnNode
| ModifyColumnNode
export interface AlterTableNode extends OperationNode {
readonly kind: 'AlterTableNode'
readonly table: TableNode
readonly renameTo?: TableNode
readonly setSchema?: IdentifierNode
readonly columnAlterations?: ReadonlyArray<AlterTableColumnAlterationNode>
readonly addConstraint?: AddConstraintNode
readonly dropConstraint?: DropConstraintNode
}
/**
* @internal
*/
export const AlterTableNode = freeze({
is(node: OperationNode): node is AlterTableNode {
return node.kind === 'AlterTableNode'
},
create(table: string): AlterTableNode {
return freeze({
kind: 'AlterTableNode',
table: TableNode.create(table),
})
},
cloneWithTableProps(
node: AlterTableNode,
props: AlterTableNodeTableProps
): AlterTableNode {
return freeze({
...node,
...props,
})
},
cloneWithColumnAlteration(
node: AlterTableNode,
columnAlteration: AlterTableColumnAlterationNode
): AlterTableNode {
return freeze({
...node,
columnAlterations: node.columnAlterations
? [...node.columnAlterations, columnAlteration]
: [columnAlteration],
})
},
})