Refactor postgres to be initialized with config

This commit is contained in:
Eric Meyer
2017-11-09 12:42:24 -06:00
parent aa52088ba7
commit 58fbeb32fd
5 changed files with 28 additions and 34 deletions
+1 -7
View File
@@ -10,7 +10,6 @@ import (
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/pkg/history"
"github.com/8thlight/vulcanizedb/pkg/repositories"
"github.com/jmoiron/sqlx"
)
func main() {
@@ -23,12 +22,7 @@ func main() {
}
blockchain := geth.NewGethBlockchain(cfg.Client.IPCPath)
connectString := config.DbConnectionString(cfg.Database)
db, err := sqlx.Connect("postgres", connectString)
if err != nil {
log.Fatalf("Error connecting to DB: %v\n", err)
}
repository := repositories.NewPostgres(db)
repository := repositories.NewPostgres(cfg.Database)
numberOfBlocksCreated := history.PopulateBlocks(blockchain, repository, int64(*startingBlockNumber))
fmt.Printf("Populated %d blocks", numberOfBlocksCreated)
}
+1 -7
View File
@@ -12,7 +12,6 @@ import (
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/pkg/observers"
"github.com/8thlight/vulcanizedb/pkg/repositories"
"github.com/jmoiron/sqlx"
)
func main() {
@@ -26,12 +25,7 @@ func main() {
fmt.Println("Client Path ", cfg.Client.IPCPath)
blockchain := geth.NewGethBlockchain(cfg.Client.IPCPath)
loggingObserver := observers.BlockchainLoggingObserver{}
connectString := config.DbConnectionString(cfg.Database)
db, err := sqlx.Connect("postgres", connectString)
if err != nil {
log.Fatalf("Error connecting to DB: %v\n", err)
}
repository := repositories.NewPostgres(db)
repository := repositories.NewPostgres(cfg.Database)
dbObserver := observers.NewBlockchainDbObserver(repository)
listener := blockchain_listener.NewBlockchainListener(blockchain, []core.BlockchainObserver{
loggingObserver,