Catalyst::Model::DBI(3pm)

Catalyst::Model::DBI3pm

Dbi model class

Usage

  # 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;

Overview

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.

Releases

10 releases since Debian 4.0 (Etch); the text changed 6 times.

  1. 4.0
  2. 5.0
  3. 6.0
  4. 7
  5. 8–10
  6. 11
  7. 12–13

Author

Alex Pavlovic, "[email protected]"

License

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

From libcatalyst-model-dbi-perl 0.32-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.