Example #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`.")
	}
}
Example #2
0
// InitPostgresStore Creates a `PostgresStore` object and initiates all necessary
// moving parts like the `HandlePeerUpdates` channel consumer.
func InitPostgresStore() (store PostgresStore) {
	dbConn, err := postgres.OpenConnection()
	if err != nil {
		panic("Failed opening a connection to remote Postgres database.")
	}

	store = PostgresStore{
		dbConn,
	}

	return store
}
Example #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`.")
	}
}
Example #4
0
// OpenConnection wraps `postgres.OpenConnection`.
func (m *PostgresStore) OpenConnection() (*gorm.DB, error) {
	return postgres.OpenConnection()
}