-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
index.go
67 lines (55 loc) · 1.32 KB
/
index.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
package rel
// Index definition.
type Index struct {
Op SchemaOp
Table string
Name string
Unique bool
Columns []string
Optional bool
Filter FilterQuery
Options string
}
func (i Index) description() string {
return i.Op.String() + " index " + i.Name + " on " + i.Table
}
func (Index) internalMigration() {}
func createIndex(table string, name string, columns []string, options []IndexOption) Index {
index := Index{
Op: SchemaCreate,
Table: table,
Name: name,
Columns: columns,
}
applyIndexOptions(&index, options)
return index
}
func createUniqueIndex(table string, name string, columns []string, options []IndexOption) Index {
index := createIndex(table, name, columns, options)
index.Unique = true
return index
}
func dropIndex(table string, name string, options []IndexOption) Index {
index := Index{
Op: SchemaDrop,
Table: table,
Name: name,
}
applyIndexOptions(&index, options)
return index
}
// IndexOption interface.
// Available options are: Comment, Options.
type IndexOption interface {
applyIndex(index *Index)
}
func applyIndexOptions(index *Index, options []IndexOption) {
for i := range options {
options[i].applyIndex(index)
}
}
// Name option for defining custom index name.
type Name string
func (n Name) applyKey(key *Key) {
key.Name = string(n)
}