Name
Object::Relation::Setup::DB - Set up database stores
Synopsis
Description
This module inherits from Object::Relation::Setup to function as the base class for all store setup classes that build a data stores in databases. Its interface is defined entirely by Object::Relation::Setup.
Class Interface
Constructors
new
my $db_setup = Object::Relation::Setup::DB->new(\%params);
The constructor inherits from Object::Relation::Setup, but adds support for these parameters:
- dsn
-
The DSN to use to connect to the database via the DBI.
- user
-
The username to use when connecting to the database. Defaults to ''.
- pass
-
The password to use when connecting to the database. Defaults to ''.
Class Methods
dbd_class
my $dbd_class = Object::Relation::Setup::DB->dbd_class;
This abstract class method returns the name of the DBI database driver class, such as "DBD::Pg" or "DBD::SQLite". Defaults to using the last part of the schema class name (e.g., "Pg" for Object::Relation::Setup::DB::Pg) prepended with "DBD::".
dsn_dbd
my $dsn_dbd = Object::Relation::Setup::DB->dsn_dbd;
Returns the part of the database driver class name suitable for use in a DBI DSN. By default, this method simply returns the value returned by dbd_class(), but with the leading "DBD::" stripped off.
connect_attrs
DBI->connect(
$dsn, $user, $pass,
{ Object::Relation::Setup::DB->connect_attrs }
);
Returns a list of arugments to be used in the attributes hash passed to the DBI connect() method. By default, the arguments are:
RaiseError => 0,
PrintError => 0,
HandleError => Object::Relation::Exception::DBI->handler,
But they may be overridden or added to by subclasses.
Instance Interface
Instance Accessors
dsn
my $dsn = $setup->dsn;
$setup->dsn($dsn);
Gets or sets the DSN to use when connecting to the database via the DBI.
user
my $user = $setup->user;
$setup->user($user);
Gets or sets the username used to connect to the database via the DBI.
pass
my $pass = $setup->pass;
$setup->pass($pass);
Gets or sets the passname used to connect to the database via the DBI.
Instance Methods
setup
$setup->setup;
Sets up the data store by calling build_db().
build_db
$setup->build_db;
Builds the database.
connect
my $dbh = $setup->connect;
$dbh = $setup->connect(@args);
Connects to the database and returns the database handle, which is also stored in the dbh attribute. By default, it uses the dsn, user, and pass attributes to connect, but these can be overridden by passing them to the method as arguments, instead.
The attributes passed to DBI->connect are those returned by connect_attrs.
disconnect_all
$setup->disconnect_all;
Disconnects all cached connections to the database server (that is, created by calls to DBI->connect_cached for the driver returned by dbd_class(). Used by test_cleanup() methods and in other contexts.
Copyright and License
Copyright (c) 2004-2006 Kineticode, Inc. <info@obj_relode.com>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.