MCPcopy
hub / github.com/go-gorm/gorm / HasIndex

Method HasIndex

migrator/migrator.go:883–900  ·  view source on GitHub ↗

HasIndex check has index `name` or not

(value interface{}, name string)

Source from the content-addressed store, hash-verified

881
882// HasIndex check has index `name` or not
883func (m Migrator) HasIndex(value interface{}, name string) bool {
884 var count int64
885 m.RunWithValue(value, func(stmt *gorm.Statement) error {
886 currentDatabase := m.DB.Migrator().CurrentDatabase()
887 if stmt.Schema != nil {
888 if idx := stmt.Schema.LookIndex(name); idx != nil {
889 name = idx.Name
890 }
891 }
892
893 return m.DB.Raw(
894 "SELECT count(*) FROM information_schema.statistics WHERE table_schema = ? AND table_name = ? AND index_name = ?",
895 currentDatabase, stmt.Table, name,
896 ).Row().Scan(&count)
897 })
898
899 return count > 0
900}
901
902// RenameIndex rename index from oldName to newName
903func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 7

RunWithValueMethod · 0.95
LookIndexMethod · 0.80
CurrentDatabaseMethod · 0.65
MigratorMethod · 0.65
ScanMethod · 0.65
RowMethod · 0.65
RawMethod · 0.65

Tested by

no test coverage detected