The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

version 0.007

SYNOPSIS

 # 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" }
 );

DESCRIPTION

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.

METHODS

configure

Apply callbacks and other parameters, preparing state for event loop start.

on_connection_established

Prepare and activate a new transport.

on_starttls

Upgrade the underlying stream to use TLS.

connect

on_read

Handle read requests by passing full packets back to the protocol handler.

do

terminate

Sends the Terminate message to the database server and closes the connection for a clean shutdown.

SEE ALSO

  • DBI - the real database interface

  • DBD::Gofer - proxy request support for DBI

AUTHOR

Tom Molesworth <cpan@entitymodel.com>

LICENSE

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