1NAME
2 AnyEvent::DBD::Pg - AnyEvent interface to DBD::Pg's async interface
3
4SYNOPSIS
5 use AnyEvent::DBD::Pg;
6
7 my $adb = AnyEvent::DBD::Pg->new('dbi:Pg:dbname=test', user => 'pass', {
8 pg_enable_utf8 => 1,
9 pg_server_prepare => 0,
10 quote_char => '"',
11 name_sep => ".",
12 }, debug => 1);
13
14 $adb->queue_size( 4 );
15 $adb->debug( 1 );
16
17 $adb->connect;
18
19 $adb->selectcol_arrayref("select pg_sleep( 0.1 ), 1", { Columns => [ 1 ] }, sub {
20 my $rc = shift or return warn;
21 my $res = shift;
22 warn "Got <$adb->{qd}> = $rc / @{$res}";
23 $adb->selectrow_hashref("select data,* from tx limit 2", {}, sub {
24 my $rc = shift or return warn;
25 warn "Got $adb->{qd} = $rc [@_]";
26 });
27 });
28
29 $adb->execute("update tx set data = data;",sub {
30 my $rc = shift or return warn;
31 warn "Got exec: $rc";
32 #my $st = shift;
33 #$st->finish;
34 });
35
36 $adb->execute("select from 1",sub {
37 shift or return warn;
38 warn "Got $adb->{qd} = @_";
39 });
40
41 $adb->selectrow_array("select pg_sleep( 0.1 ), 2", {}, sub {
42 shift or return warn;
43 warn "Got $adb->{qd} = [@_]";
44 $adb->selectrow_hashref("select * from tx limit 1", {}, sub {
45 warn "Got $adb->{qd} = [@_]";
46 $adb->execute("select * from tx", sub {
47 my $rc = shift or return warn;
48 my $st = shift;
49 while(my $row = $st->fetchrow_hashref) { warn "$row->{id}"; }
50 $st->finish;
51 exit;
52 });
53 });
54 });
55 AE::cv->recv;
56
57METHODS
58 connect()
59 Establish connection to database
60
61 selectrow_array( $query, [\%args], $cb->( $rc, ... ))
62 Execute PG_ASYNC prepare, than push result of "fetchrow_array" into
63 callback
64
65 selectrow_arrayref( $query, [\%args], $cb->( $rc, \@row ))
66 Execute PG_ASYNC prepare, than push result of "fetchrow_arrayref"
67 into callback
68
69 selectrow_hashref( $query, [\%args], $cb->( $rc, \%row ))
70 Execute PG_ASYNC prepare, than push result of "fetchrow_hashref"
71 into callback
72
73 selectall_arrayref( $query, [\%args], $cb->( $rc, \@rows ))
74 Execute PG_ASYNC prepare, than push result of "fetchall_arrayref"
75 into callback
76
77 selectall_hashref( $query, [\%args], $cb->( $rc, \@rows ))
78 Execute PG_ASYNC prepare, than push result of "fetchall_hashref"
79 into callback
80
81 selectcol_arrayref( $query, { Columns => [...], ... }, $cb->( $rc,
82 \@rows ))
83 Execute PG_ASYNC prepare, than push result of
84 "fetchall_hashref($args{Columns})" into callback
85
86 execute( $query, [\%args], $cb->( $rc, $sth ))
87 Execute PG_ASYNC prepare, than invoke callback, pushing resulting
88 sth to it.
89
90 Please, note: result already passed as first argument
91
92AUTHOR
93 Mons Anderson, "<mons@cpan.org>"
94
95LICENSE AND COPYRIGHT
96 Copyright 2010 Mons Anderson.
97
98 This program is free software; you can redistribute it and/or modify it
99 under the terms of either: the GNU General Public License as published
100 by the Free Software Foundation; or the Artistic License.
101
102