Add DropTableIfExists back

This commit is contained in:
Jinzhu 2016-03-07 21:33:48 +08:00
parent d169ac55e2
commit 946909f1e8
1 changed files with 11 additions and 0 deletions

11
main.go
View File

@ -485,6 +485,17 @@ func (s *DB) DropTable(values ...interface{}) *DB {
return db
}
// DropTableIfExists drop table if it is exist
func (s *DB) DropTableIfExists(values ...interface{}) *DB {
db := s.clone()
for _, value := range values {
if s.HasTable(value) {
db.AddError(s.DropTable(value).Error)
}
}
return db
}
// HasTable check has table or not
func (s *DB) HasTable(value interface{}) bool {
var (