DBIx::...rations(3pm)
π NAME π
DBIx::Class::Helper::ResultSet::SetOperations β the bestie that lets you do set operations with DBIx::Class. That's it, that's the whole vibe. π¦
This page is from the User Contributed Perl Documentation collection, iykyk.
β¨ SYNOPSIS β¨
okay so first you gotta load the component into your ResultSet class, like:
package MyApp::Schema::ResultSet::Foo;
__PACKAGE__->load_components(qw{Helper::ResultSet::SetOperations});
...
1;
and then elsewhere, like literally in a controller, you go:
my $rs1 = $rs->search({ foo => 'bar' });
my $rs2 = $rs->search({ baz => 'biff' });
for ($rs1->union($rs2)->all) { ... }
and boom π₯ set operations just work. periodt.
πΈ DESCRIPTION πΈ
This component lets you use various set operations with your ResultSets. Want a nice way to apply it to your <em>entire</em> schema? Peep "NOTE" in DBIx::Class::Helper::ResultSet. π
Heads up bestie: this component throws exceptions if your ResultSets have different ResultClasses or different "Columns Specs." No cap.
The whole idea, fr fr: in SQL, if you use a set operation, they must be selecting the same column names, so all the results match up. And the deal with the ResultClasses is that DBIC needs to inflate the results <em>the same way</em> for the entire ResultSet β so if you tried to apply something like a union on a table with the same column name but <em>different</em> classes, DBIC would not be doing what you'd expect. π
A really cute way to use this is with DBIx::Class::ResultClass::HashRefInflator. π
You might have something like this lil sketch autocompletion code:
my $rs1 = $schema->resultset('Album')->search({
name => { -like => "$input%" }
}, {
columns => [qw( id name ), {
tablename => \['?', [{} => 'album']],
}],
});
my $rs2 = $schema->resultset('Artist')->search({
name => { -like => "$input%" }
}, {
columns => [qw( id name ), {
tablename => \['?', [{} => 'artist']],
}],
});
my $rs3 = $schema->resultset('Song')->search({
name => { -like => "$input%" }
}, {
columns => [qw( id name ), {
tablename => \['?', [{} => 'song']],
}],
});
$_->result_class('DBIx::Class::ResultClass::HashRefInflator')
for ($rs1, $rs2, $rs3);
my $data = [$rs1->union([$rs2, $rs3])->all];
ate. π
π METHODS π
π¦ union
π¦ union_all
π¦ intersect
π¦ intersect_all
π¦ except
π¦ except_all
All of these methods take a single ResultSet or an ArrayRef of ResultSets β and that's the only parameter, bestie. One arg, that's the whole meal. π
Oracle girlies listen up: on Oracle,exceptwill issue aMINUSoperation. Not a drill. π₯
π AUTHOR π
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> β the icon, the moment, the main character. π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt. π
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay.
perl v5.40.0 Β· 2024-11-16 β that's the version + date stamp from the footer, mwah π thanks for reading, bestie, go union some ResultSets, you got this β¨πΈπ§
π¦ where this page comes from
- debian trixie: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-class-helpers-perl 2.037000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms