db

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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