DBIx::Class::Helper::WindowFunctions - Add support for window functions and aggregate filters to DBIx::Class
version v0.7.0
In a resultset:
package MyApp::Schema::ResultSet::Wobbles;
use base qw/DBIx::Class::ResultSet/;
__PACKAGE__->load_components( qw/
Helper::WindowFunctions
/);
Using the resultset:
my $rs = $schema->resultset('Wobbles')->search_rs(
undef,
{
'+select' => {
avg => 'fingers',
-filter => { hats => { '>', 1 } },
-over => {
partition_by => 'hats',
order_by => 'age',
},
},
'+as' => 'avg',
}
);
This helper adds rudimentary support for window functions and aggregate filters to DBIx::Class resultsets.
It adds the following keys to the resultset attributes:
This is used for window functions, e.g. the following adds a row number columns
'+select' => {
row_number => [],
-over => {
partition_by => 'class',
order_by => 'score',
},
},
which is equivalent to the SQL
ROW_NUMBER() OVER ( PARTITION BY class ORDER BY score )
You can omit either the partition_by
or order_by
clauses.
This is used for filtering aggregate functions or window functions, e.g. the following clause
'+select' => {
count => \ 1,
-filter => { kittens => { '<', 10 } },
},
is equivalent to the SQL
COUNT(1) FILTER ( WHERE kittens < 10 )
You can apply filters to window functions, e.g.
'+select' => {
row_number => [],
-filter => { class => { -like => 'A%' } },
-over => {
partition_by => 'class',
order_by => 'score',
},
},
which is equivalent to the SQL
ROW_NUMBER() FILTER ( WHERE class like 'A%' ) OVER ( PARTITION BY class ORDER BY score )
The -filter
feature was added v0.6.0.
This module is experimental.
Not all databases support window functions.
Since v0.7.0, the this module requires Perl v5.20 or later.
Future releases may only support Perl versions released in the last ten years.
The development version is on github at https://github.com/robrwo/DBIx-Class-Helper-ResultSet-WindowFunctions and may be cloned from git://github.com/robrwo/DBIx-Class-Helper-ResultSet-WindowFunctions.git
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/DBIx-Class-Helper-ResultSet-WindowFunctions/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.
Security issues should not be reported on the bugtracker website. Please see SECURITY.md
for instructions how to
report security vulnerabilities
Robert Rothenberg rrwo@cpan.org
Peter Rabbitson ribasushi@leporine.io
This software is Copyright (c) 2018-2024 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)