This commit is contained in:
2025-09-28 20:19:45 +03:00
parent 6638ef1b5f
commit 3fd63d5f32
21 changed files with 356 additions and 355 deletions

View File

@@ -1,17 +1,26 @@
package db
import (
"database/sql"
"context"
"sipro-mps/internal/config"
"github.com/jackc/pgx/v5/pgxpool"
_ "github.com/lib/pq"
"go.uber.org/fx"
)
func NewConnection(dsn string) (*sql.DB, error) {
db, err := sql.Open("postgres", dsn)
func NewPgxPool(lc fx.Lifecycle, config config.Config) (*pgxpool.Pool, error) {
ctx := context.Background()
pool, err := pgxpool.New(ctx, config.Database.URL)
if err != nil {
return nil, err
}
if err := db.Ping(); err != nil {
return nil, err
}
return db, nil
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
pool.Close()
return nil
},
})
return pool, nil
}