20 lines
400 B
Go
20 lines
400 B
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
func NewPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error) {
|
|
cfg, err := pgxpool.ParseConfig(databaseURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cfg.MaxConns = 10
|
|
cfg.MinConns = 2
|
|
cfg.MaxConnLifetime = time.Hour
|
|
cfg.MaxConnIdleTime = 10 * time.Minute
|
|
return pgxpool.NewWithConfig(ctx, cfg)
|
|
}
|