1Mojo::SQLite::Results(3U)ser Contributed Perl DocumentatiMoonjo::SQLite::Results(3)
2
3
4

NAME

6       Mojo::SQLite::Results - Results
7

SYNOPSIS

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

DESCRIPTION

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

ATTRIBUTES

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

METHODS

34       Mojo::SQLite::Results inherits all methods from Mojo::Base and
35       implements the following new ones.
36
37   new
38         my $results = Mojo::SQLite::Results->new;
39         my $results = Mojo::SQLite::Results->new(sth => $sth);
40         my $results = Mojo::SQLite::Results->new({sth => $sth});
41
42       Construct a new Mojo::SQLite::Results object.
43
44   array
45         my $array = $results->array;
46
47       Fetch next row from "sth" and return it as an array reference. Note
48       that "finish" needs to be called if you are not fetching all the
49       possible rows.
50
51         # Process one row at a time
52         while (my $next = $results->array) {
53           say $next->[3];
54         }
55
56   arrays
57         my $collection = $results->arrays;
58
59       Fetch all rows from "sth" and return them as a Mojo::Collection object
60       containing array references.
61
62         # Process all rows at once
63         say $results->arrays->reduce(sub { $a + $b->[3] }, 0);
64
65   columns
66         my $columns = $results->columns;
67
68       Return column names as an array reference.
69
70         # Names of all columns
71         say for @{$results->columns};
72
73   expand
74         $results = $results->expand(json => 'some_json');
75         $results = $results->expand(json => ['some_json','other_json']);
76
77       Decode specified fields from a particular format to Perl values for all
78       rows.  Currently only the "json" text format is recognized. The names
79       must exactly match the column names as returned by "columns"; it is
80       recommended to use explicit aliases in the query for consistent column
81       names.
82
83         # Expand JSON
84         $results->expand(json => 'json_field')->hashes->map(sub { $_->{foo}{bar} })->join("\n")->say;
85
86   finish
87         $results->finish;
88
89       Indicate that you are finished with "sth" and will not be fetching all
90       the remaining rows.
91
92   hash
93         my $hash = $results->hash;
94
95       Fetch next row from "sth" and return it as a hash reference. Note that
96       "finish" needs to be called if you are not fetching all the possible
97       rows.
98
99         # Process one row at a time
100         while (my $next = $results->hash) {
101           say $next->{money};
102         }
103
104   hashes
105         my $collection = $results->hashes;
106
107       Fetch all rows from "sth" and return them as a Mojo::Collection object
108       containing hash references.
109
110         # Process all rows at once
111         say $results->hashes->reduce(sub { $a + $b->{money} }, 0);
112
113   last_insert_id
114         my $id = $results->last_insert_id;
115
116       Returns the rowid <https://www.sqlite.org/c3ref/last_insert_rowid.html>
117       of the most recent successful "INSERT".
118
119   rows
120         my $num = $results->rows;
121
122       Number of rows. Note that for "SELECT" statements, this count will not
123       be accurate until all rows have been fetched.
124
125   text
126         my $text = $results->text;
127
128       Fetch all rows from "sth" and turn them into a table with "tablify" in
129       Mojo::Util.
130

BUGS

132       Report any issues on the public bugtracker.
133

AUTHOR

135       Dan Book, "dbook@cpan.org"
136
138       Copyright 2015, Dan Book.
139
140       This library is free software; you may redistribute it and/or modify it
141       under the terms of the Artistic License version 2.0.
142

SEE ALSO

144       Mojo::SQLite
145
146
147
148perl v5.32.1                      2021-01-27          Mojo::SQLite::Results(3)
Impressum