uow

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package uow owns one invocation-scoped mutation unit of work.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCompleted           = errors.New("mutation unit of work is completed")
	ErrFailed              = errors.New("mutation unit of work has failed")
	ErrFrameSealed         = errors.New("component mutation frame is sealed")
	ErrBindingFlush        = errors.New("cannot flush a binding child while its ancestor is open")
	ErrTransactionConflict = errors.New("conflicting transaction for database")
	ErrTransactionAccess   = errors.New("direct transaction access is unavailable in invocation mode")
)

Functions

func BindingOrder

func BindingOrder(ctx context.Context) string

BindingOrder returns a previously reserved binding declaration order.

func Enter

func Enter(ctx context.Context, name string) (context.Context, *Scope, *Frame, bool, error)

Enter creates a child frame when ctx was prepared for dispatch. Otherwise it returns the current root frame, or creates a root for an external entry.

func FromContext

func FromContext(ctx context.Context) (*Scope, *Frame, bool)

FromContext returns the active scope and frame.

func NewRoot

func NewRoot(ctx context.Context, name string) (context.Context, *Scope, *Frame)

NewRoot creates a new root scope and installs it in ctx.

func PrepareChild

func PrepareChild(ctx context.Context, relation Relation, order string) context.Context

PrepareChild marks the next component dispatch as a child of the active frame.

func Propagate

func Propagate(source, destination context.Context) context.Context

Propagate copies only Datly's private invocation carrier from source to destination. Dispatcher closures use it so caller cancellation is retained while a nested session cannot accidentally lose the active unit of work.

func ReserveBindingOrder

func ReserveBindingOrder(ctx context.Context) (string, error)

ReserveBindingOrder allocates a stable frame-wide declaration slot before a binding resolver goroutine is started.

func WithBindingOrder

func WithBindingOrder(ctx context.Context, order string) context.Context

WithBindingOrder records the declaration order reserved by the parameter resolver before concurrently evaluating component-valued bindings.

func WithBindingOrderIndex

func WithBindingOrderIndex(ctx context.Context, index int) context.Context

WithBindingOrderIndex extends a reserved parameter slot with the authored index of a concurrently resolved repeated item.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer associates statements with one component frame and database source.

func (*Buffer) Append

func (b *Buffer) Append(value any) error

Append adds one operation at the exact current position in the frame timeline.

func (*Buffer) Flush

func (b *Buffer) Flush(ctx context.Context, table string) error

Flush executes the causal prefix ending at the requested table for b's database.

func (*Buffer) Reconcile

func (b *Buffer) Reconcile(values []any) error

Reconcile replaces this buffer's observed entries with the exact execution sequence produced by template materialization while retaining child markers.

func (*Buffer) SetBatchExecutor

func (b *Buffer) SetBatchExecutor(execute func(context.Context, *sql.Tx, []any) error)

SetBatchExecutor enables batching for contiguous operations that expose the same non-empty BatchKey. Ordering barriers are never crossed.

func (*Buffer) Transaction

func (b *Buffer) Transaction(ctx context.Context) (*sql.Tx, error)

Transaction returns the database transaction owned by the invocation scope. The caller may issue work through it, but must not commit or roll it back; completion remains the responsibility of the root scope.

func (*Buffer) UseTransaction

func (b *Buffer) UseTransaction(ctx context.Context, fn func(*sql.Tx) error) error

UseTransaction serializes work which must share this buffer's database transaction, including identity sequencing and buffered DML execution.

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

Frame owns the mutation timeline of one component invocation.

func (*Frame) DebugLabel

func (f *Frame) DebugLabel() string

DebugLabel identifies a frame in diagnostics without exposing its mutable timeline or ownership internals.

func (*Frame) NewBuffer

func (f *Frame) NewBuffer(resolveDB func(context.Context) (*sql.DB, error), externalTx *sql.Tx, execute func(context.Context, *sql.Tx, any) error) *Buffer

NewBuffer creates a frame-scoped statement buffer.

func (*Frame) Seal

func (f *Frame) Seal()

Seal closes a component frame to new semantic children.

type Operation

type Operation struct {
	// contains filtered or unexported fields
}

Operation is one ordered buffered mutation.

type Relation

type Relation uint8
const (
	RelationRoot Relation = iota
	RelationBinding
	RelationImperative
)

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope coordinates component frames and database transactions for one root operation.

func (*Scope) AdoptTransaction

func (s *Scope) AdoptTransaction(db *sql.DB, tx *sql.Tx) error

AdoptTransaction registers a caller-owned transaction for db before child binding evaluation can lazily create a local transaction for that database.

func (*Scope) Finish

func (s *Scope) Finish(ctx context.Context, cause error) error

Finish drains and completes locally owned transactions at the root boundary.

func (*Scope) IsCompleted

func (s *Scope) IsCompleted() bool

IsCompleted reports whether root completion has run.

Jump to

Keyboard shortcuts

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