Mojo::SQLite::Results(3pm) | User Contributed Perl Documentation | Mojo::SQLite::Results(3pm) |
Mojo::SQLite::Results - Results
use Mojo::SQLite::Results; my $results = Mojo::SQLite::Results->new(sth => $sth); $results->hashes->map(sub { $_->{foo} })->shuffle->join("\n")->say;
Mojo::SQLite::Results is a container for DBD::SQLite statement handles used by Mojo::SQLite::Database.
Mojo::SQLite::Results implements the following attributes.
my $db = $results->db; $results = $results->db(Mojo::SQLite::Database->new);
Mojo::SQLite::Database object these results belong to.
my $sth = $results->sth; $results = $results->sth($sth);
DBD::SQLite statement handle results are fetched from.
Mojo::SQLite::Results inherits all methods from Mojo::Base and implements the following new ones.
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.
my $array = $results->array;
Fetch next row from "sth" and return it as an array reference. Note that "finish" needs to be called if you are not fetching all the possible rows.
# Process one row at a time while (my $next = $results->array) { say $next->[3]; }
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);
my $columns = $results->columns;
Return column names as an array reference.
# Names of all columns say for @{$results->columns};
$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.
# Expand JSON $results->expand(json => 'json_field')->hashes->map(sub { $_->{foo}{bar} })->join("\n")->say;
$results->finish;
Indicate that you are finished with "sth" and will not be fetching all the remaining rows.
my $hash = $results->hash;
Fetch next row from "sth" and return it as a hash reference. Note that "finish" needs to be called if you are not fetching all the possible rows.
# Process one row at a time while (my $next = $results->hash) { say $next->{money}; }
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);
my $id = $results->last_insert_id;
Returns the rowid <https://www.sqlite.org/c3ref/last_insert_rowid.html> of the most recent successful "INSERT".
my $num = $results->rows;
Number of rows. Note that for "SELECT" statements, this count will not be accurate until all rows have been fetched.
my $text = $results->text;
Fetch all rows from "sth" and turn them into a table with "tablify" in Mojo::Util.
Report any issues on the public bugtracker.
Dan Book, "dbook@cpan.org"
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.
Mojo::SQLite
2022-07-11 | perl v5.34.0 |