mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* Speeds up tests * Reduces time.Sleeps, lowers CreateTestBot complexity. Breaks things * Removal of unecessary config reads. Parallel tests. Lower times * Speeds up recent trades results * mini update * zoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooom * Removes the dupes * Lint * post cherrypick * Fix rare kraken data race * Fixes banking global issues. Fixes postgres trades * rmline for appveyor test * Expands timeout in event that channel is closed before send * Fix data race * No rows, no bows and definitely no shows * Removes parallel from createsnapshot tests * Extends timedmutext test a smidge. Exchange fatality * Shorter end timeframe and bigger candle
42 lines
856 B
Go
42 lines
856 B
Go
package postgres
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
// import go libpq driver package
|
|
_ "github.com/lib/pq"
|
|
"github.com/thrasher-corp/gocryptotrader/database"
|
|
)
|
|
|
|
// Connect opens a connection to Postgres database and returns a pointer to database.DB
|
|
func Connect(cfg *database.Config) (*database.Instance, error) {
|
|
if cfg == nil {
|
|
return nil, database.ErrNilConfig
|
|
}
|
|
if !cfg.Enabled {
|
|
return nil, database.ErrDatabaseSupportDisabled
|
|
}
|
|
if cfg.SSLMode == "" {
|
|
cfg.SSLMode = "disable"
|
|
}
|
|
|
|
configDSN := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
|
|
cfg.Username,
|
|
cfg.Password,
|
|
cfg.Host,
|
|
cfg.Port,
|
|
cfg.Database,
|
|
cfg.SSLMode)
|
|
|
|
db, err := sql.Open(database.DBPostgreSQL, configDSN)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = database.DB.SetPostgresConnection(db)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return database.DB, nil
|
|
}
|