DBR - Database Repository ORM (object-relational mapper).
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.
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"; }
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
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
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.
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' );
DBR::Util::Logger object ( required )
path to the DBR.conf you wish to use ( required )
Boolean. Causes all DBR errors to raise an exception, rather than logging an returning false ( default )
Boolean. Enables configuration objects to write changes to metadata DB ( don't use )
Boolean. Prevents DBR from aborting in the event that it cannot determine the system timezone.
Returns a DBR object.
Same arguments as dbr_connect above
Same arguments as dbr_instance above
Disconnects all active database connections. Useful if you need to fork your process
To install DBR, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBR
CPAN shell
perl -MCPAN -e shell install DBR
For more information on module installation, please visit the detailed CPAN module installation guide.