Catalyst::Model::DBI(3) DBI Model Class

SYNOPSIS


# use the helper to create a model for example
perl script/myapp_create.pl model MyModel DBI dsn username password
# lib/MyApp/Model/DBI.pm
package MyApp::Model::DBI;
use base 'Catalyst::Model::DBI';
__PACKAGE__->config(
dsn => 'DBI:Pg:dbname=mydb;host=localhost',
username => 'pgsql',
password => '',
options => { AutoCommit => 1 },
loglevel => 1
);
1;
# or load settings from a config file via Config::General for example
# in your myapp.conf you could have
name MyApp
<Model::MyModel>
dsn "DBI:Pg:dbname=mydb;host=localhost"
username pgsql
password ""
<options>
AutoCommit 1
</options>
loglevel 1
</Model>
# note that config settings always override Model settings
# do something with $dbh inside a controller ...
my $dbh = $c->model('MyModel')->dbh;
# do something with $dbh inside a model ...
my $dbh = $self->dbh;
#do something with DBIx::Connector connection inside a controller ...
my $connection = $c->model('MyModel')->connection;
#do something with DBIx::Connector connection inside a model ...
my $connection = $self->connection;

DESCRIPTION

This is the "DBI" model class. It has been rewritten to use DBIx::Connector since it's internal code that deals with connection maintenance has already been ported into there. You now have two options for doing custom models with Catalyst. Either by using this model and any related modules as needed or by having your custom model decoupled from Catalyst and glued on using Catalyst::Model::Adaptor

Some general rules are as follows. If you do not wish to use DBIx::Connector directly or DBI and setup connections in your custom models or have glue models, then use this model. If you however need models that can be re-used outside of your application or simply wish to maintain connection code yourself outside of the Catalyst, then use Catalyst::Model::Adaptor which allows you to glue outside models into your Catalyst app.

METHODS

new
Initializes DBI connection
$self->connection
Returns the current DBIx::Connector connection handle.
$self->dbh
Returns the current database handle.
$self->connect
Connects to the database and returns the handle.

AUTHOR

Alex Pavlovic, "[email protected]"

COPYRIGHT

Copyright (c) 2005 - 2012 the Catalyst::Model::DBI ``AUTHOR'' as listed above.

LICENSE

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.