use DBD::Pg ':async';
use Mojo::IOLoop;
my $dbh = DBI->connect(
'dbi:Pg:dbname=postgres;host=127.0.0.1;port=5432',
'postgres',
'',
{
AutoCommit => 1,
AutoInactiveDestroy => 1,
PrintError => 0,
PrintWarn => 0,
RaiseError => 1
}
);
my $sth = $dbh->prepare('select 1', {pg_async => PG_ASYNC});
$sth->execute;
open my $handle, '{pg_socket} or die "Can't dup: $!";
Mojo::IOLoop->singleton->reactor->io(
$handle => sub {
return unless $dbh->pg_ready;
my $result = $sth->pg_result;
my $data = $sth->fetchall_arrayref;
...
Mojo::IOLoop->stop;
}
);
Mojo::IOLoop->start;