storage

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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 Database

type Database interface {
	Ping(context.Context, time.Duration) error
	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)
	BeginTx(ctx context.Context) (Transaction, error)
	Close() error
}

func MustConnect

func MustConnect(ctx context.Context) Database

type Transaction

type Transaction 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)
	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