1Mojo::Pg::Results(3)  User Contributed Perl Documentation Mojo::Pg::Results(3)
2
3
4

NAME

6       Mojo::Pg::Results - Results
7

SYNOPSIS

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

DESCRIPTION

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

ATTRIBUTES

19       Mojo::Pg::Results implements the following attributes.
20
21   db
22         my $db   = $results->db;
23         $results = $results->db(Mojo::Pg::Database->new);
24
25       Mojo::Pg::Database object these results belong to.
26
27   sth
28         my $sth  = $results->sth;
29         $results = $results->sth($sth);
30
31       DBD::Pg statement handle results are fetched from.
32

METHODS

34       Mojo::Pg::Results inherits all methods from Mojo::Base and implements
35       the following new ones.
36
37   array
38         my $array = $results->array;
39
40       Fetch one row from "sth" and return it as an array reference.
41
42   arrays
43         my $collection = $results->arrays;
44
45       Fetch all rows from "sth" and return them as a Mojo::Collection object
46       containing array references.
47
48         # Process all rows at once
49         say $results->arrays->reduce(sub { $a + $b->[3] }, 0);
50
51   columns
52         my $columns = $results->columns;
53
54       Return column names as an array reference.
55
56         # Names of all columns
57         say for @{$results->columns};
58
59   expand
60         $results = $results->expand;
61
62       Decode "json" and "jsonb" fields automatically to Perl values for all
63       rows.
64
65         # Expand JSON
66         $results->expand->hashes->map(sub { $_->{foo}{bar} })->join("\n")->say;
67
68   finish
69         $results->finish;
70
71       Indicate that you are finished with "sth" and will not be fetching all
72       the remaining rows.
73
74   hash
75         my $hash = $results->hash;
76
77       Fetch one row from "sth" and return it as a hash reference.
78
79   hashes
80         my $collection = $results->hashes;
81
82       Fetch all rows from "sth" and return them as a Mojo::Collection object
83       containing hash references.
84
85         # Process all rows at once
86         say $results->hashes->reduce(sub { $a + $b->{money} }, 0);
87
88   new
89         my $results = Mojo::Pg::Results->new;
90         my $results = Mojo::Pg::Results->new(sth => $sth);
91         my $results = Mojo::Pg::Results->new({sth => $sth});
92
93       Construct a new Mojo::Pg::Results object.
94
95   rows
96         my $num = $results->rows;
97
98       Number of rows.
99
100   text
101         my $text = $results->text;
102
103       Fetch all rows from "sth" and turn them into a table with "tablify" in
104       Mojo::Util.
105

SEE ALSO

107       Mojo::Pg, Mojolicious::Guides, <https://mojolicious.org>.
108
109
110
111perl v5.34.0                      2022-01-21              Mojo::Pg::Results(3)
Impressum