5 CXGN::Ima::DBI - subclass of Ima::DBI, customizing it for use with the
10 ## this is a complete working script, notice you don't
11 ## have to create any database connections
14 use base qw/ Ima::DBI /;
16 __PACKAGE__->set_sql( get_all_foos => <<EOSQL );
20 my $sth = __PACKAGE__->sql_get_all_foos;
22 my $foo_names = $sth->fetchall_arrayref;
26 This is a customized subclass of Ima::DBI, an off-the-shelf,
27 well-tested connection sharing solution used by the popular
28 object-relational mapping package Class::DBI.
30 The reasons to use this package is that ALL SUBCLASSES OF THIS
31 PACKAGE SHARE THE SAME 'cxgn' DATABASE HANDLE.
34 - the DB handles it manages are now CXGN::DB::Connections,
35 not regular DBI connections
36 - the DB name in set_sql now defaults to 'cxgn', whereas in
37 vanilla Ima::DBI, it had no default
50 use base qw
/ Ima::DBI /;
51 use CXGN
::DB
::Connection
;
55 my $db_name = shift or $class->_croak("Need a db name");
58 $class->_remember_handle($db_name);
60 *{ $class . "::db_$db_name" } =
61 $class->_make_cxgn_db_closure(@_);
66 sub _make_cxgn_db_closure
{
67 my ($class, @connection) = @_;
70 unless ($dbh && $dbh->FETCH('Active') && $dbh->ping) {
71 $dbh = CXGN
::DB
::Connection
->new(@connection);
81 $class->SUPER::set_sql
(@_);
84 #make a db_Main with default connection args
85 __PACKAGE__
->set_db( 'cxgn' );