Skip to content

Instantly share code, notes, and snippets.

Created March 24, 2015 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6ec9822376016aed9486 to your computer and use it in GitHub Desktop.
Save anonymous/6ec9822376016aed9486 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use Mojo::Pg;
use Mojo::IOLoop;
my $pg = Mojo::Pg->new('postgresql://tester:testing@/test')->max_connections(1)->max_statements(1);
$pg->db->query(q{create table if not exists qwe (num integer, text text)});
$pg->db->query(q{truncate qwe});
Mojo::IOLoop->delay(
sub {
my $delay = shift;
my $db = $pg->db;
warn $db->dbh;
$db->query(q{insert into qwe(num, text) values (?, ?)}, 1, '1' => $delay->begin(0));
},
sub {
my ($delay, $db, $err, $results) = @_;
warn $db->dbh;
$db->ping;
$db->query(q{insert into qwe(num, text) values (?, ?)}, 1, '1' => $delay->begin);
say $db->dbh->pg_ready ? 'READY' : 'NOT READY' for 1 .. 100;
},
sub { Mojo::IOLoop->stop }
);
Mojo::IOLoop->start;
$pg->db->query('drop table qwe');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment