DBIx::Handler - fork-safe and easy transaction handling DBI handler
use DBIx::Handler; my $handler = DBIx::Handler->new($dsn, $user, $pass, $dbi_opts, $opts); my $dbh = $handler->dbh; $dbh->do(...);
DBIx::Handler is fork-safe and easy transaction handling DBI handler.
DBIx::Handler provide scope base transaction, fork safe dbh handling, simple.
get database handling instance.
Options:
Execute SQL or CodeRef when connected/disconnected.
This is a query method's result class. If this value is defined, $result_class-new($handler, $sth)> is called in query() and query() returns the instance.
query
$result_class-
query()
Enables to inject a caller information as SQL comment.
Ignore to inject the SQL comment when trace_ignore_if's return value is true.
By default, ping before each executing query. If it affect performance then you can set to true for ping stopping.
By default, this module uses generally DBI class. For example, if you want to use another custom class compatibility with DBI, you can use it with this option.
By default, this module uses generally prepare method. For example, if you want to use prepare_cached method or other custom method compatibility with prepare method, you can use it with this option.
prepare_cached
prepare
connect method is alias for new method.
get fork safe DBI handle.
disconnect current database handle.
Creates a new transaction scope guard object.
do { my $txn_guard = $handler->txn_scope; # some process $txn_guard->commit; }
If an exception occurs, or the guard object otherwise leaves the scope before $txn->commit is called, the transaction will be rolled back by an explicit "txn_rollback" call. In essence this is akin to using a "txn_begin"/"txn_commit" pair, without having to worry about calling "txn_rollback" at the right places. Note that since there is no defined code closure, there will be no retries and other magic upon database disconnection.
$txn->commit
Get the DBIx::TransactionManager instance.
start new transaction.
commit transaction.
rollback transaction.
are you in transaction?
execute $coderef in auto transaction scope.
begin transaction before $coderef execute, do $coderef with database handle, after commit or rollback transaction.
$handler->txn(sub { my $dbh = shift; $dbh->do(...); });
equals to:
$handler->txn_begin; my $dbh = $handler->dbh; $dbh->do(...); $handler->txn_rollback;
execute $coderef.
my $rs = $handler->run(sub { my $dbh = shift; $dbh->selectall_arrayref(...); });
or
my @result = $handler->run(sub { my $dbh = shift; $dbh->selectrow_array('...'); });
execute query. return database statement handler.
inject a caller information as a SQL comment to $sql when trace_query is true.
$sql
The setters and the getters for options.
Atsushi Kobayashi <nekokak _at_ gmail _dot_ com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBIx::Handler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Handler
CPAN shell
perl -MCPAN -e shell install DBIx::Handler
For more information on module installation, please visit the detailed CPAN module installation guide.