Add AddColumn method
This commit is contained in:
parent
5050a58b45
commit
3b699fdf3e
7
main.go
7
main.go
@ -552,6 +552,13 @@ func (s *DB) AutoMigrate(values ...interface{}) *DB {
|
|||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddColumn add column with type
|
||||||
|
func (s *DB) AddColumn(column string, typ string) *DB {
|
||||||
|
scope := s.clone().NewScope(s.Value)
|
||||||
|
scope.addColumn(column, typ)
|
||||||
|
return scope.db
|
||||||
|
}
|
||||||
|
|
||||||
// ModifyColumn modify column to type
|
// ModifyColumn modify column to type
|
||||||
func (s *DB) ModifyColumn(column string, typ string) *DB {
|
func (s *DB) ModifyColumn(column string, typ string) *DB {
|
||||||
scope := s.clone().NewScope(s.Value)
|
scope := s.clone().NewScope(s.Value)
|
||||||
|
4
scope.go
4
scope.go
@ -1124,6 +1124,10 @@ func (scope *Scope) dropTable() *Scope {
|
|||||||
return scope
|
return scope
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scope *Scope) addColumn(column string, typ string) {
|
||||||
|
scope.Raw(fmt.Sprintf("ALTER TABLE %v ADD %v %v", scope.QuotedTableName(), scope.Quote(column), typ)).Exec()
|
||||||
|
}
|
||||||
|
|
||||||
func (scope *Scope) modifyColumn(column string, typ string) {
|
func (scope *Scope) modifyColumn(column string, typ string) {
|
||||||
scope.Raw(fmt.Sprintf("ALTER TABLE %v MODIFY %v %v", scope.QuotedTableName(), scope.Quote(column), typ)).Exec()
|
scope.Raw(fmt.Sprintf("ALTER TABLE %v MODIFY %v %v", scope.QuotedTableName(), scope.Quote(column), typ)).Exec()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user