DBIx::Simple::Inject - Injects DBIx::Simple methods into DBI
use DBI; my $dbh = DBI->connect( 'dbi:SQLite:dbname=:memory:', '', '', { RootClass => 'DBIx::Simple::Inject', RaiseError => 1, PrintError => 0, ShowErrorStatement => 1, } ); # of course can use dbh methods, $dbh->do('create table users (id, name)'); # and also can use DBIx::Simple methods! my $row = $dbh->query('select * from users where id = ?', 123)->hash; my $res = $dbh->insert(users => { name => "John", });
DBIx::Simple::Inject is-a DBI::db. This module injects DBIx::Simple power into DBI itself. So you can use this module directly or via "RootClass".
"RootClass"
use DBIx::Simple::Inject; my $dbh = DBIx::Simple::Inject->connect( ... );
or
use DBI; my $dbh = DBI->connect( ..., { RootClass => 'DBIx::Simple::Inject', });
This is useful when you use several modules (like DBIx::Connector) that take same as DBI's connect info.
You can set or access DBIx::Simple's property using "private_dbixsimple" attribute.
"private_dbixsimple"
my $db = DBI->connect( 'dbi:...', 'user', 'pass', { RootClass => 'DBIx::Simple::Inject', RaiseError => 1, private_dbixsimple => { lc_columns => 0, keep_statements => 20, result_class => 'MyApp::Result', abstract => 'SQL::Maker', }, }, );
For convenience, abstract can take some module names. Supported module names are as follows:
abstract
SQL::Abstract SQL::Abstract::Limit SQL::Maker
You can also set callback for your own modules as follows.
my $db = DBI->connect( ..., { RootClass => 'DBIx::Simple::Inject', private_dbixsimple => { abstract => sub { my $dbh = shift; My::SQL::Generator->new(driver => $dbh->{Driver}{Name}); }, }, }, );
You can use the following methods from DBIx::Simple in addition to all DBI database handle methods.
$dbh->query()
$dbh->select()
$dbh->insert()
$dbh->update()
$dbh->delete()
$dbh->iquery()
$dbh->error()
$dbh->begin()
Note: Besides these, DBIx::Simple provides commit(), rollback() and func(), etc. DBI database handles already provides these methods.
commit()
rollback()
func()
$dbh->lc_columns()
$dbh->keep_statements()
$dbh->result_class()
$dbh->abstract()
These are accessor methods to DBIx::Simple properties.
Yes.
OK I know that DBIx namespace is hodgepodge. Several authors should know that DBI itself has a lot of useful features already (like "Callbacks").
However, if you don't want ORM but want result set object (blessed result), I think DBIx::Simple makes great success. The module has nice API.
Some useful CPAN modules (that knows DBI's true power) takes $dbh or same arguments as DBI->connect(). That's why I made this module.
$dbh
DBI->connect()
DBIx::Simple, DBI
Naoki Tomita <tomita@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBIx::Simple::Inject, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Simple::Inject
CPAN shell
perl -MCPAN -e shell install DBIx::Simple::Inject
For more information on module installation, please visit the detailed CPAN module installation guide.