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

Method CreateConstraint

migrator/migrator.go:762–775  ·  view source on GitHub ↗

CreateConstraint create constraint

(value interface{}, name string)

Source from the content-addressed store, hash-verified

760
761// CreateConstraint create constraint
762func (m Migrator) CreateConstraint(value interface{}, name string) error {
763 return m.RunWithValue(value, func(stmt *gorm.Statement) error {
764 constraint, table := m.GuessConstraintInterfaceAndTable(stmt, name)
765 if constraint != nil {
766 vars := []interface{}{clause.Table{Name: table}}
767 if stmt.TableExpr != nil {
768 vars[0] = stmt.TableExpr
769 }
770 sql, values := constraint.Build()
771 return m.DB.Exec("ALTER TABLE ? ADD "+sql, append(vars, values...)...).Error
772 }
773 return nil
774 })
775}
776
777// DropConstraint drop constraint
778func (m Migrator) DropConstraint(value interface{}, name string) error {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 4

RunWithValueMethod · 0.95
BuildMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected