| 1 |
NAME |
| 2 |
Catalyst::Model::DBI - DBI Model Class |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
# use the helper to create a model for example |
| 6 |
perl script/myapp_create.pl model MyModel DBI dsn username password |
| 7 |
|
| 8 |
# lib/MyApp/Model/DBI.pm |
| 9 |
package MyApp::Model::DBI; |
| 10 |
|
| 11 |
use base 'Catalyst::Model::DBI'; |
| 12 |
|
| 13 |
__PACKAGE__->config( |
| 14 |
dsn => 'DBI:Pg:dbname=mydb;host=localhost', |
| 15 |
username => 'pgsql', |
| 16 |
password => '', |
| 17 |
options => { AutoCommit => 1 }, |
| 18 |
loglevel => 1 |
| 19 |
); |
| 20 |
|
| 21 |
1; |
| 22 |
|
| 23 |
# or load settings from a config file via Config::General for example |
| 24 |
# in your myapp.conf you could have |
| 25 |
|
| 26 |
name MyApp |
| 27 |
|
| 28 |
<Model::MyModel> |
| 29 |
dsn "DBI:Pg:dbname=mydb;host=localhost" |
| 30 |
username pgsql |
| 31 |
password "" |
| 32 |
<options> |
| 33 |
AutoCommit 1 |
| 34 |
</options> |
| 35 |
loglevel 1 |
| 36 |
</Model> |
| 37 |
|
| 38 |
# note that config settings always override Model settings |
| 39 |
|
| 40 |
# do something with $dbh inside a controller ... |
| 41 |
my $dbh = $c->model('MyModel')->dbh; |
| 42 |
|
| 43 |
# do something with $dbh inside a model ... |
| 44 |
my $dbh = $self->dbh; |
| 45 |
|
| 46 |
#do something with DBIx::Connector connection inside a controller ... |
| 47 |
my $connection = $c->model('MyModel')->connection; |
| 48 |
|
| 49 |
#do something with DBIx::Connector connection inside a model ... |
| 50 |
my $connection = $self->connection; |
| 51 |
|
| 52 |
DESCRIPTION |
| 53 |
This is the "DBI" model class. It has been rewritten to use |
| 54 |
DBIx::Connector since it's internal code that deals with connection |
| 55 |
maintenance has already been ported into there. You now have two options |
| 56 |
for doing custom models with Catalyst. Either by using this model and |
| 57 |
any related modules as needed or by having your custom model decoupled |
| 58 |
from Catalyst and glued on using Catalyst::Model::Adaptor |
| 59 |
|
| 60 |
Some general rules are as follows. If you do not wish to use |
| 61 |
DBIx::Connector directly or DBI and setup connections in your custom |
| 62 |
models or have glue models, then use this model. If you however need |
| 63 |
models that can be re-used outside of your application or simply wish to |
| 64 |
maintain connection code yourself outside of the Catalyst, then use |
| 65 |
Catalyst::Model::Adaptor which allows you to glue outside models into |
| 66 |
your Catalyst app. |
| 67 |
|
| 68 |
METHODS |
| 69 |
new Initializes DBI connection |
| 70 |
|
| 71 |
$self->connection |
| 72 |
Returns the current DBIx::Connector connection handle. |
| 73 |
|
| 74 |
$self->dbh |
| 75 |
Returns the current database handle. |
| 76 |
|
| 77 |
$self->connect |
| 78 |
Connects to the database and returns the handle. |
| 79 |
|
| 80 |
SEE ALSO |
| 81 |
Catalyst, DBI, Catalyst::Model::Proxy, |
| 82 |
Catalyst::Model::DBI::SQL::Library |
| 83 |
|
| 84 |
AUTHOR |
| 85 |
Alex Pavlovic, "[email protected]" |
| 86 |
|
| 87 |
COPYRIGHT |
| 88 |
Copyright (c) 2005 - 2012 the Catalyst::Model::DBI "AUTHOR" as listed |
| 89 |
above. |
| 90 |
|
| 91 |
LICENSE |
| 92 |
This program is free software, you can redistribute it and/or modify it |
| 93 |
under the same terms as Perl itself. |
| 94 |
|