Add FU::SQL
Somewhat experimental, need to test this approach on a real site. Looking pretty promising so far, though.
This commit is contained in:
parent
48d3fb86a5
commit
145d086bea
5 changed files with 504 additions and 0 deletions
18
FU/Pg.pm
18
FU/Pg.pm
|
|
@ -6,8 +6,17 @@ _load_libpq();
|
|||
|
||||
package FU::Pg::conn {
|
||||
sub lib_version { FU::Pg::lib_version() }
|
||||
|
||||
sub Q {
|
||||
require FU::SQL;
|
||||
my $s = shift;
|
||||
my($sql, $params) = FU::SQL::SQL(@_)->compile(placeholder_style => 'pg', in_style => 'pg');
|
||||
$s->q($sql, @$params);
|
||||
}
|
||||
};
|
||||
|
||||
*FU::Pg::txn::Q = \*FU::Pg::conn::Q;
|
||||
|
||||
package FU::Pg::error {
|
||||
use overload '""' => sub($e, @) { $e->{full_message} };
|
||||
}
|
||||
|
|
@ -21,6 +30,8 @@ FU::Pg - The Ultimate (synchronous) Interface to PostgreSQL
|
|||
|
||||
=head1 SYNOPSYS
|
||||
|
||||
use FU::Pg;
|
||||
|
||||
my $conn = FU::Pg->connect("dbname=test user=test password=nottest");
|
||||
|
||||
$conn->exec('CREATE TABLE books (id SERIAL, title text, read bool)');
|
||||
|
|
@ -147,6 +158,11 @@ Note that this method just creates a statement object, the given query is not
|
|||
prepared or executed until the appropriate statement methods (see below) are
|
||||
used.
|
||||
|
||||
=item $conn->Q(@args)
|
||||
|
||||
Same as C<< $conn->q() >> but uses L<FU::SQL> to construct the SQL query and
|
||||
bind parameters.
|
||||
|
||||
=back
|
||||
|
||||
Statement objects returned by C<< $conn->q() >> support the following
|
||||
|
|
@ -359,6 +375,8 @@ Transaction methods:
|
|||
|
||||
=item $txn->q(..)
|
||||
|
||||
=item $txn->Q(..)
|
||||
|
||||
Run a query inside the transaction. These work the same as the respective
|
||||
methods on the parent C<$conn> object.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue