| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Async::PostgreSQL; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: PostgreSQL database support for IO::Async | 
| 3 | 1 |  |  | 1 |  | 913 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 79 |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '0.007'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Net::Async::PostgreSQL - (preliminary) asynchronous PostgreSQL support for L | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | version 0.007 | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | use strict; use warnings; | 
| 18 |  |  |  |  |  |  | use IO::Async::Loop; | 
| 19 |  |  |  |  |  |  | use Net::Async::PostgreSQL::Client; | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | my $loop = IO::Async::Loop->new; | 
| 22 |  |  |  |  |  |  | my $client = Net::Async::PostgreSQL::Client->new( | 
| 23 |  |  |  |  |  |  | host			=> $ENV{NET_ASYNC_POSTGRESQL_SERVER} || 'localhost', | 
| 24 |  |  |  |  |  |  | service			=> $ENV{NET_ASYNC_POSTGRESQL_PORT} || 5432, | 
| 25 |  |  |  |  |  |  | database		=> $ENV{NET_ASYNC_POSTGRESQL_DATABASE}, | 
| 26 |  |  |  |  |  |  | user			=> $ENV{NET_ASYNC_POSTGRESQL_USER}, | 
| 27 |  |  |  |  |  |  | pass			=> $ENV{NET_ASYNC_POSTGRESQL_PASS}, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  | $client->init; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | $client->configure( | 
| 32 |  |  |  |  |  |  | on_error	=> sub { | 
| 33 |  |  |  |  |  |  | my ($self, %args) = @_; | 
| 34 |  |  |  |  |  |  | my $err = $args{error}; | 
| 35 |  |  |  |  |  |  | warn "$_ => " . $err->{$_} . "\n" for sort keys %$err; | 
| 36 |  |  |  |  |  |  | }, | 
| 37 |  |  |  |  |  |  | on_ready_for_query => sub { | 
| 38 |  |  |  |  |  |  | my $self = shift; | 
| 39 |  |  |  |  |  |  | unless($init) { | 
| 40 |  |  |  |  |  |  | print "Server version " . $status{server_version} . "\n"; | 
| 41 |  |  |  |  |  |  | ++$init; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  | unless(keys %sth) { | 
| 44 |  |  |  |  |  |  | $self->simple_query(q{begin work}); | 
| 45 |  |  |  |  |  |  | my $sth = $self->prepare_async( | 
| 46 |  |  |  |  |  |  | sql => q{insert into sometable(name) values ($1) returning idsometable, name}, | 
| 47 |  |  |  |  |  |  | statement => 'new_value', | 
| 48 |  |  |  |  |  |  | ); | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | $sth->bind("some more data"); | 
| 51 |  |  |  |  |  |  | }, | 
| 52 |  |  |  |  |  |  | on_parameter_status => sub { | 
| 53 |  |  |  |  |  |  | my $self = shift; | 
| 54 |  |  |  |  |  |  | my %args = @_; | 
| 55 |  |  |  |  |  |  | $status{$_} = $args{status}->{$_} for sort keys %{$args{status}}; | 
| 56 |  |  |  |  |  |  | }, | 
| 57 |  |  |  |  |  |  | on_row_description => sub { | 
| 58 |  |  |  |  |  |  | my $self = shift; | 
| 59 |  |  |  |  |  |  | my %args = @_; | 
| 60 |  |  |  |  |  |  | print '[' . join(' ', map { $_->{name} } @{$args{description}{field}}) . "]\n"; | 
| 61 |  |  |  |  |  |  | }, | 
| 62 |  |  |  |  |  |  | on_data_row => sub { | 
| 63 |  |  |  |  |  |  | my $self = shift; | 
| 64 |  |  |  |  |  |  | my %args = @_; | 
| 65 |  |  |  |  |  |  | print '[' . join(',', map { $_->{data} } @{$args{row}}) . "]\n"; | 
| 66 |  |  |  |  |  |  | $loop->loop_stop; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | ); | 
| 69 |  |  |  |  |  |  | $loop->add($client); | 
| 70 |  |  |  |  |  |  | $client->connect; | 
| 71 |  |  |  |  |  |  | $loop->loop_forever; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | See L or L. | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =cut | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 1; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | __END__ |