Documentation
¶
Overview ¶
Package data provides standard-library-first SQL transaction contracts for generated Spice applications and application-owned repositories.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPanicked = errors.New("transaction callback panicked")
ErrPanicked identifies an observed transaction callback panic. Within rolls the transaction back, reports this error to observers, and re-panics with the original value.
Functions ¶
This section is empty.
Types ¶
type Definition ¶
type Definition struct {
ID string
Module string
Isolation sql.IsolationLevel
ReadOnly bool
}
Definition is compiler-owned metadata for one transaction boundary.
type Executor ¶
type Executor interface {
ExecContext(context.Context, string, ...any) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...any) *sql.Row
}
Executor is the common database/sql surface implemented by *sql.DB and *sql.Tx. Repositories can depend on this interface and remain usable inside and outside a managed transaction.
func ExecutorFromContext ¶
ExecutorFromContext returns the transaction-owned executor installed by Manager.Within. Generated service decorators use this explicit accessor so repository implementations can participate without receiving a transaction parameter through every service method. It returns false outside a managed transaction.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager executes transaction callbacks against one caller-owned database.
func NewManager ¶
NewManager constructs a transaction manager. It makes no connection and does not mutate database pool settings.
func (*Manager) Within ¶
func (manager *Manager) Within( ctx context.Context, definition Definition, work Work, ) (resultErr error)
Within begins a transaction, invokes work, and commits only when work succeeds. Callback errors and panics cause rollback. A rollback failure is joined with the callback failure; a panic is re-raised after observation.
type Observer ¶
type Observer interface {
BeginTransaction(context.Context, Definition) (context.Context, func(Result))
}
Observer receives transaction begin/end information on the calling goroutine. Implementations must not panic or block indefinitely.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package repository provides bounded, typed database/sql query primitives for application-owned and generated repositories.
|
Package repository provides bounded, typed database/sql query primitives for application-owned and generated repositories. |