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

Method HasColumn

migrator/migrator.go:429–447  ·  view source on GitHub ↗

HasColumn check has column `field` for value or not

(value interface{}, field string)

Source from the content-addressed store, hash-verified

427
428// HasColumn check has column `field` for value or not
429func (m Migrator) HasColumn(value interface{}, field string) bool {
430 var count int64
431 m.RunWithValue(value, func(stmt *gorm.Statement) error {
432 currentDatabase := m.DB.Migrator().CurrentDatabase()
433 name := field
434 if stmt.Schema != nil {
435 if field := stmt.Schema.LookUpField(field); field != nil {
436 name = field.DBName
437 }
438 }
439
440 return m.DB.Raw(
441 "SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE table_schema = ? AND table_name = ? AND column_name = ?",
442 currentDatabase, stmt.Table, name,
443 ).Row().Scan(&count)
444 })
445
446 return count > 0
447}
448
449// RenameColumn rename value's field name from oldName to newName
450func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error {

Callers

nothing calls this directly

Implementers 1

Migratormigrator/migrator.go

Calls 7

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

Tested by

no test coverage detected