-
Notifications
You must be signed in to change notification settings - Fork 232
/
spec.go
37 lines (33 loc) · 974 Bytes
/
spec.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
package specutil
import (
"ariga.io/atlas/schema/schemaspec"
"ariga.io/atlas/sql/sqlspec"
)
// NewCol is a helper method for constructing *sqlspec.Column instances.
func NewCol(name, coltype string, attrs ...*schemaspec.Attr) *sqlspec.Column {
return &sqlspec.Column{
Name: name,
TypeName: coltype,
DefaultExtension: schemaspec.DefaultExtension{
Extra: schemaspec.Resource{Attrs: attrs},
},
}
}
// LitAttr is a helper method for constructing *schemaspec.Attr instances that contain literal values.
func LitAttr(k, v string) *schemaspec.Attr {
return &schemaspec.Attr{
K: k,
V: &schemaspec.LiteralValue{V: v},
}
}
// ListAttr is a helper method for constructing *schemaspec.Attr instances that contain list values.
func ListAttr(k string, litValues ...string) *schemaspec.Attr {
lv := &schemaspec.ListValue{}
for _, v := range litValues {
lv.V = append(lv.V, &schemaspec.LiteralValue{V: v})
}
return &schemaspec.Attr{
K: k,
V: lv,
}
}