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 // and disables foreign key check's because we maintain referential integreity to allow // for mass batch input. // 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 } _, err = db.Exec("set foreign_key_check=0") if err != nil { sugar.Warnf("app.InitDB: 💣⛔ can't disable foreign key check") } MyDB = db sugar.Debugf("app.InitDB: 👍 📤 %s", GetDBMS()) }