Class::DBI::Plugin::AggregateFunction - aggregate function for Class::DBI
package MyData::CD; use base qw/Class::DBI/; use Class::DBI::Plugin::AggregateFunction; __PACKAGE__->mk_aggregate_function('sum'); __PACKAGE__->mk_aggregate_function( max => 'maximum'); package main; # SELECT MAX(price) FROM __TABLE__ $max = MyData::CD->maximum( 'price' ); # SELECT SUM(price) FROM __TABLE__ WHERE artist = 'foo' $sum = MyData::CD->sum( 'price', artist => 'foo', ); $sum = MyData::CD->sum( 'price', { price => {'>=', 1000}, });
This module is for using an aggregate function easily by Class::DBI.
The aggregate function is added by using the mk_aggregate_function method.
The 1st argument is an aggregate function used by SQL.
The 2nd argument is a method name. When it is omitted, the aggregate function becomes a method name.
__PACKAGE__->mk_aggregate_function( 'max' );
or
__PACKAGE__->mk_aggregate_function( 'max' => 'maximum' );
The 1st argument of the aggregate function method is the target column name.
$max_price = MyData::CD->maximum( 'price' );
It is the same as the search_where method of Class::DBI::AbstractSearch after the 2nd argument.
# SELECT SUM(price) FROM __TABLE__ WHERE artist = 'foo' $total_price = MyData::CD->sum( 'price', 'artist' => 'foo', );
# SELECT SUM(price) FROM __TABLE__ WHERE price >= 1000 $total_price = MyData::CD->sum( 'price', { 'price' => {'>=', 1000}, });
ASAKURA Takuji <asakura.takuji+cpan@gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Class::DBI::AbstractSearch, Class::DBI
To install Class::DBI::Plugin::AggregateFunction, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::DBI::Plugin::AggregateFunction
CPAN shell
perl -MCPAN -e shell install Class::DBI::Plugin::AggregateFunction
For more information on module installation, please visit the detailed CPAN module installation guide.