Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/gf/internal/cmd/cmd_z_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
)

var (
ctx = context.Background()
testDB gdb.DB
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true"
ctx = context.Background()
testDB gdb.DB
testPgDB gdb.DB
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true"
linkPg = "pgsql:postgres:12345678@tcp(127.0.0.1:5432)/test"
)

func init() {
Expand All @@ -28,6 +30,10 @@ func init() {
if err != nil {
panic(err)
}
// PostgreSQL connection (optional, may not be available in all environments)
testPgDB, _ = gdb.New(gdb.ConfigNode{
Link: linkPg,
})
}

func dropTableWithDb(db gdb.DB, table string) {
Expand All @@ -36,3 +42,11 @@ func dropTableWithDb(db gdb.DB, table string) {
gtest.Error(err)
}
}

// dropTableStd uses standard SQL syntax compatible with MySQL and PostgreSQL.
func dropTableStd(db gdb.DB, table string) {
dropTableStmt := fmt.Sprintf("DROP TABLE IF EXISTS %s", table)
if _, err := db.Exec(ctx, dropTableStmt); err != nil {
gtest.Error(err)
}
}
Loading
Loading