forked from go-gorp/gorp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.go
47 lines (39 loc) · 1.25 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
// Copyright 2012 James Cooper. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package borp
// IndexMap represents a mapping between a Go struct field and a single
// index in a table.
// Unique and MaxSize only inform the
// CreateTables() function and are not used by Insert/Update/Delete/Get.
type IndexMap struct {
// Index name in db table
IndexName string
// If true, " unique" is added to create index statements.
// Not used elsewhere
Unique bool
// Index type supported by Dialect
// Mysql: Btree, Hash.
// Sqlite: nil.
IndexType string
// Columns name for single and multiple indexes
columns []string
}
// Rename allows you to specify the index name in the table
//
// Example: table.IndMap("customer_test_idx").Rename("customer_idx")
func (idx *IndexMap) Rename(indname string) *IndexMap {
idx.IndexName = indname
return idx
}
// SetUnique adds "unique" to the create index statements for this
// index, if b is true.
func (idx *IndexMap) SetUnique(b bool) *IndexMap {
idx.Unique = b
return idx
}
// SetIndexType specifies the index type supported by chousen SQL Dialect
func (idx *IndexMap) SetIndexType(indtype string) *IndexMap {
idx.IndexType = indtype
return idx
}