package db import ( "database/sql" "fmt" "github.com/go-flucky/flucky/pkg/config" _ "github.com/lib/pq" "github.com/volker-raschek/go-logger/pkg/logger" ) var ( flogger = logger.NewSilentLogger() ) func New(databaseSettings *config.DatabaseSettings) (Database, error) { connStr := fmt.Sprintf("%v://%v:%v@%v:%v/%v?sslmode=disable", databaseSettings.Vendor.String(), databaseSettings.User, databaseSettings.Password, databaseSettings.Host, databaseSettings.Port, databaseSettings.Database) newDBO, err := sql.Open(databaseSettings.Vendor.String(), connStr) if err != nil { return nil, err } switch databaseSettings.Vendor { case config.VendorPostgreSQL: return &Postgres{ dbo: newDBO, }, nil default: return nil, fmt.Errorf("Unknown Database Type") } } func SetLogger(logger logger.Logger) { flogger = logger }