Documentation
¶
Overview ¶
Package txnode provides a transaction node for chaining SQL operations within a single transaction.
Index ¶
- Variables
- type TxNode
- func (txn *TxNode) CommitIfNeeded() error
- func (txn *TxNode) IsEnd() bool
- func (txn *TxNode) PrepareQuery(ctx context.Context, db *sql.DB, query string) (*sql.Stmt, error)
- func (txn *TxNode) RollbackTransaction() error
- func (txn *TxNode) RollbackTransactionAndLog(log *slog.Logger, op string, err error) error
- func (txn *TxNode) SetEnd()
- func (txn *TxNode) UnsetEnd()
Constants ¶
This section is empty.
Variables ¶
var (
ErrTransactionArgsMismatch = errors.New("transaction args mismatch")
)
Functions ¶
This section is empty.
Types ¶
type TxNode ¶
type TxNode struct {
// contains filtered or unexported fields
}
TxNode represents a node in a transaction chain. It manages the lifecycle of a SQL transaction across multiple operations.
func New ¶ added in v0.1.0
func New() *TxNode
New creates a new TxNode ready to start a transaction.
func (*TxNode) CommitIfNeeded ¶
CommitIfNeeded commits the transaction only if this node is marked as the end.
func (*TxNode) PrepareQuery ¶
func (txn *TxNode) PrepareQuery( ctx context.Context, db *sql.DB, query string, ) (*sql.Stmt, error)
PrepareQuery prepares a SQL statement. It begins a transaction on first call or reuses the existing transaction. Returns nil if txn is nil (non-transactional mode).
func (*TxNode) RollbackTransaction ¶
RollbackTransaction rolls back the transaction if one exists.
func (*TxNode) RollbackTransactionAndLog ¶
RollbackTransactionAndLog rolls back the transaction and logs both the rollback and the original error. Returns a wrapped error with the operation name.