db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package db holds shared low-level database abstractions used across the GoFastr framework subpackages. Splitting this out lets slow_query, eager loading, and the CRUD handler all share the same Executor interface without depending on each other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TxFromContext

func TxFromContext(ctx context.Context) (*sql.Tx, bool)

TxFromContext returns the active *sql.Tx from context when a CRUD handler has wrapped the operation in a transaction. Lifecycle hooks may use it to perform additional database work that is atomic with the parent operation — queries the hook runs through the tx see (and only commit with) the parent write.

func WithTx

func WithTx(ctx context.Context, tx *sql.Tx) context.Context

WithTx returns a derived context carrying tx for hook consumption.

Types

type Beginner

type Beginner interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

Beginner is satisfied by *sql.DB. *sql.Tx does not satisfy it, which lets inTx skip nested begin attempts.

type Executor

type Executor interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

Executor is the interface for database operations. Both *sql.DB and *sql.Tx satisfy it; wrappers (e.g. SlowQueryLogger) implement it by delegating to an inner Executor.

Jump to

Keyboard shortcuts

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