lib/app/mysql.go

29 lines
601 B
Go
Raw Permalink Normal View History

2023-09-12 03:42:13 +00:00
package app
import (
"database/sql"
// need this for SQL
_ "github.com/go-sql-driver/mysql"
)
// MyDB is the MySQL handler variable
var MyDB *sql.DB
// InitDB initializes the MySQL database using DSN information from the config file
func InitDB() {
var db *sql.DB
var err error
if GetDBMS() != "mysql" {
sugar.Fatalf("app.InitDB: 💣 ⛔ unknown DBMS: %s", GetDBMS())
return
}
db, err = sql.Open("mysql", GetDSN())
if err != nil {
sugar.Fatalf("app.InitDB: 💣 ⛔ Can't log on to DBMS host: %w", err)
return
}
MyDB = db
2023-11-19 19:31:26 +00:00
sugar.Debugf("app.InitDB: 👍 👈 %s", GetDBMS())
2023-09-12 03:42:13 +00:00
}