NAME

Class::DBI::Plugin::AggregateFunction - create aggregate function for Class::DBI

SYNOPSYS

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},
});

DESCRIPTION

This module is for using an aggregate function easily by Class::DBI.

HOW TO USE =head2 Make Metod of Aggregate Function

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' );

Use Metod of Aggregate Function

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',
);

or

# SELECT SUM(price) FROM __TABLE__ WHERE price >= 1000
$total_price = MyData::CD->sum( 'price', {
	'price' => {'>=', 1000},
});

AUTHOR

ASAKURA Takuji <asakura.takuji+cpan@gmail.com>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Class::DBI::AbstractSearch

Class::DBI