Class::DBI::Sweet

Class::DBI::Sweet is a Perl module that provides convenient count, search, page, and cache functions in a sweet package.
Download

Class::DBI::Sweet Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Christian Hansen, Matt S Trout and Andy Grundman
  • Publisher web site:
  • http://search.cpan.org/~mramberg/

Class::DBI::Sweet Tags


Class::DBI::Sweet Description

Class::DBI::Sweet is a Perl module that provides convenient count, search, page, and cache functions in a sweet package. Class::DBI::Sweet is a Perl module that provides convenient count, search, page, and cache functions in a sweet package. It integrates these functions with Class::DBI in a convenient and efficient way.SYNOPSIS package MyApp::DBI; use base 'Class::DBI::Sweet'; MyApp::DBI->connection('dbi:driver:dbname', 'username', 'password'); package MyApp::Article; use base 'MyApp::DBI'; use DateTime; __PACKAGE__->table('article'); __PACKAGE__->columns( Primary => qw ); __PACKAGE__->columns( Essential => qw ); __PACKAGE__->has_a( created_on => 'DateTime', inflate => sub { DateTime->from_epoch( epoch => shift ) }, deflate => sub { shift->epoch } ); # Simple search MyApp::Article->search( created_by => 'sri', { order_by => 'title' } ); MyApp::Article->count( created_by => 'sri' ); MyApp::Article->page( created_by => 'sri', { page => 5 } ); MyApp::Article->retrieve_all( order_by => 'created_on' ); # More powerful search with deflating $criteria = { created_on => { -between => }, created_by => , title => { -like => } }; MyApp::Article->search( $criteria, { rows => 30 } ); MyApp::Article->count($criteria); MyApp::Article->page( $criteria, { rows => 10, page => 2 } ); MyApp::Article->retrieve_next( $criteria, { order_by => 'created_on' } ); MyApp::Article->retrieve_previous( $criteria, { order_by => 'created_on' } ); MyApp::Article->default_search_attributes( { order_by => 'created_on' } ); # Automatic joins for search and count MyApp::CD->has_many(tracks => 'MyApp::Track'); MyApp::CD->has_many(tags => 'MyApp::Tag'); MyApp::CD->has_a(artist => 'MyApp::Artist'); MyApp::CD->might_have(liner_notes => 'MyApp::LinerNotes' => qw/notes/); MyApp::Artist->search({ 'cds.year' => $cd }, # $cd->year subtituted { order_by => 'artistid DESC' }); my ($tag) = $cd->tags; # Grab first tag off CD my ($next) = $cd->retrieve_next( { 'tags.tag' => $tag }, { order_by => 'title' } ); MyApp::CD->search( { 'liner_notes.notes' => { "!=" => undef } } ); MyApp::CD->count( { 'year' => { '>', 1998 }, 'tags.tag' => 'Cheesy', 'liner_notes.notes' => { 'like' => 'Buy%' } } ); # Multi-step joins MyApp::Artist->search({ 'cds.tags.tag' => 'Shiny' }); # Retrieval with pre-loading my ($cd) = MyApp::CD->search( { ... }, { prefetch => } ); $cd->artist # Pre-loaded # Caching of resultsets (*experimental*) __PACKAGE__->default_search_attributes( { use_resultset_cache => 1 } ); Requirements: · Perl


Class::DBI::Sweet Related Software