Net::Async::PostgreSQL - (preliminary) asynchronous PostgreSQL support for IO::Async
version 0.007
use strict; use warnings; use IO::Async::Loop; use Net::Async::PostgreSQL::Client; my $loop = IO::Async::Loop->new; my $client = Net::Async::PostgreSQL::Client->new( host => $ENV{NET_ASYNC_POSTGRESQL_SERVER} || 'localhost', service => $ENV{NET_ASYNC_POSTGRESQL_PORT} || 5432, database => $ENV{NET_ASYNC_POSTGRESQL_DATABASE}, user => $ENV{NET_ASYNC_POSTGRESQL_USER}, pass => $ENV{NET_ASYNC_POSTGRESQL_PASS}, ); $client->init; $client->configure( on_error => sub { my ($self, %args) = @_; my $err = $args{error}; warn "$_ => " . $err->{$_} . "\n" for sort keys %$err; }, on_ready_for_query => sub { my $self = shift; unless($init) { print "Server version " . $status{server_version} . "\n"; ++$init; } unless(keys %sth) { $self->simple_query(q{begin work}); my $sth = $self->prepare_async( sql => q{insert into sometable(name) values ($1) returning idsometable, name}, statement => 'new_value', ); } $sth->bind("some more data"); }, on_parameter_status => sub { my $self = shift; my %args = @_; $status{$_} = $args{status}->{$_} for sort keys %{$args{status}}; }, on_row_description => sub { my $self = shift; my %args = @_; print '[' . join(' ', map { $_->{name} } @{$args{description}{field}}) . "]\n"; }, on_data_row => sub { my $self = shift; my %args = @_; print '[' . join(',', map { $_->{data} } @{$args{row}}) . "]\n"; $loop->loop_stop; } ); $loop->add($client); $client->connect; $loop->loop_forever;
See Net::Async::PostgreSQL::Client or Protocol::PostgreSQL.
Tom Molesworth <cpan@entitymodel.com>
Copyright Tom Molesworth 2011. Licensed under the same terms as Perl itself.
To install Net::Async::PostgreSQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::PostgreSQL
CPAN shell
perl -MCPAN -e shell install Net::Async::PostgreSQL
For more information on module installation, please visit the detailed CPAN module installation guide.