27 lines
712 B
Go
27 lines
712 B
Go
package postgresql
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
type PGXPool interface {
|
|
Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)
|
|
Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)
|
|
QueryRow(ctx context.Context, query string, args ...any) pgx.Row
|
|
SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
|
|
BeginTx(ctx context.Context, opts pgx.TxOptions) (pgx.Tx, error)
|
|
}
|
|
|
|
func NewPGXPool(ctx context.Context, connectionString string) (*pgxpool.Pool, error) {
|
|
pool, err := pgxpool.New(ctx, connectionString)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return pool, nil
|
|
}
|