Feature/22 test handling incoming events - Intermediary Commit #28
@ -8,7 +8,6 @@ import (
|
||||
"github.com/vulcanize/ipld-ethcl-indexer/pkg/beaconclient"
|
||||
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
|
||||
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql/postgres"
|
||||
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -18,36 +17,6 @@ var (
|
||||
BC *beaconclient.BeaconClient = &beaconclient.BeaconClient{}
|
||||
)
|
||||
|
||||
// A simple wrapper to create a DB object to use.
|
||||
func SetupPostgresDb(dbHostname string, dbPort int, dbName string, dbUsername string, dbPassword string, driverName string) (sql.Database, error) {
|
||||
log.Debug("Resolving Driver Type")
|
||||
DbDriver, err := postgres.ResolveDriverType(driverName)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"err": err,
|
||||
"driver_name_provided": driverName,
|
||||
}).Error("Can't resolve driver type")
|
||||
}
|
||||
log.Info("Using Driver:", DbDriver)
|
||||
|
||||
postgresConfig := postgres.Config{
|
||||
Hostname: dbHostname,
|
||||
Port: dbPort,
|
||||
DatabaseName: dbName,
|
||||
Username: dbUsername,
|
||||
Password: dbPassword,
|
||||
Driver: DbDriver,
|
||||
}
|
||||
DB, err = postgres.NewPostgresDB(postgresConfig)
|
||||
|
||||
if err != nil {
|
||||
loghelper.LogError(err).Error("Unable to connect to the DB")
|
||||
return nil, err
|
||||
}
|
||||
return DB, err
|
||||
|
||||
}
|
||||
|
||||
// This function will perform some boot operations. If any steps fail, the application will fail to start.
|
||||
// Keep in mind that the DB connection can be lost later in the lifecycle of the application or
|
||||
// it might not be able to connect to the beacon client.
|
||||
@ -69,7 +38,7 @@ func BootApplication(ctx context.Context, dbHostname string, dbPort int, dbName
|
||||
}
|
||||
|
||||
log.Debug("Setting up DB connection")
|
||||
DB, err := SetupPostgresDb(dbHostname, dbPort, dbName, dbUsername, dbPassword, driverName)
|
||||
DB, err := postgres.SetupPostgresDb(dbHostname, dbPort, dbName, dbUsername, dbPassword, driverName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/vulcanize/ipld-ethcl-indexer/pkg/database/sql"
|
||||
"github.com/vulcanize/ipld-ethcl-indexer/pkg/loghelper"
|
||||
)
|
||||
|
||||
var _ sql.Database = &DB{}
|
||||
@ -23,6 +24,35 @@ func NewPostgresDB(c Config) (*DB, error) {
|
||||
return &DB{driver}, nil
|
||||
}
|
||||
|
||||
// A simple wrapper to create a DB object to use.
|
||||
func SetupPostgresDb(dbHostname string, dbPort int, dbName string, dbUsername string, dbPassword string, driverName string) (sql.Database, error) {
|
||||
log.Debug("Resolving Driver Type")
|
||||
DbDriver, err := ResolveDriverType(driverName)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"err": err,
|
||||
"driver_name_provided": driverName,
|
||||
}).Error("Can't resolve driver type")
|
||||
}
|
||||
log.Info("Using Driver:", DbDriver)
|
||||
|
||||
postgresConfig := Config{
|
||||
Hostname: dbHostname,
|
||||
Port: dbPort,
|
||||
DatabaseName: dbName,
|
||||
Username: dbUsername,
|
||||
Password: dbPassword,
|
||||
Driver: DbDriver,
|
||||
}
|
||||
DB, err := NewPostgresDB(postgresConfig)
|
||||
|
||||
if err != nil {
|
||||
loghelper.LogError(err).Error("Unable to connect to the DB")
|
||||
return nil, err
|
||||
}
|
||||
return DB, err
|
||||
}
|
||||
|
||||
// Create a driver based on the config
|
||||
func createDriver(c Config) (*pgxDriver, error) {
|
||||
switch c.Driver {
|
||||
|
Loading…
Reference in New Issue
Block a user