NAME
Mojo::Pg::Results - Results
SYNOPSIS
my $results = Mojo::Pg::Results->new( sth => $sth );
$results ->hashes-> map ( sub { $_ ->{foo} })->shuffle-> join ( "\n" )-> say ;
|
DESCRIPTION
Mojo::Pg::Results is a container for DBD::Pg statement handles used by Mojo::Pg::Database.
ATTRIBUTES
Mojo::Pg::Results implements the following attributes.
sth
my $sth = $results ->sth;
$results = $results ->sth( $sth );
|
DBD::Pg statement handle results are fetched from.
METHODS
Mojo::Pg::Results inherits all methods from Mojo::Base and implements the following new ones.
array
my $array = $results ->array;
|
Fetch next row from "sth" and return it as an array reference.
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.
say $results ->arrays->reduce( sub { $a ->[3] + $b ->[3] });
|
columns
my $columns = $results ->columns;
|
Return column names as an array reference.
expand
$results = $results ->expand;
|
Decode json
and jsonb
fields automatically for all rows.
$results ->expand->hashes-> map ( sub { $_ ->{foo}{bar} })-> join ( "\n" )-> say ;
|
hash
my $hash = $results ->hash;
|
Fetch next row from "sth" and return it as a hash reference.
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.
say $results ->hashes->reduce( sub { $a ->{money} + $b ->{money} });
|
rows
my $num = $results ->rows;
|
Number of rows.
text
my $text = $results ->text;
|
Fetch all rows from "sth" and turn them into a table with "tablify" in Mojo::Util.
SEE ALSO
Mojo::Pg, Mojolicious::Guides, http://mojolicio.us.