Documentation
¶
Overview ¶
Package dml provides the SQLX-backed buffered write and transaction scope.
Index ¶
- Constants
- Variables
- type Data
- func (d *Data) Allocate(ctx context.Context, tableName string, dest any, selector string) error
- func (d *Data) BeginInvocation() error
- func (d *Data) Complete(ctx context.Context, cause error) error
- func (d *Data) ComponentData(relation, order string) xhandler.Data
- func (d *Data) Delete(tableName string, data any) error
- func (d *Data) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (d *Data) Execute(dml string, args ...any) error
- func (d *Data) Flush(ctx context.Context, tableName string) error
- func (d *Data) FrameworkValidator() xhandler.Validator
- func (d *Data) Insert(tableName string, data any) error
- func (d *Data) PrepareCompletion(ctx context.Context) error
- func (d *Data) PrepareFinalization(ctx context.Context) error
- func (d *Data) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (d *Data) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- func (d *Data) Reserve(ctx context.Context, tableName string, dest any, selector string) error
- func (d *Data) SealComponent()
- func (d *Data) Start(ctx context.Context) error
- func (d *Data) TransactionOutcome() xhandler.TransactionOutcome
- func (d *Data) Update(tableName string, data any) error
- func (d *Data) ValidationConnection(ctx context.Context, connector string) (validation.Connection, error)
- type Option
- type Source
- func (s Source) InvocationKey() any
- func (s Source) InvocationSequenceStrategy() string
- func (s Source) InvocationTransactionKey() any
- func (s Source) Open(ctx context.Context) (xhandler.Data, error)
- func (s Source) ResolveSequenceStrategy(ctx context.Context) (dexec.DataSource, string, error)
- func (s Source) WithSequenceStrategy(strategy string) (dexec.DataSource, error)
Constants ¶
const ( ComponentBinding = "binding" ComponentImperative = "imperative" )
Variables ¶
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 (*Data) BeginInvocation ¶
BeginInvocation switches Data from standalone auto-commit behavior to one root-owned transaction completed by Complete after output finalization.
func (*Data) Complete ¶
Complete drains the invocation journal and completes only locally owned transactions. Caller-supplied transactions always remain open.
func (*Data) ComponentData ¶
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) ExecContext ¶
ExecContext executes immediately through the invocation-owned transaction. It never flushes pending buffered writes implicitly.
func (*Data) FrameworkValidator ¶
FrameworkValidator is an optional internal Data capability. Engine adapters expose only Validator, retaining database and transaction ownership here.
func (*Data) PrepareCompletion ¶
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 ¶
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 ¶
QueryContext executes immediately through the invocation-owned transaction. It never flushes pending buffered writes implicitly.
func (*Data) QueryRowContext ¶
QueryRowContext executes immediately through the invocation-owned transaction. It never flushes pending buffered writes implicitly.
func (*Data) Reserve ¶
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 ¶
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) 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 WithSequenceStrategy ¶
func WithSequenceStrategy(strategy dialect.PresetIDStrategy) Option
WithSequenceStrategy selects a native allocation strategy for this data owner. Empty/undefined retains the native product default.
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 ¶
InvocationKey lets Datly's private invocation scope separate database units without exposing transaction or data-unit lifecycle through xdatly.
func (Source) InvocationSequenceStrategy ¶
func (Source) InvocationTransactionKey ¶
InvocationTransactionKey supports early child/root transaction conflict checks.
func (Source) ResolveSequenceStrategy ¶
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)