dbi

package
v0.0.0-...-af95b3a Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, db DBI, val any, query string, vals ...any) error

func ReadOnly

func ReadOnly[T any](ctx context.Context, db *sql.DB, fn func(DBI) (T, error)) (T, error)

ReadOnly executes fn within a read-only transaction. The transaction is committed if fn returns nil, otherwise rolled back.

func ReadWrite

func ReadWrite[T any](ctx context.Context, db *sql.DB, fn func(DBI) (T, error)) (T, error)

ReadWrite executes fn within a read-write transaction. The transaction is committed if fn returns nil, otherwise rolled back.

func TranslateNotFound

func TranslateNotFound(from, to error) error

func WithTx

func WithTx[T any](ctx context.Context, db *sql.DB, opts *sql.TxOptions, fn func(*TxDal) (T, error)) (T, error)

Types

type DBI

type DBI interface {
	Query(context.Context, string, ...any) (*sql.Rows, error)
	QueryRow(context.Context, string, ...any) *sql.Row
	Exec(context.Context, string, ...any) (sql.Result, error)
}

type Factory

type Factory[T any] func(DBI) T

type TxDal

type TxDal struct {
	Tx *sql.Tx
}

func (*TxDal) Exec

func (t *TxDal) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*TxDal) Query

func (t *TxDal) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)

func (*TxDal) QueryRow

func (t *TxDal) QueryRow(ctx context.Context, query string, args ...any) *sql.Row

Source Files

  • dbi.go
  • get.go

Jump to

Keyboard shortcuts

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