NAME
DBR - Database Repository ORM (object-relational mapper).
DESCRIPTION
DBR (Database Repository) is a fairly directed attempt at an Object Relational Mapper. It is not trying to be all things to all people. It's focus is on managing large schemas with an emphasis on metadata, rather than defining schema structure with code.
See DBR::Manual for more details.
SYNOPSIS
use DBR ( conf => '/path/to/my/DBR.conf' );
my $music = dbr_connect('music');
my $artists = $music->artist->all;
print "Artists:\n";
while (my $artist = $artists->next) {
print "\t" . $artist->name . "\n";
}
EXPORT
use DBR (
conf => '/path/to/my/DBR.conf' # Required ( unless app is specified )
# Remaining parameters are optional
app => 'myapp' # auto generated by default
use_exceptions => 1, # default
logpath => '/tmp/dbr_auto.log' # default
loglevel => 'warn' # default. allows: none info warn error debug debug2 debug3
);
Note: specify parameter: app => 'myappname' to allow multiple libraries to share one connection pool. Only the library loaded first needs to specify conf and the other parameters. Subsequent libraries can then specify only app => 'myappname'
When you "use DBR" with arguments, as above, the default behavior is to export the following methods into your class
dbr_connect( $schema [, $class] );
Connect to an instance of the specified schema
my $music = dbr_connect('music');
Optionally accepts a $class argument, to specify which instance. Defaults to "master"
Returns a DBR::Handle object representing your connection handle
dbr_instance( $schema [, $class] );
Similar to dbr_connect, but returns a DBR::Config::Instance object instead of a DBR::Handle object.
my $instance = dbr_connect('music');
An instance object represents the instance of the database schema in question, without necessarily being connected to it.
METHODS
new
Constructor. Useful in situations where you do not wish to export dbr_connect and dbr_instance into your class ( described above )
my $logger = new DBR::Util::Logger( -logpath => 'dbr.log' );
my $dbr = new DBR(
-logger => $logger,
-conf => '/path/to/my/DBR.conf'
);
my $handle = $dbr->connect( 'music' );
arguments
- -logger
-
DBR::Util::Logger object ( required )
- -conf
-
path to the DBR.conf you wish to use ( required )
- -use_exceptions
-
Boolean. Causes all DBR errors to raise an exception, rather than logging an returning false ( default )
- -admin
-
Boolean. Enables configuration objects to write changes to metadata DB ( don't use )
- -fudge_tz
-
Boolean. Prevents DBR from aborting in the event that it cannot determine the system timezone.
Returns a DBR object.
connect
Same arguments as dbr_connect above
get_instance
Same arguments as dbr_instance above
flush_handles
Disconnects all active database connections. Useful if you need to fork your process