diff options
author | Unknwon <u@gogs.io> | 2017-02-09 19:48:13 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-02-09 19:48:13 -0500 |
commit | 2fd69f13d9599a6c58b47225565163fd7d87889f (patch) | |
tree | fd19e868e1c2e95a5fb83a268f6e393669d6ee79 /vendor/github.com/go-xorm/core/index.go | |
parent | eb66060cd7b9bce996b1d75ae80ce1ef31d5ce62 (diff) |
vendor: check in vendors
Bye bye glide...
Diffstat (limited to 'vendor/github.com/go-xorm/core/index.go')
-rw-r--r-- | vendor/github.com/go-xorm/core/index.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/github.com/go-xorm/core/index.go b/vendor/github.com/go-xorm/core/index.go new file mode 100644 index 00000000..73b95175 --- /dev/null +++ b/vendor/github.com/go-xorm/core/index.go @@ -0,0 +1,61 @@ +package core + +import ( + "fmt" + "sort" + "strings" +) + +const ( + IndexType = iota + 1 + UniqueType +) + +// database index +type Index struct { + IsRegular bool + Name string + Type int + Cols []string +} + +func (index *Index) XName(tableName string) string { + if !strings.HasPrefix(index.Name, "UQE_") && + !strings.HasPrefix(index.Name, "IDX_") { + if index.Type == UniqueType { + return fmt.Sprintf("UQE_%v_%v", tableName, index.Name) + } + return fmt.Sprintf("IDX_%v_%v", tableName, index.Name) + } + return index.Name +} + +// add columns which will be composite index +func (index *Index) AddColumn(cols ...string) { + for _, col := range cols { + index.Cols = append(index.Cols, col) + } +} + +func (index *Index) Equal(dst *Index) bool { + if index.Type != dst.Type { + return false + } + if len(index.Cols) != len(dst.Cols) { + return false + } + sort.StringSlice(index.Cols).Sort() + sort.StringSlice(dst.Cols).Sort() + + for i := 0; i < len(index.Cols); i++ { + if index.Cols[i] != dst.Cols[i] { + return false + } + } + return true +} + +// new an index +func NewIndex(name string, indexType int) *Index { + return &Index{true, name, indexType, make([]string, 0)} +} |