github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/app/lib/schema/model/index.go (about) 1 // Package model - Content managed by Project Forge, see [projectforge.md] for details. 2 package model 3 4 import ( 5 "strings" 6 7 "github.com/samber/lo" 8 9 "github.com/kyleu/dbaudit/app/lib/schema/field" 10 ) 11 12 type Index struct { 13 Key string `json:"key"` 14 Fields []string `json:"type"` 15 Unique bool `json:"unique,omitempty"` 16 Primary bool `json:"primary,omitempty"` 17 Metadata *field.Metadata `json:"metadata,omitempty"` 18 } 19 20 func (i Index) String() string { 21 return i.Key + "(" + strings.Join(i.Fields, ", ") + ")" 22 } 23 24 type Indexes []*Index 25 26 func (s Indexes) Get(key string) *Index { 27 return lo.FindOrElse(s, nil, func(x *Index) bool { 28 return x.Key == key 29 }) 30 }