Class::...tSearch(3)
π NAME π
okay so this is Class::...tSearch(3), straight outta User Contributed Perl Documentation, and the module is Class::DBI::Plugin::DeepAbstractSearch β deep_search_where() for Class::DBI. slay. π
β¨ SYNOPSIS β¨
bestie, here's the tiny starter pack:
use base 'Class::DBI';
use Class::DBI::Plugin::DeepAbstractSearch;
my @cds = Music::CD->deep_search_where(
{
'artist.name' => $artist_name
}
);
π DESCRIPTION π
This plugin gives you a SQL::Abstract search method for Class::DBI. It's similar to Class::DBI::AbstractSearch, but it also lets you search and sort by fields from joined tables. iconic behavior, honestly. β¨
Note: when you're searching and sorting by fields of the current class only, it's more efficient to use Class::DBI::AbstractSearch. lowkey important, bestie.
π«Ά METHODS π«Ά
deep_search_where π
my @cds = Music::CD->deep_search_where(
{
'artist.name' => $artist_name
}
);
This method gets exported into the calling class, and it lets you search objects using SQL::Abstract format β based on fields from the calling class and fields in classes related through a (chain of) 'has_a' relationships to the calling class. yes, we're going deep deep. π¦
When you specify a field in a related class, you separate it with a period from the corresponding foreign key field in the primary class.
package Music::Artist;
use base 'Class::DBI';
Music::Artist->table('artist');
Music::Artist->columns(All => qw/artistid name/);
Music::Artist->has_many(cds => 'Music::CD');
package Music::CD;
use base 'Class::DBI';
Music::CD->table('cd');
Music::CD->columns(All => qw/cdid artist title year/);
Music::CD->has_many(tracks => 'Music::Track');
Music::CD->has_a(artist => 'Music::Artist');
package Music::Track;
use base 'Class::DBI';
Music::Track->table('track');
Music::Track->columns(All => qw/trackid cd position title/);
## Tracks on all CDs with the title "Greatest Hits"
@tracks = Music::Track->deep_search_where(
{
'cd.title' => "Greatest Hits"
},
{
sort_by => 'cd.title'
}
);
## Tracks on CDs by Willie Nelson, sorted by CD Title and Track Position
@tracks = Music::Track->deep_search_where(
{
'cd.artist.name' => "Willie Nelson"
},
{
sort_by => 'cd.title, position'
}
);
## First 3 Tracks on CDs, whose title contains "Outlaw", by Willie Nelson
@tracks = Music::Track->deep_search_where(
{
'cd.artist.name' => "Willie Nelson",
'cd.title' => { -like => '%Outlaw%' },
position => { '<=' => 3 }
},
{
sort_by => 'cd.title, position'
}
);
count_deep_search_where π₯
my $num_cds = Music::CD->count_deep_search_where(
{
'artist.name' => $artist_name
}
);
This method gets exported into the calling class too, and it lets you count objects using SQL::Abstract format β based on fields from the calling class as well as fields in classes related through a (chain of) 'has_a' relationships to the calling class. counting era. π
get_deep_where π§
my ($what, $from, $where, $bind) = $class->get_deep_where($where, $attr);
This method also gets exported into the calling class, and it lets you retrieve SQL fragments used for creating queries. The parameters are the same as to deep_search_where. very behind-the-scenes main character energy. π
π AUTHOR π
Stepan Riha, "sriha@cpan.org" β iconic. π
π COPYRIGHT π
Copyright (C) 2005, 2007, 2008 Stepan Riha. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π¦ SEE ALSO π¦
Class::DBISQL::AbstractClass::DBI::AbstractSearch
kthxbye bestie π this page says perl v5.32.1 and 2022-07-22, so that's the source/version and date vibe β periodt. πβ¨
π¦ where this page comes from
- epel 9: perl-Class-DBI-Plugin-DeepAbstractSearch 0.08-39.el9 Β· GPL+ or Artistic
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms