DBIx::Class::Helper::SimpleStats - Simple grouping and aggregate functions for DBIx::Class
version v0.1.3
In a resultset class:
package My::Schema::ResultSet::Foo; use base 'DBIx::Class::ResultSet'; __PACKAGE__->load_components('Helper::SimpleStats'); ...
In code
my @stats = $rs->simple_stats( 'name' )->all;
is roughly equivalent to
my @stats = $rs->search_rs( undef, { select => [qw/ name /, { count => 'name' }], as => [qw/ name name_count /], group_by => [qw/ name /], order_by => [qw/ name /], } )->all;
This is a simple helper method for DBIx::Class resultsets to run simple aggregate queries.
simple_stats
my $stats_rs => $rs->simple_stats( @columns );
The simplest usage is to pass a single column name, and obtain a count of rows for each value of that column.
However, you could specify multiple columns or functions, and optional column names:
$rs->simple_stats( { min => 'cost' }, { max => 'cost' }, { sum => 'cost', -as => 'total_cost' }, { count => 'cost', -as => 'num_purchases' }, );
DBIx::Class
The development version is on github at https://github.com/robrwo/DBIx-Class-Helper-SimpleStats and may be cloned from git://github.com/robrwo/DBIx-Class-Helper-SimpleStats.git
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/DBIx-Class-Helper-SimpleStats/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Robert Rothenberg <rrwo@cpan.org>
The initial development of this module was sponsored by Science Photo Library https://www.sciencephoto.com.
This software is Copyright (c) 2019 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install DBIx::Class::Helper::SimpleStats, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::Helper::SimpleStats
CPAN shell
perl -MCPAN -e shell install DBIx::Class::Helper::SimpleStats
For more information on module installation, please visit the detailed CPAN module installation guide.