-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
column.go
86 lines (76 loc) · 1.71 KB
/
column.go
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
package rel
// ColumnType definition.
type ColumnType string
const (
// ID ColumnType.
ID ColumnType = "ID"
// BigID ColumnType.
BigID ColumnType = "BigID"
// Bool ColumnType.
Bool ColumnType = "BOOL"
// SmallInt ColumnType.
SmallInt ColumnType = "SMALLINT"
// Int ColumnType.
Int ColumnType = "INT"
// BigInt ColumnType.
BigInt ColumnType = "BIGINT"
// Float ColumnType.
Float ColumnType = "FLOAT"
// Decimal ColumnType.
Decimal ColumnType = "DECIMAL"
// String ColumnType.
String ColumnType = "STRING"
// Text ColumnType.
Text ColumnType = "TEXT"
// JSON ColumnType that will fallback to Text ColumnType if adapter does not support it.
JSON ColumnType = "JSON"
// Date ColumnType.
Date ColumnType = "DATE"
// DateTime ColumnType.
DateTime ColumnType = "DATETIME"
// Time ColumnType.
Time ColumnType = "TIME"
)
// Column definition.
type Column struct {
Op SchemaOp
Name string
Type ColumnType
Rename string
Primary bool
Unique bool
Required bool
Unsigned bool
Limit int
Precision int
Scale int
Default any
Options string
}
func (Column) internalTableDefinition() {}
func createColumn(name string, typ ColumnType, options []ColumnOption) Column {
column := Column{
Op: SchemaCreate,
Name: name,
Type: typ,
}
applyColumnOptions(&column, options)
return column
}
func renameColumn(name string, newName string, options []ColumnOption) Column {
column := Column{
Op: SchemaRename,
Name: name,
Rename: newName,
}
applyColumnOptions(&column, options)
return column
}
func dropColumn(name string, options []ColumnOption) Column {
column := Column{
Op: SchemaDrop,
Name: name,
}
applyColumnOptions(&column, options)
return column
}