GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mojo::Pg::Results(3) User Contributed Perl Documentation Mojo::Pg::Results(3)

Mojo::Pg::Results - Results

  use Mojo::Pg::Results;

  my $results = Mojo::Pg::Results->new(sth => $sth);
  $results->hashes->map(sub { $_->{foo} })->shuffle->join("\n")->say;

Mojo::Pg::Results is a container for DBD::Pg statement handles used by Mojo::Pg::Database.

Mojo::Pg::Results implements the following attributes.

  my $db   = $results->db;
  $results = $results->db(Mojo::Pg::Database->new);

Mojo::Pg::Database object these results belong to.

  my $sth  = $results->sth;
  $results = $results->sth($sth);

DBD::Pg statement handle results are fetched from.

Mojo::Pg::Results inherits all methods from Mojo::Base and implements the following new ones.

  my $array = $results->array;

Fetch one row from "sth" and return it as an array reference.

  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;

Decode "json" and "jsonb" fields automatically to Perl values for all rows.

  # Expand JSON
  $results->expand->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 one row from "sth" and return it as a hash reference.

  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 $results = Mojo::Pg::Results->new;
  my $results = Mojo::Pg::Results->new(sth => $sth);
  my $results = Mojo::Pg::Results->new({sth => $sth});

Construct a new Mojo::Pg::Results object.

  my $num = $results->rows;

Number of rows.

  my $text = $results->text;

Fetch all rows from "sth" and turn them into a table with "tablify" in Mojo::Util.

Mojo::Pg, Mojolicious::Guides, <https://mojolicious.org>.
2022-03-10 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.