HasColumn check has column `field` for value or not
(value interface{}, field string)
| 427 | |
| 428 | // HasColumn check has column `field` for value or not |
| 429 | func (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 |
| 450 | func (m Migrator) RenameColumn(value interface{}, oldName, newName string) error { |
nothing calls this directly
no test coverage detected