ObjectDB::Table - actions on tables
package MyDB; use base 'ObjectDB'; sub init_db { ... return $dbh; } package MyAuthor; use base 'MyDB'; __PACKAGE__->meta( table => 'author', columns => [qw/id name/], primary_key => 'id', auto_increment => 'id', relationships => { books => { type = 'one to many', class => 'MyBook', map => {id => 'author_id'} } } ); package MyBook; use base 'MyDB'; __PACKAGE__->meta( table => 'book', columns => [qw/id author_id title/], primary_key => 'id', auto_increment => 'id', relationships => { author => { type = 'many to one', class => 'MyAuthor', map => {author_id => 'id'} } } ); my @books = MyBook->table->find( with => 'author', order_by => [title => 'ASC'], page => 1, per_page => 10 );
ObjectDB::Table allows to perform actions on table: find, update, delete many rows at a time.
find
Finds specific rows.
my @books = MyBook->table->find; my @books = MyBook->table->find(where => [...]); my @books = MyBook->table->find(where => [...], order_by => [...]); my @books = MyBook->table->find(where => [...], order_by => [...], group_by => [...]);
count
A convenient method for counting.
my $total_books = MyBook->table->count;
update
Updates many rows at a time.
MyBook->table->update(set => {author_id => 1}, where => [author_id => 2]);
delete
Deletes many rows at a time.
MyBook->table->delete; MyBook->table->delete(where => [...]);
To install ObjectDB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ObjectDB
CPAN shell
perl -MCPAN -e shell install ObjectDB
For more information on module installation, please visit the detailed CPAN module installation guide.