This commit is contained in:
2021-12-02 10:44:14 +00:00
parent cdc767a497
commit e465b961a5
5 changed files with 25 additions and 11 deletions

View File

@ -4,14 +4,15 @@ package postgres
import (
"context"
"database/sql"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
)
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
func New(db DBTX) *Queries {
@ -22,7 +23,7 @@ type Queries struct {
db DBTX
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}