Files
2025-09-28 20:19:45 +03:00

27 lines
464 B
Go
Executable File

package db
import (
"context"
"sipro-mps/internal/config"
"github.com/jackc/pgx/v5/pgxpool"
_ "github.com/lib/pq"
"go.uber.org/fx"
)
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
}
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
pool.Close()
return nil
},
})
return pool, nil
}