db

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScanFirstValue added in v0.9.0

func ScanFirstValue[T any](rows *sql.Rows, dest *T) error

ScanFirstValue is a helper function to scan the first value with the assumption that Rows contains a single row with a single value.

Types

type DB

type DB interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	WithRetryableTransaction(ctx context.Context, f func(context.Context, *sql.Tx) error) error
	Close() error
}

type FakeDB added in v0.9.0

type FakeDB struct{}

FakeDB is a fake implementation of `DB`. All methods on `FakeDB` are implemented as no-ops

func (*FakeDB) Close added in v0.9.0

func (db *FakeDB) Close() error

func (*FakeDB) ExecContext added in v0.9.0

func (db *FakeDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*FakeDB) QueryContext added in v0.9.0

func (db *FakeDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*FakeDB) WithRetryableTransaction added in v0.9.0

func (db *FakeDB) WithRetryableTransaction(ctx context.Context, f func(context.Context, *sql.Tx) error) error

type RDB

type RDB struct {
	DB *sql.DB
}

RDB wraps a *sql.DB and retries queries using an exponential backoff (with jitter) on lock_timeout errors.

func (*RDB) Close

func (db *RDB) Close() error

func (*RDB) ExecContext

func (db *RDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext wraps sql.DB.ExecContext, retrying queries on lock_timeout errors.

func (*RDB) QueryContext added in v0.9.0

func (db *RDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext wraps sql.DB.QueryContext, retrying queries on lock_timeout errors.

func (*RDB) WithRetryableTransaction

func (db *RDB) WithRetryableTransaction(ctx context.Context, f func(context.Context, *sql.Tx) error) error

WithRetryableTransaction runs `f` in a transaction, retrying on lock_timeout errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL