DBIx::OO is a database to Perl objects abstraction.
SYNOPSIS
package MyDB;
use base 'DBIx::OO';
# We need to overwrite get_dbh since it's an abstract function.
# The way you connect to the DB is really your job; this function
# should return the database handle. The default get_dbh() croaks.
my $dbh;
sub get_dbh {
$dbh = DBI->connect_cached('dbi:mysql:test', 'user', 'passwd')
if !defined $dbh;
return $dbh;
}
package MyDB::Users;
use base 'MyDB';
__PACKAGE__->table('Users');
__PACKAGE__->columns(P => [ 'id' ],
E => [qw/ first_name last_name email /]);
__PACKAGE__->has_many(pages => 'MyDB::Pages', 'user');
package MyDB::Pages;
use base 'MyDB';
__PACKAGE__->table('Pages');
__PACKAGE__->columns(P => [ 'id' ],
E => [qw/ title content user /]);
__PACKAGE__->has_a(user => 'MyDB::Users');
package main;
my $u = MyDB::Users->create({ id => 'userid',
first_name => 'Q',
last_name => 'W' });
my $foo = MyDB::Users->retrieve('userid');
my @p = @{ $foo->fk_pages };
print "User: ", $foo->first_name, " ", $foo->last_name, " pages:n";
foreach (@p) {
print $_->title, "n";
}
$foo->first_name('John');
$foo->last_name('Doe');
# or
$foo->set(first_name => 'John', last_name => 'Doe');
$foo->update;
Product's homepage
Requirements:
· Perl
What's New in This Release: [ read full changelog ]
· Fixed bug in search_join_X methods: $#{@$row} no longer works to determine the index of the last element in an array ref, it returns -1 instead. Either it never worked (but AFAIR it did) or it somehow broke in Perl 5.10.