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

Method HasConstraint

migrator/migrator.go:789–805  ·  view source on GitHub ↗

HasConstraint check has constraint or not

(value interface{}, name string)

Source from the content-addressed store, hash-verified

787
788// HasConstraint check has constraint or not
789func (m Migrator) HasConstraint(value interface{}, name string) bool {
790 var count int64
791 m.RunWithValue(value, func(stmt *gorm.Statement) error {
792 currentDatabase := m.DB.Migrator().CurrentDatabase()
793 constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name)
794 if constraint != nil {
795 name = constraint.GetName()
796 }
797
798 return m.DB.Raw(
799 "SELECT count(*) FROM INFORMATION_SCHEMA.table_constraints WHERE constraint_schema = ? AND table_name = ? AND constraint_name = ?",
800 currentDatabase, table, name,
801 ).Row().Scan(&count)
802 })
803
804 return count > 0
805}
806
807// BuildIndexOptions build index options
808func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{}) {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 8

RunWithValueMethod · 0.95
CurrentDatabaseMethod · 0.65
MigratorMethod · 0.65
GetNameMethod · 0.65
ScanMethod · 0.65
RowMethod · 0.65
RawMethod · 0.65

Tested by

no test coverage detected