Beispiel #1
0
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`.")
	}
}
Beispiel #2
0
// 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
}
Beispiel #3
0
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`.")
	}
}
Beispiel #4
0
// OpenConnection wraps `mysql.OpenConnection`.
func (m *MySQLStore) OpenConnection() (*gorm.DB, error) {
	return mysql.OpenConnection()
}