Example::DB - Example class for DBIx::AnyDBD usage
use Example::DB Example::DB->set_dsn('dbi:Pg:dbname=foo'); Example::DB->set_user('matt'); Example::DB->set_password('blueberry'); my $db = Example::DB->instance(); my @users = $db->get_users(); # called from Example/DB/Pg.pm # NB: This is just an example. It is designed not for usage, # but so that you read the source code!
This is a couple of example class files that you can use and adapt in projects that use DBIx::AnyDBD. It is here as an example only, and not meant to be used as-is. That means you should copy the code into your own class hierarchy, rather than use it as Example::*.
The methods of most interest are those in DB/*.pm. These implement the database specific routines for each database. They encapsulate various things about each database, such as the ability to do nested transactions, how to retrieve the current id value for a table, and how dates are encapsulated. For most purposes you should put your SQL inside the Default.pm file, and only put stuff in the database specific files when necessary.
Most of the code in these files is originally by Dave Rolsky, with thanks.
To install DBIx::AnyDBD, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::AnyDBD
CPAN shell
perl -MCPAN -e shell install DBIx::AnyDBD
For more information on module installation, please visit the detailed CPAN module installation guide.