The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

AnyEvent::Pg::Pool::Multiserver - Asyncronious multiserver requests to Postgresql with AnyEvent::Pg

SYNOPSIS

use AnyEvent;
use AnyEvent::Pg::Pool::Multiserver;

my $servers = [
  {
    id   => 1,
    name => 'remote 1',
    conn => 'host=remote1 port=5432 dbname=mydb user=myuser password=mypass',
  },
  {
    id   => 2,
    name => 'remote 2',
    conn => 'host=remote2 port=5432 dbname=mydb user=myuser password=mypass',
  },
];
my $pool = AnyEvent::Pg::Pool::Multiserver->new( servers => $servers );

my $cv = AE::cv;

# query and args same as in AnyEvent::Pg
$pool->selectall_arrayref(
  query  => 'SELECT val FROM ( SELECT 1 AS val ) tmp WHERE tmp.val = $1;',
  args   => [1],
  cb     => sub {
    my $result = shift;
    my $err    = shift;

    if ( $err ) {
      foreach my $srv ( @$err ) {
        say "err with $srv->{name} $srv->{id}";
      }
    }

    if ( $result ) {
      foreach my $val ( @$result ) {
        say "server_id=$val->{_server_id} value=$val->{val}";
      }
    }

    $cv->send;
  },
);

$cv->recv;

DESCRIPTION

$pool->selectall_arrayref

query and args are the same, that in AnyEvent::Pg

SOURCE AVAILABILITY

The source code for this module is available from Github at Github

AUTHOR

Andrey Kuzmin, <kak-tus@mail.ru>

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Andrey Kuzmin

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.