storage

package
v1.59.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromPgUUID added in v1.11.0

func FromPgUUID(v pgtype.UUID) uuid.UUID

func Int8OrNull added in v1.48.0

func Int8OrNull(n int64) pgtype.Int8

Int8OrNull returns a NULL pgtype.Int8 for 0, or a valid one otherwise.

func TextOrNull added in v1.10.0

func TextOrNull(s string) pgtype.Text

TextOrNull returns a NULL pgtype.Text for an empty string, or a valid one otherwise.

func TimestampOrNull added in v1.10.0

func TimestampOrNull(t time.Time) pgtype.Timestamptz

TimestampOrNull returns a NULL pgtype.Timestamptz for the zero time, or a valid one otherwise.

func ToPgUUID added in v1.11.0

func ToPgUUID(id uuid.UUID) pgtype.UUID

func WithTransaction added in v1.10.0

func WithTransaction(ctx context.Context, db Database, fn func(Transaction) error) error

WithTransaction runs fn within a database transaction, committing if fn returns nil and rolling back otherwise.

Types

type DBTX added in v1.14.0

type DBTX interface {
	Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, query string, args ...any) pgx.Row
	Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)
}

DBTX is the read-capable subset shared by Database and Transaction; it mirrors sqlc's generated DBTX, so sqlcgen.New accepts either. Components accept it so a read can run on the pool directly, while a write takes a Transaction (a superset).

type Database

type Database interface {
	DBTX
	Ping(context.Context, time.Duration) error
	BeginTx(ctx context.Context) (Transaction, error)
	Close() error
}

func Connect added in v1.59.0

func Connect(ctx context.Context, p Params) (Database, error)

func MustConnect

func MustConnect(ctx context.Context) Database

type Driver added in v1.59.0

type Driver string

The two drivers have separate migration directories, so an unset Driver is rejected rather than defaulted.

const (
	DriverPostgres Driver = "postgres"
	DriverYugabyte Driver = "yugabyte"
)

type Params added in v1.59.0

type Params struct {
	Driver Driver

	// The caller builds the DSN because LabKit's builder emits no query string,
	// and that is where sslmode is set.
	DSN string

	// MaxConns and MinIdleConns override pool_max_conns and pool_min_idle_conns
	// in the DSN; zero leaves the DSN value in place.
	MaxConns     int32
	MinIdleConns int32
}

func (Params) Validate added in v1.59.0

func (p Params) Validate() error

type Transaction

type Transaction interface {
	DBTX
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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