парсер
This commit is contained in:
37
tg_parser/pkg/postgres/postgres.go
Normal file
37
tg_parser/pkg/postgres/postgres.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
URL string `envconfig:"DB__URL" required:"true"`
|
||||
}
|
||||
|
||||
type Pool struct {
|
||||
*pgxpool.Pool
|
||||
}
|
||||
|
||||
func New(ctx context.Context, c Config) (*Pool, error) {
|
||||
cfg, err := pgxpool.ParseConfig(c.URL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pgxpool.ParseConfig: %w", err)
|
||||
}
|
||||
|
||||
pool, err := pgxpool.NewWithConfig(ctx, cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("pgxpool.NewWithConfig: %w", err)
|
||||
}
|
||||
|
||||
return &Pool{Pool: pool}, nil
|
||||
}
|
||||
|
||||
func (p *Pool) Close() {
|
||||
p.Pool.Close()
|
||||
|
||||
log.Info().Msg("Postgres closed")
|
||||
}
|
||||
Reference in New Issue
Block a user