30 lines
403 B
Go
30 lines
403 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
type Store struct {
|
|
pool *pgxpool.Pool
|
|
}
|
|
|
|
func newDB(ctx context.Context, cfg *Config) (*Store, error) {
|
|
pool, err := pgxpool.New(ctx, cfg.DBURL)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := pool.Ping(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Store{pool: pool}, nil
|
|
}
|
|
|
|
func (s *Store) closeDB() {
|
|
s.pool.Close()
|
|
}
|