MCPcopy Create free account
hub / github.com/cloudwan/gohan / ensureDatabase

Function ensureDatabase

cli/generate.go:44–65  ·  view source on GitHub ↗
(dbName string)

Source from the content-addressed store, hash-verified

42}
43
44func ensureDatabase(dbName string) error {
45 config := util.GetConfig()
46 databaseType := config.GetString("database/type", "mysql")
47 databaseConnection := os.Getenv("DATABASE_CONNECTION")
48 if databaseConnection == "" {
49 databaseConnection = config.GetString("database/connection", "")
50 }
51 db, err := sql.Open(databaseType, databaseConnection)
52 if err != nil {
53 return err
54 }
55 defer db.Close()
56 _, err = db.Exec("drop database if exists " + dbName)
57 if err != nil {
58 return err
59 }
60 _, err = db.Exec("create database " + dbName)
61 if err != nil {
62 return err
63 }
64 return nil
65}
66
67func dropDatabase(dbName string) error {
68 config := util.GetConfig()

Callers 1

gohanGenerateFunction · 0.85

Calls 3

GetStringMethod · 0.80
CloseMethod · 0.65
ExecMethod · 0.65

Tested by

no test coverage detected