v2
This commit is contained in:
@@ -14,13 +14,13 @@ import (
|
||||
|
||||
// ****************** conn ******************
|
||||
|
||||
func newDsn() string {
|
||||
func newDsn(conf config.DB) string {
|
||||
return fmt.Sprintf("postgresql://%s:%s@%s:%d/%s?sslmode=disable",
|
||||
config.File.DB.Username,
|
||||
config.File.DB.Password,
|
||||
config.File.DB.Host,
|
||||
config.File.DB.Port,
|
||||
config.File.DB.DBName)
|
||||
conf.Username,
|
||||
conf.Password,
|
||||
conf.Host,
|
||||
conf.Port,
|
||||
conf.DBName)
|
||||
}
|
||||
|
||||
// ****************** errors ******************
|
||||
@@ -69,9 +69,26 @@ type SQLStore struct {
|
||||
*Queries
|
||||
}
|
||||
|
||||
func NewIStore(ctx context.Context, conf config.DB) (Store, error) {
|
||||
pool, err := pgxpool.New(ctx, newDsn(conf))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = pool.Ping(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &SQLStore{
|
||||
connPool: pool,
|
||||
Queries: New(pool),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewStore creates a new store
|
||||
func NewStore(ctx context.Context) error {
|
||||
pool, err := pgxpool.New(ctx, newDsn())
|
||||
pool, err := pgxpool.New(ctx, newDsn(config.File.DB))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user