exec

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package exec is the base module's execution layer — the only layer that touches database/sql at runtime. The query runners List, One, and Query take a database.Session, so the same reads run against the pool or inside a transaction; the command runners Insert, Update, and Delete take a *database.Tx, so the compiler enforces the consumer-owned transaction boundary. Every runner renders the SQL its operation would be hand-written as — never another operation's scaffolding — and every driver error routes through the session dialect's MapError, so constraint violations reach the caller as the database package's classified sentinels.

Guard outcomes

The guarded runners map the operation.Guarded pair to one outcome: success returns the deterministic new version with no extra round trip; a miss runs the check, returning sql.ErrNoRows when the row is gone and database.ErrVersionMismatch — carrying the expected and current versions — when it moved. Under concurrent writers the split is best-effort (the check observes a later snapshot); it is exact under serializable isolation, and both outcomes are conflicts either way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(ctx context.Context, tx *database.Tx, del operation.GuardedDelete) error

Delete runs the guarded delete, with the same guard outcomes as Update.

func List

func List[T any](
	ctx context.Context,
	s database.Session,
	p operation.Projection,
	dir operation.Directives,
	scan Scan[T],
) ([]T, int, error)

List runs the list query: the projection's count and page statements over one shared WHERE, returning the page's items and the total row count.

func One

func One[T any](
	ctx context.Context,
	s database.Session,
	p operation.Projection,
	field string,
	value any,
	scan Scan[T],
) (T, error)

One runs the single-row query. A missing row is sql.ErrNoRows; an unknown field is the operation package's typed error, surfaced before anything executes; when the filtered field is not unique, the first row wins, as with sql.DB.QueryRow.

func Query

func Query[T any](
	ctx context.Context,
	s database.Session,
	stmt ast.SQL,
	scan Scan[T],
) ([]T, error)

Query executes one rendered statement and scans every row it returns, with a nil slice for zero rows.

func Update

Update runs the guarded update, returning the new version on success and otherwise the guard outcome: sql.ErrNoRows when the row is gone, database.ErrVersionMismatch when it moved.

Types

type Identity

type Identity struct {
	ID      string
	Version int64
}

Identity is an insert's envelope: the engine-minted identity — a string by the organization's UUID convention — and the row's initial version.

func Insert

func Insert(ctx context.Context, tx *database.Tx, i operation.Insertion) (Identity, error)

Insert runs the identity-returning insert inside the consumer's transaction, scanning the returned identity and version.

type Scan

type Scan[T any] func(*sql.Rows) (T, error)

Scan reads one row of a statement's result into a T. A domain package supplies one per entity, scanning in its projection's select-list order: key first, then each field in declaration order.

Jump to

Keyboard shortcuts

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