-
Notifications
You must be signed in to change notification settings - Fork 280
/
column-definition-node.ts
58 lines (53 loc) · 1.6 KB
/
column-definition-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
import { freeze } from '../util/object-utils.js'
import { CheckConstraintNode } from './check-constraint-node.js'
import { ColumnNode } from './column-node.js'
import { DataTypeNode } from './data-type-node.js'
import { OperationNode } from './operation-node.js'
import { RawNode } from './raw-node.js'
import { ReferencesNode } from './references-node.js'
import { ValueNode } from './value-node.js'
export type ColumnDefinitionNodeProps = Omit<
Partial<ColumnDefinitionNode>,
'kind'
>
export type ColumnDataTypeNode = DataTypeNode | RawNode
export interface ColumnDefinitionNode extends OperationNode {
readonly kind: 'ColumnDefinitionNode'
readonly column: ColumnNode
readonly dataType: ColumnDataTypeNode
readonly references?: ReferencesNode
readonly isPrimaryKey: boolean
readonly isAutoIncrementing: boolean
readonly isUnique: boolean
readonly isNullable: boolean
readonly defaultTo?: ValueNode | RawNode
readonly check?: CheckConstraintNode
}
/**
* @internal
*/
export const ColumnDefinitionNode = freeze({
is(node: OperationNode): node is ColumnDefinitionNode {
return node.kind === 'ColumnDefinitionNode'
},
create(column: string, dataType: ColumnDataTypeNode): ColumnDefinitionNode {
return freeze({
kind: 'ColumnDefinitionNode',
column: ColumnNode.create(column),
dataType,
isPrimaryKey: false,
isAutoIncrementing: false,
isUnique: false,
isNullable: true,
})
},
cloneWith(
node: ColumnDefinitionNode,
props: ColumnDefinitionNodeProps
): ColumnDefinitionNode {
return freeze({
...node,
...props,
})
},
})