dml

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 24 Imported by: 2

Documentation

Overview

Package dml provides the SQLX-backed buffered write and transaction scope.

Index

Constants

View Source
const (
	ComponentBinding    = "binding"
	ComponentImperative = "imperative"
)

Variables

View Source
var (
	ErrInvocationCompleted = errors.New("DML data invocation is completed")
	ErrInvocationFailed    = errors.New("DML data invocation failed")
	ErrComponentSealed     = errors.New("DML component frame is sealed")
	ErrBindingFlush        = errors.New("cannot flush a binding component while its ancestor is open")
)

Functions

This section is empty.

Types

type Data

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

func NewData

func NewData(db *sql.DB, opts ...Option) *Data

func (*Data) Allocate

func (d *Data) Allocate(ctx context.Context, tableName string, dest any, selector string) error

func (*Data) BeginInvocation

func (d *Data) BeginInvocation() error

BeginInvocation switches Data from standalone auto-commit behavior to one root-owned transaction completed by Complete after output finalization.

func (*Data) Complete

func (d *Data) Complete(ctx context.Context, cause error) error

Complete drains the invocation journal and completes only locally owned transactions. Caller-supplied transactions always remain open.

func (*Data) ComponentData

func (d *Data) ComponentData(relation, order string) xhandler.Data

ComponentData creates a private component view over the same root journal. It is consumed by Datly's engine through an optional internal capability; xdatly's public Data interface remains unchanged.

func (*Data) Delete

func (d *Data) Delete(tableName string, data any) error

func (*Data) ExecContext

func (d *Data) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext executes immediately through the invocation-owned transaction. It never flushes pending buffered writes implicitly.

func (*Data) Execute

func (d *Data) Execute(dml string, args ...any) error

func (*Data) Flush

func (d *Data) Flush(ctx context.Context, tableName string) error

func (*Data) FrameworkValidator

func (d *Data) FrameworkValidator() xhandler.Validator

FrameworkValidator is an optional internal Data capability. Engine adapters expose only Validator, retaining database and transaction ownership here.

func (*Data) Insert

func (d *Data) Insert(tableName string, data any) error

func (*Data) PrepareCompletion

func (d *Data) PrepareCompletion(ctx context.Context) error

PrepareCompletion drains the complete invocation journal into its owned or supplied transaction without completing that transaction. The engine uses this internal lifecycle seam to prepare every database unit before any local unit is committed.

func (*Data) PrepareFinalization

func (d *Data) PrepareFinalization(ctx context.Context) error

PrepareFinalization makes local flush failures visible to an error-aware finalizer before commit. A supplied transaction retains its existing ordering: no queued writes execute until the finalizer has completed successfully.

func (*Data) QueryContext

func (d *Data) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext executes immediately through the invocation-owned transaction. It never flushes pending buffered writes implicitly.

func (*Data) QueryRowContext

func (d *Data) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext executes immediately through the invocation-owned transaction. It never flushes pending buffered writes implicitly.

func (*Data) Reserve

func (d *Data) Reserve(ctx context.Context, tableName string, dest any, selector string) error

Reserve forwards pending supplied identities to the same scoped sequencer that will allocate IDs. Custom Sequencer implementations need only Allocate.

func (*Data) SealComponent

func (d *Data) SealComponent()

func (*Data) Start

func (d *Data) Start(ctx context.Context) error

Start opens the managed transaction early without executing queued DML. The same root owns completion whether this frame or a descendant starts it.

func (*Data) TransactionOutcome

func (d *Data) TransactionOutcome() xhandler.TransactionOutcome

TransactionOutcome reports this existing Data owner's managed completion. It is not part of the public Data capability and exposes no transaction.

func (*Data) Update

func (d *Data) Update(tableName string, data any) error

func (*Data) ValidationConnection

func (d *Data) ValidationConnection(ctx context.Context, connector string) (validation.Connection, error)

type Option

type Option func(*options)

Option configures an invocation SQL DML capability.

func WithCommitObserver

func WithCommitObserver(observer func(context.Context)) Option

func WithSequenceStrategy

func WithSequenceStrategy(strategy dialect.PresetIDStrategy) Option

WithSequenceStrategy selects a native allocation strategy for this data owner. Empty/undefined retains the native product default.

func WithTx

func WithTx(tx *sql.Tx) Option

WithTx attaches a parent-managed transaction. Flush writes through it but never commits or rolls it back.

type Source

type Source struct {
	DB               *sql.DB
	SequenceStrategy dialect.PresetIDStrategy
	Tx               *sql.Tx
	OnCommit         func(context.Context)
}

Source opens a fresh SQLX-backed handler data capability for each invocation.

func (Source) InvocationKey

func (s Source) InvocationKey() any

InvocationKey lets Datly's private invocation scope separate database units without exposing transaction or data-unit lifecycle through xdatly.

func (Source) InvocationSequenceStrategy

func (s Source) InvocationSequenceStrategy() string

func (Source) InvocationTransactionKey

func (s Source) InvocationTransactionKey() any

InvocationTransactionKey supports early child/root transaction conflict checks.

func (Source) Open

func (s Source) Open(ctx context.Context) (xhandler.Data, error)

func (Source) ResolveSequenceStrategy

func (s Source) ResolveSequenceStrategy(ctx context.Context) (dexec.DataSource, string, error)

ResolveSequenceStrategy freezes the effective native policy on a source copy before Open. It only reads SQLX dialect metadata on the source/caller owner; it never opens a Data capability or starts/finishes a transaction.

func (Source) WithSequenceStrategy

func (s Source) WithSequenceStrategy(strategy string) (dexec.DataSource, error)

Jump to

Keyboard shortcuts

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