feat: add Go password session lifecycle
This commit is contained in:
1 parent
772795e7eb
commit
d0207fcebe
19 files changed
+2483
-16
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
@@ -68,8 +69,40 @@ func (p *pgxPoolAdapter) Query(ctx context.Context, sql string, args ...any) (Ro
|
||||
return p.pool.Query(ctx, sql, args...)
|
||||
}
|
||||
|
||||
func (p *pgxPoolAdapter) Begin(ctx context.Context) (Transaction, error) {
|
||||
tx, err := p.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pgxTransactionAdapter{tx: tx}, nil
|
||||
}
|
||||
|
||||
func (p *pgxPoolAdapter) Close() {
|
||||
p.pool.Close()
|
||||
}
|
||||
|
||||
var _ Pool = (*pgxPoolAdapter)(nil)
|
||||
var _ TransactionBeginner = (*pgxPoolAdapter)(nil)
|
||||
|
||||
type pgxTransactionAdapter struct {
|
||||
tx pgx.Tx
|
||||
}
|
||||
|
||||
func (t *pgxTransactionAdapter) Query(ctx context.Context, sql string, args ...any) (Rows, error) {
|
||||
return t.tx.Query(ctx, sql, args...)
|
||||
}
|
||||
|
||||
func (t *pgxTransactionAdapter) Exec(ctx context.Context, sql string, args ...any) error {
|
||||
_, err := t.tx.Exec(ctx, sql, args...)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *pgxTransactionAdapter) Commit(ctx context.Context) error {
|
||||
return t.tx.Commit(ctx)
|
||||
}
|
||||
|
||||
func (t *pgxTransactionAdapter) Rollback(ctx context.Context) error {
|
||||
return t.tx.Rollback(ctx)
|
||||
}
|
||||
|
||||
var _ Transaction = (*pgxTransactionAdapter)(nil)
|
||||
Reference in new issue
Block a user