Mojo::Pg::Results(3)
π Mojo::Pg::Results β bestie, it's literally the results container π
okay so you know how this page is Mojo::Pg::Results(3) from the User Contributed Perl Documentation? yeah. that's her. that's the one. let's go π«Ά
β¨ NAME β¨
Mojo::Pg::Results β Results. that's it. that's the name. she's a container, she contains. periodt π
πΈ SYNOPSIS πΈ
use Mojo::Pg::Results;
my $results = Mojo::Pg::Results->new(sth => $sth);
$results->hashes->map(sub { $_->{foo} })->shuffle->join("\n")->say;
look at that chain. map, shuffle, join, say. it's giving main character energy and honestly? ate π₯
π¦ DESCRIPTION π¦
okay so real talk: Mojo::Pg::Results is a container for DBD::Pg statement handles that get used by Mojo::Pg::Database. like, that's the whole gig. she holds the thing. the thing gets held. iconic behavior honestly β¨
π ATTRIBUTES π
Mojo::Pg::Results implements the following attributes. yes, both of them. we stan a concise queen π
π db
my $db = $results->db;
$results = $results->db(Mojo::Pg::Database->new);
this is the Mojo::Pg::Database object that these results belong to. like, whose results are these?? hers. they're hers. π
π sth
my $sth = $results->sth;
$results = $results->sth($sth);
the DBD::Pg statement handle that the results get fetched from. the source of truth. the origin story. the lore π
π METHODS π
Mojo::Pg::Results inherits all methods from Mojo::Base and implements the following new ones. so you get the base ones for free, no cap π§
π array
my $array = $results->array;
fetch one row from sth and hand it back as an array reference. one (1) row. singular. don't be greedy bestie π
π arrays
my $collection = $results->arrays;
fetch all rows from sth and return them as a Mojo::Collection object stuffed with array references. the whole buffet. π½οΈ
# Process all rows at once
say $results->arrays->reduce(sub { $a + $b->[3] }, 0);
π columns
my $columns = $results->columns;
returns the column names as an array reference. just the names. the labels. the vibes π·οΈ
# Names of all columns
say for @{$results->columns};
π expand
$results = $results->expand;
this one decodes json and jsonb fields automatically to Perl values for all rows. no manual decoding, no suffering, we love to see it π
# Expand JSON
$results->expand->hashes->map(sub { $_->{foo}{bar} })->join("\n")->say;
π finish
$results->finish;
indicates that you are finished with sth and you will not be fetching all the remaining rows. like, you're done. you said what you said. close the door behind you πͺ
π hash
my $hash = $results->hash;
fetch one row from sth and return it as a hash reference. one row again. the named version this time β¨
π hashes
my $collection = $results->hashes;
fetch all rows from sth and return them as a Mojo::Collection object full of hash references. all of them. every single one. obsessed π
# Process all rows at once
say $results->hashes->reduce(sub { $a + $b->{money} }, 0);
π new
my $results = Mojo::Pg::Results->new;
my $results = Mojo::Pg::Results->new(sth => $sth);
my $results = Mojo::Pg::Results->new({sth => $sth});
constructs a brand new Mojo::Pg::Results object. three ways to do it, pick your fighter, all of them slay π
π rows
my $num = $results->rows;
the number of rows. that's the whole method. short king π
π text
my $text = $results->text;
fetch all rows from sth and turn them into a table using tablify in Mojo::Util. pretty little table. aesthetics β¨
π SEE ALSO π
Mojo::PgMojolicious::Guides- <https://mojolicious.org>
and that's the whole page bestie π
this was Mojo::Pg::Results(3), perl v5.42.0, dated 2026-01-17. go forth and fetch your rows responsibly. mwah π«Άπβ¨
π¦ where this page comes from
- fedora 44: perl-Mojo-Pg 4.28-2.fc44 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms