NAME
DBIx::Fast::Transaction - Transaction management for DBIx::Fast
SYNOPSIS
# Usually through DBIx::Fast::txn
$db->txn(sub {
$db->insert('accounts', { id => 1, balance => 100 });
$db->transaction->savepoint('before_fee');
eval { charge_fee($db); 1 }
or $db->transaction->rollback_to('before_fee');
}, { max_retries => 3, isolation => 'REPEATABLE READ' });
my $stats = $db->transaction->get_stats; # success/error/deadlock counts
DESCRIPTION
Manages database transactions with support for nested transactions, savepoints, automatic deadlock retry, and performance statistics tracking. Transactions that exceed the slow threshold (5 seconds) emit a warning.
METHODS
do
my $result = $tx->do(sub { ... }, \%options);
Executes a code block inside a transaction. Supports nested calls, automatic commit/rollback, and deadlock retry. Options: max_retries (default 3), retry_delay (default 1 second).
savepoint
$tx->savepoint('my_savepoint');
Creates a named savepoint within an active transaction.
rollback_to
$tx->rollback_to('my_savepoint');
Rolls back to the named savepoint and removes any savepoints created after it.
get_stats
my $stats = $tx->get_stats();
Returns a hashref with transaction statistics: total_count, success_count, error_count, deadlock_count, total_duration, max_duration, and avg_duration.
reset_stats
Resets all transaction statistics counters to zero.
SEE ALSO
DBIx::Fast, "txn" in DBIx::Fast, DBIx::Fast::X (Deadlock, LockTimeout)
AUTHOR
SeHarrys
LICENSE
This is free software under the Artistic License 2.0.