pg: Add a few result fetching methods

I'm not sure if these are free from memory leaks, need to find a way to
test for that.
This commit is contained in:
Yorhel 2025-02-06 11:36:08 +01:00
parent 711300b227
commit 9d5905e3b4
5 changed files with 223 additions and 21 deletions

View file

@ -108,7 +108,8 @@ used.
=back
Statement objects returned by C<< $conn->q() >> support the following methods:
Statement objects returned by C<< $conn->q() >> can be inspected with the
following two methods:
=over
@ -137,6 +138,40 @@ returns.
# { name => 'title', oid => 25 },
# ]
=back
The statement can be executed with one of the following methods, depending on
how you'd like to obtain the results:
=over
=item B<< $st->exec >>
Execute the query and return the number of rows affected. Similar to C<<
$conn->exec >>.
=item B<< $st->val >>
Return the first column of the first row. Throws an error if the query does not
return exactly one column, or if multiple rows are returned. Returns I<undef>
if no rows are returned or if its value is I<NULL>.
=item B<< $st->rowl >>
Return the first row as a list. Throws an error if the query does not return
exactly one row.
=item B<< $st->rowa >>
Return the first row as an arrayref, equivalent to C<< [$st->rowl] >> but
probably slightly more efficient.
=item B<< $st->rowh >>
Return the first row as a hashref. Also throws an error if the query returns
multiple columns with the same name.
=back
=head2 Transactions
@ -194,4 +229,9 @@ A thin wrapper around libpq. Lacks many higher-level conveniences and does not
support binary transfers (at the time of writing, but then again there's little
benefit in dealing with the binary format in pure perl anyway).
=item L<DBIx::Simple>
A popular DBI wrapper with some API conveniences. I may have taken some
inspiration from it in the design of this module's API.
=back