Documentation
¶
Overview ¶
Package xsql provides utilities for working with SQL databases.
Index ¶
- func ExecOne(ctx context.Context, x Executor, query string, args ...any) error
- func PanicOnDeadlock(err error)
- func Transact(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error) (err error)
- func UUIDSeq(seq iter.Seq[*uuidpb.UUID]) any
- func UUIDs(ids ...*uuidpb.UUID) any
- type Executor
- type Querier
- type ScannerValuer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PanicOnDeadlock ¶
func PanicOnDeadlock(err error)
PanicOnDeadlock panics if err is a PostgreSQL deadlock_detected error (SQLSTATE 40P01) and the program is running under go test.
Deadlocks indicate a lock-ordering bug in the engine and should never occur.
In production the function is a no-op because the transaction is already aborted and the retry path recovers gracefully - crashing the process would cause more harm than the wasted round-trip.
func Transact ¶
func Transact( ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error, ) (err error)
Transact executes the given function within a transaction.
If fn returns an error the transaction is rolled back, otherwise it is committed.
Types ¶
type Executor ¶
type Executor interface {
Querier
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
Executor is the common interface for running queries and executing statements, it is implemented by both sql.DB and sql.Tx.
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
Querier is the common interface for running queriesshared by both sql.DB and sql.Tx.
type ScannerValuer ¶
ScannerValuer is an interface for values that can be stored in the database.
func Envelope ¶
func Envelope(envelope *envelopepb.Envelope) ScannerValuer
Envelope returns a value that marshals and unmarshals an envelope to/from its binary representation as used in the database.
func UUID ¶
func UUID(id *uuidpb.UUID) ScannerValuer
UUID returns a value that marshals and unmarshals a UUID to/from its binary representation as used in the database.