From 2fd69f13d9599a6c58b47225565163fd7d87889f Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 9 Feb 2017 19:48:13 -0500 Subject: vendor: check in vendors Bye bye glide... --- vendor/github.com/go-xorm/core/index.go | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 vendor/github.com/go-xorm/core/index.go (limited to 'vendor/github.com/go-xorm/core/index.go') 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)} +} -- cgit v1.2.3