Mojo::...Results(3pm)
π NAME π
okay so welcome to the Mojo::SQLite::Results(3pm) page, part of the User Contributed Perl Documentation situation. The NAME is literally Mojo::SQLite::Results β Results. That's it. That's the whole name. π
β¨ SYNOPSIS β¨
bestie, here's the vibe in code form:
use Mojo::SQLite::Results;
my $results = Mojo::SQLite::Results->new(sth => $sth);
$results->hashes->map(sub { $_->{foo} })->shuffle->join("\n")->say;
πΈ DESCRIPTION πΈ
Mojo::SQLite::Results is a container for DBD::SQLite statement handles used by Mojo::SQLite::Database. That's the whole personality: it holds the statement-handle situation so the database can do its thing. β¨ main character energy β¨
π«Ά ATTRIBUTES π«Ά
Mojo::SQLite::Results implements the following attributes. lowkey important:
π¦ db π¦
my $db = $results->db;
$results = $results->db(Mojo::SQLite::Database->new);
The Mojo::SQLite::Database object these results belong to. It's giving "whose results are these?" and the answer is this db. π
π¦ sth π¦
my $sth = $results->sth;
$results = $results->sth($sth);
The DBD::SQLite statement handle results are fetched from. the source of the rows, fr fr. π
β METHODS β
Mojo::SQLite::Results inherits all methods from Mojo::Base and implements the following new ones. slay.
π new π
my $results = Mojo::SQLite::Results->new;
my $results = Mojo::SQLite::Results->new(sth => $sth);
my $results = Mojo::SQLite::Results->new({sth => $sth});
Construct a new Mojo::SQLite::Results object. fresh object, fresh vibes. π
π array π
my $array = $results->array;
Fetch next row from sth and return it as an array reference.
β οΈ note: finish needs to be called if you are not fetching all the possible rows. don't leave the sth hanging, bestie.
# Process one row at a time
while (my $next = $results->array) {
say $next->[3];
}
π arrays π
my $collection = $results->arrays;
Fetch all rows from sth and return them as a Mojo::Collection object containing array references.
# Process all rows at once
say $results->arrays->reduce(sub { $a + $b->[3] }, 0);
π columns π
my $columns = $results->columns;
Return column names as an array reference.
# Names of all columns
say for @{$results->columns};
π expand π
$results = $results->expand(json => 'some_json');
$results = $results->expand(json => ['some_json','other_json']);
Decode specified fields from a particular format to Perl values for all rows. Currently only the json text format is recognized. The names must exactly match the column names as returned by columns; it is recommended to use explicit aliases in the query for consistent column names. iykyk, exact match only. π
# Expand JSON
$results->expand(json => 'json_field')->hashes->map(sub { $_->{foo}{bar} })->join("\n")->say;
π finish π
$results->finish;
Indicate that you are finished with sth and will not be fetching all the remaining rows. closure, but for statement handles. periodt. π
π hash π
my $hash = $results->hash;
Fetch next row from sth and return it as a hash reference.
β οΈ note: finish needs to be called if you are not fetching all the possible rows. same rule, bestie.
# Process one row at a time
while (my $next = $results->hash) {
say $next->{money};
}
π hashes π
my $collection = $results->hashes;
Fetch all rows from sth and return them as a Mojo::Collection object containing hash references.
# Process all rows at once
say $results->hashes->reduce(sub { $a + $b->{money} }, 0);
π last_insert_id π
my $id = $results->last_insert_id;
Returns the rowid (https://www.sqlite.org/c3ref/last_insert_rowid.html) of the most recent successful INSERT. that's the id of the newest successful insert, no cap. π₯
π rows π
my $num = $results->rows;
Number of rows.
β οΈ note: for SELECT statements, this count will not be accurate until all rows have been fetched. so don't trust the count too early, bestie. π
π text π
my $text = $results->text;
Fetch all rows from sth and turn them into a table with tablify in Mojo::Util. cute little text table moment. π
π BUGS π
Report any issues on the public bugtracker. if something's cursed, that's where it goes. vibe check. π
π AUTHOR π
Dan Book, dbook@cpan.org. iconic. π
π COPYRIGHT AND LICENSE π
Copyright 2015, Dan Book.
This library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.
π¦ SEE ALSO π¦
Mojo::SQLite. go read that too, bestie. π«Ά
later, bestie β this was Mojo::SQLite::Results(3pm) from perl v5.42.0, dated 2022-03-23. stay slaying. β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojo-SQLite 3.009-bp160.1.4 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms