From 946909f1e8790ca4f9ddddb8b7cb2e974439f5a1 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 7 Mar 2016 21:33:48 +0800 Subject: [PATCH] Add DropTableIfExists back --- main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.go b/main.go index 8baf1deb..46d64b29 100644 --- a/main.go +++ b/main.go @@ -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 (