Catalyst::Model::CDBI::Sweet - Making sweet things sweeter
package MyApp::Model::CDBI; use base 'Catalyst::Model::CDBI::Sweet'; MyApp::Model::CDBI->connection('DBI:driver:database'); package MyApp::Model::Article; use base 'MyApp::Model::CDBI'; use DateTime; __PACKAGE__->table('article'); __PACKAGE__->columns( Primary => qw[ id ] ); __PACKAGE__->columns( Essential => qw[ title created_on created_by ] ); __PACKAGE__->has_a( created_on => 'DateTime', inflate => sub { DateTime->from_epoch( epoch => shift ) }, deflate => sub { shift->epoch } ); # Simple search MyApp::Model::Article->search( created_by => 'sri', { order_by => 'title' } ); MyApp::Model::Article->count( created_by => 'sri' ); MyApp::Model::Article->page( created_by => 'sri', { page => 5 } ); MyApp::Model::Article->retrieve_all( order_by => 'created_on' ); # More powerful search with deflating $criteria = { created_on => { -between => [ DateTime->new( year => 2004 ), DateTime->new( year => 2005 ), ] }, created_by => [ qw(chansen draven gabb jester sri) ], title => { -like => [ qw( perl% catalyst% ) ] } }; MyApp::Model::Article->search( $criteria, { rows => 30 } ); MyApp::Model::Article->count($criteria); MyApp::Model::Article->page( $criteria, { rows => 10, page => 2 } ); # Using Catalyst::Model::CDBI::Sweet with Catalyst::Model::CDBI package MyApp::Model::CDBI; use base 'Catalyst::Model::CDBI'; use Catalyst::Model::CDBI::Sweet; __PACKAGE__->config( dsn => 'dbi:driver:dbname', password => 'username', user => 'password', relationships => 1 ); sub new { my $class = shift; my $self = $class->NEXT::new(@_); foreach my $subclass ( $self->loader->classes ) { no strict 'refs'; unshift @{ $subclass . '::ISA' }, 'Catalyst::Model::CDBI::Sweet'; } return $self; }
This is the Catalyst::Model::CDBI::Sweet model class. It's built on top of Class::DBI::Sweet.
Christian Hansen <ch@ngmedia.com>
Danijel Milicevic, Jesse Sheidlower, Marcus Ramberg, Sebastian Riedel, Viljo Marrandi
#catalyst on irc://irc.perl.org
http://lists.rawmode.org/mailman/listinfo/catalyst
http://lists.rawmode.org/mailman/listinfo/catalyst-dev
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Catalyst
Class::DBI::Sweet
To install Catalyst::Model::CDBI::Sweet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::CDBI::Sweet
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::CDBI::Sweet
For more information on module installation, please visit the detailed CPAN module installation guide.