Class::DBI::Query(3)

✨ Class::DBI::Query(3) ✨

okay so real talk, bestie β€” this is a page from Class::DBI::Query, part of the User Contributed Perl Documentation crew, and the very first thing you need to know is right in the title: it's deprecated. Like, this is the old SQL manager for Class::DBI. It's been sidelined. Still iconic in its day though πŸ’…


πŸŽ€ NAME πŸŽ€

Class::DBI::Query β€” Deprecated SQL manager for Class::DBI. That's it. That's the whole name. She's a legacy queen and we respect her πŸ‘‘


⭐ SYNOPSIS ⭐

Here's the whole vibe in code, no notes:

        my $sth = Class::DBI::Query
                ->new({
                        owner => $class,
                        sqlname => $type,
                        essential => \@columns,
                        where_columns => \@where_cols,
                })
                ->run($val);

look at her go 😭 new it up with a hashref, then run it with your value. slay.


πŸ’– DESCRIPTION πŸ’–

So what does this thing do? It abstracts away a whole bunch of the messy little details of the SQL mechanism that lives underneath Class::DBI. Basically it's the middle manager of your queries 🫢

ngl though β€” for the most part, you probably don't want to be interfacing directly with this. Like, it's behind the curtain for a reason, bestie. Let the framework handle it πŸ™ˆ

⚠️ heads up! The underlying mechanisms are not yet stable, and are subject to change at any time. That's not me being dramatic, that's literally what the docs say. So don't build your whole personality around this API, okay? πŸ’€

🌸 OPTIONS 🌸

A Query can have many options set before executing. Most of them can either be passed as an option to new(), or set later if you're building the query up dynamically β€” which is honestly such a flex, you can just keep adding to her as you go πŸ¦‹

πŸ‘‘ owner

The Class::DBI subclass that 'owns' this query. In the vast majority of cases a query will return objects β€” and the owner is the class of which instances will be returned. So like, the owner is the vibe, the objects are the guest list πŸ’–

🧚 sqlname

This should be the name of a query set up using set_sql. That's it. That's the whole thing. iykyk ✨

🌈 where_clause

This is the raw SQL that will be substituted into the 'WHERE %s' in your query. If you've got multiple %s's in your query, then you should supply a listref of where_clauses β€” one for each, no skipping, bestie πŸŽ€

This SQL can also include placeholders, which will be used when you call run(). Cute, right? πŸ“

πŸ’œ essential

When retrieving rows from the database that match the WHERE clause of the query, these are the columns that we fetch back and pre-load the resulting objects with. Obsessed with pre-loading honestly, it's giving efficiency πŸ’…

By default, this is the Essential column group of the owner class. defaults are a gift 🫢


πŸ”₯ METHODS πŸ”₯

⭐ where()

        $query->where($match, @columns);

This will extend your 'WHERE' clause by adding a 'AND $column = ?' (or whatever $match is, instead of "=") for each column you pass in. So like, one chunk per column, add 'em all, go off πŸ’€

And if you've got multiple WHERE clauses? This will extend the last one. not the first, not the middle β€” the last. don't forget it or you'll be confused for an hour, trust me 😭


and that's the whole page, bestie! go forth and query responsibly πŸŒΈπŸ’–

with love, from the perl v5.42.0 girlies β€” dated a very vintage 2011-04-08 πŸŽ€

πŸ“¦ where this page comes from