github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/sqlx/builder/obj_database_test.go (about) 1 package builder 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestDatabase(t *testing.T) { 10 tt := assert.New(t) 11 12 db := DB("db") 13 14 tt.Nil(db.Table("t")) 15 16 table := T(db, "t") 17 db.Register(table) 18 tt.NotNil(db.Table("t")) 19 tt.Equal([]string{"t"}, db.TableNames()) 20 21 exprCases{ 22 Case( 23 "drop Database", 24 db.Drop(), 25 Expr("DROP DATABASE `db`"), 26 ), 27 Case( 28 "create Database if not exists", 29 db.Create(true), 30 Expr("CREATE DATABASE IF NOT EXISTS `db`"), 31 ), 32 Case( 33 "create Database", 34 db.Create(false), 35 Expr("CREATE DATABASE `db`"), 36 ), 37 }.Run(t, "Database") 38 }