Class::...tSearch(3)

πŸ“¦
version 0.08 Β· 3 versions
, in epel 9

πŸŽ€ 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 (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::DBI
  • SQL::Abstract
  • Class::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