NAME
DBIx::TransactionManager - transaction handling for database.
SYNOPSIS
basic usage:
use DBI;
use DBIx::TransactionManager;
my $dbh = DBI->connect('dbi:SQLite:');
my $tm = DBIx::TransactionManager->new($dbh);
$tm->txn_begin;
$dbh->do("insert into foo (id, var) values (1,'baz')");
$tm->txn_commit;
scope_gurad usage:
use DBI;
use DBIx::TransactionManager;
my $dbh = DBI->connect('dbi:SQLite:');
my $tm = DBIx::TransactionManager->new($dbh);
my $txn = $tm->txn_scope;
$dbh->do("insert into foo (id, var) values (1,'baz')");
$txn->commit;
nested transaction usage:
use DBI;
use DBIx::TransactionManager;
my $dbh = DBI->connect('dbi:SQLite:');
my $tm = DBIx::TransactionManager->new($dbh);
{
my $txn = $tm->txn_scope;
$dbh->do("insert into foo (id, var) values (1,'baz')");
{
my $txn2 = $tm->txn_scope;
$dbh->do("insert into foo (id, var) values (2,'bab')");
$txn2->commit;
}
{
my $txn3 = $tm->txn_scope;
$dbh->do("insert into foo (id, var) values (3,'bee')");
$txn3->commit;
}
$txn->commit;
}
DESCRIPTION
DBIx::TransactionManager is a simple transaction manager. like DBIx::Class::Storage::TxnScopeGuard.
METHODS
my $tm = DBIx::TransactionManager->new($dbh)
get DBIx::TransactionManager's instance object. $dbh parameter must be required.
my $txn = $tm->txn_scope(%args)
get DBIx::TransactionManager::ScopeGuard's instance object. You may pass an optional argument to %args, to tell the scope guard where the scope was generated, like so:
sub mymethod {
my $self = shift;
my $txn = $tm->txn_scope( caller => [ caller() ] );
}
$self->mymethod();
This will allow the guard object to report the caller's location from the perspective of mymethod()
, not where txn_scope()
was called.
see "DBIx::TransactionManager::ScopeGuard's METHODS"
$tm->txn_begin
Start the transaction.
$tm->txn_rollback
Rollback the transaction.
$tm->txn_commit
Commit the transaction.
DBIx::TransactionManager::ScopeGuard's METHODS
$txn->commit
Commit the transaction.
$txn->rollback
Rollback the transaction.
$txn->in_transaction
are you in transaction?
AUTHOR
Atsushi Kobayashi <nekokak _at_ gmail _dot_ com>
SEE ALSO
DBIx::Class::Storage::TxnScopeGuard
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.