txnode

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package txnode provides a transaction node for chaining SQL operations within a single transaction.

Index

Constants

This section is empty.

Variables

View Source
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

func (txn *TxNode) CommitIfNeeded() error

CommitIfNeeded commits the transaction only if this node is marked as the end.

func (*TxNode) IsEnd added in v0.1.2

func (txn *TxNode) IsEnd() bool

IsEnd return TxNode.isEnd or false if txn == nil

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

func (txn *TxNode) RollbackTransaction() error

RollbackTransaction rolls back the transaction if one exists.

func (*TxNode) RollbackTransactionAndLog

func (txn *TxNode) RollbackTransactionAndLog(
	log *slog.Logger,
	op string,
	err error,
) error

RollbackTransactionAndLog rolls back the transaction and logs both the rollback and the original error. Returns a wrapped error with the operation name.

func (*TxNode) SetEnd

func (txn *TxNode) SetEnd()

SetEnd marks this node as the end of the transaction chain.

func (*TxNode) UnsetEnd added in v0.1.0

func (txn *TxNode) UnsetEnd()

UnsetEnd marks this node as not being the end of the transaction chain.

Jump to

Keyboard shortcuts

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