
Net::Async::PostgreSQL - support for the PostgreSQL wire protocol

version 0.007

# Simple queries are performed similar to DBI:
$dbh->do(q{insert into something (x,y,z) values (1,2,3)});
# These can also use bind variables:
$dbh->do(q{insert into something (x,y,z) values (?,?,?)}, undef, 1,2,3);
# Prepared statements work the same as DBI by default
my $sth = $dbh->prepare(q{select * from table where name = ?});
$sth->bind_param(1, 'test');
$sth->execute;
# ... but have async_ versions for passing handlers:
my $sth = $dbh->async_prepare(
sql => q{select * from table where name = ?},
on_error => sub { warn "failed" }
);
$sth->async_execute(
on_bind_request => sub {
return @param;
},
on_header => sub { ... },
on_row => sub { ... },
on_error => sub { ... },
on_complete => sub { ... },
);
# And there's a helper method for doing regular queries:
$dbh->run_query(
sql => q{select * from something where id = ?},
parameters => [1],
on_row => sub { warn "Had " . $_[1]->{} },
on_error => sub { warn "Error encountered" },
on_complete => sub { warn "all done" }
);

The interface is provided by Net::Async::DBI, which attempts to offer something close to DBI but with support for event-based request handling.
See Protocol::PostgreSQL for more details.

Apply callbacks and other parameters, preparing state for event loop start.
Prepare and activate a new transport.
Upgrade the underlying stream to use TLS.
Handle read requests by passing full packets back to the protocol handler.
Sends the Terminate message to the database server and closes the connection for a clean shutdown.


Tom Molesworth <cpan@entitymodel.com>

Copyright Tom Molesworth 2011. Licensed under the same terms as Perl itself.