Documentation
¶
Overview ¶
Package dbi - database abstraction with transaction management and pagination helpers.
Index ¶
- func Get(ctx context.Context, db DBI, val any, query string, vals ...any) error
- func Paginate[T any](ctx context.Context, db DBI, page core.PageReq, out *core.Page[T], ...) error
- func Read[T any](ctx context.Context, db *sql.DB, fn func(tx DBI) (T, error)) (T, error)
- func ReadOnly(ctx context.Context, db *sql.DB, fn func(tx DBI) error) error
- func ReadWrite(ctx context.Context, db *sql.DB, fn func(tx DBI) error) error
- func TranslateNotFound(from, to error) error
- func WithTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions, fn func(tx DBI) error) error
- func Write[T any](ctx context.Context, db *sql.DB, fn func(tx DBI) (T, error)) (T, error)
- type DBI
- type Factory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Paginate ¶
func Paginate[T any](ctx context.Context, db DBI, page core.PageReq, out *core.Page[T], cursorFn func(T) string, query string, args ...any) error
Paginate runs a paginated query and returns a Page. Use $cursor and $limit placeholders in the query; they are replaced with positional placeholders based on the number of args. The cursor function extracts the cursor value from the last item.
func Read ¶
func ReadOnly ¶
ReadOnly executes fn within a read-only transaction. The transaction is committed if fn returns nil, otherwise rolled back.
func ReadWrite ¶
ReadWrite executes fn within a read-write transaction. The transaction is committed if fn returns nil, otherwise rolled back.
func WithTx ¶
Types ¶
Source Files
¶
- dbi.go
- get.go
- scan.go
Click to show internal directories.
Click to hide internal directories.