DBIO-PostgreSQL-Async

 view release on metacpan or  search on metacpan

lib/DBIO/PostgreSQL/Async/Storage.pm  view on Meta::CPAN


sub txn_do {
  my $self = shift;
  return $self->txn_do_async(@_)->get;
}

# --- Schema Integration ---

sub schema { $_[0]->{schema} }
sub debug  { $_[0]->{debug} }

sub connected { defined $_[0]->{pool} && $_[0]->pool->available > 0 }

sub disconnect {
  my $self = shift;
  if ($self->{pool}) {
    $self->{pool}->shutdown;
    $self->{pool} = undef;
  }
  if ($self->{_listen_pg}) {
    $self->{_listen_pg}->finish;
    $self->{_listen_pg} = undef;
  }
}

sub DESTROY {
  my $self = shift;
  $self->disconnect if $self->{pool};
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

DBIO::PostgreSQL::Async::Storage - Async PostgreSQL storage driver using EV::Pg

=head1 VERSION

version 0.900000

=head1 DESCRIPTION

Implements L<DBIO::Storage::Async> using L<EV::Pg> — a non-blocking
PostgreSQL client that speaks libpq's async protocol directly.
No DBI, no DBD::Pg, just raw libpq performance.

Features:

=over 4

=item * Pipeline mode — batch queries in a single network round-trip

=item * Prepared statement caching

=item * LISTEN/NOTIFY for real-time event streaming

=item * COPY IN/OUT for bulk data transfer

=item * Connection pooling with transaction pinning

=back

=head1 METHODS

=head2 future_class

Returns C<'Future'> — uses L<Future.pm|Future> from CPAN.

=head2 connect_info

  $storage->connect_info([ \%conninfo, \%opts ]);

Set connection parameters. C<%conninfo> is passed directly to
L<EV::Pg> as libpq connection parameters (host, dbname, user, etc.).

=head2 pool

Returns the L<DBIO::PostgreSQL::Async::Pool> connection pool.
Created lazily on first access.

=head2 sql_maker

Returns the L<DBIO::PostgreSQL::SQLMaker> instance, configured for PostgreSQL
(double-quote quoting, LIMIT/OFFSET dialect).

=head2 select_async

  my $future = $storage->select_async($source, $select, $where, $attrs);

Execute a SELECT query asynchronously. Returns a L<Future> that
resolves with the result rows (arrayrefs).

=head2 select_single_async

Like L</select_async> but returns only the first row.

=head2 insert_async

  my $future = $storage->insert_async($source, \%vals);

=head2 update_async

  my $future = $storage->update_async($source, \%vals, \%where);

=head2 delete_async

  my $future = $storage->delete_async($source, \%where);

=head2 txn_do_async

  my $future = $storage->txn_do_async(sub {
      my ($storage) = @_;
      # All queries in here use the same connection
      $storage->insert_async(...)->then(sub { ... });
  });



( run in 0.867 second using v1.01-cache-2.11-cpan-995e09ba956 )