func OpenDBChoiceConnection() (*gorm.DB, error) { cfg := config.LoadConfig() if cfg.DBChoice == "mysql" { return mysql.OpenConnection() } else if cfg.DBChoice == "postgres" { return postgres.OpenConnection() } else { panic("Invalid database choice found for `OpenDBChoiceConnection`.") } }
// InitMySQLStore Creates a `MySQLStore` object and initiates all necessary // moving parts like the `HandlePeerUpdates` channel consumer. func InitMySQLStore() (store MySQLStore) { dbConn, err := mysql.OpenConnection() if err != nil { panic("Failed opening a connection to remote MYSQL database.") } store = MySQLStore{ dbConn, nil, } store.UpdateConsumer = store.HandlePeerUpdates() return store }
func InitDB(config *config.ConfigStruct) { if (*config).DBChoice == "mysql" { conn, err := mysql.OpenConnection() if err != nil { panic("Unable to open connection to remote server") } mysql.InitDB(conn) } else if (*config).DBChoice == "postgres" { conn, err := postgres.OpenConnection() if err != nil { panic("Unable to open connection to remote server") } postgres.InitDB(conn) } else { panic("Invalid Config choice for DBChoice. Set either `UsePostgres` or `UseMySQL`.") } }
// OpenConnection wraps `mysql.OpenConnection`. func (m *MySQLStore) OpenConnection() (*gorm.DB, error) { return mysql.OpenConnection() }