NAME

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

VERSION

version 0.900000

DESCRIPTION

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

Features:

  • Pipeline mode — batch queries in a single network round-trip

  • Prepared statement caching

  • LISTEN/NOTIFY for real-time event streaming

  • COPY IN/OUT for bulk data transfer

  • Connection pooling with transaction pinning

METHODS

future_class

Returns 'Future' — uses Future.pm from CPAN.

connect_info

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

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

pool

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

sql_maker

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

select_async

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

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

select_single_async

Like "select_async" but returns only the first row.

insert_async

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

update_async

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

delete_async

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

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 { ... });
});

Acquires a connection from the pool, issues BEGIN, executes the coderef, and issues COMMIT on success or ROLLBACK on Future failure.

pipeline

my $future = $storage->pipeline(sub {
    my ($storage) = @_;
    my @futures;
    push @futures, $storage->insert_async('artist', { name => $_ })
        for @names;
    return Future->needs_all(@futures);
});

Execute multiple queries in pipeline mode. All queries are batched and sent in a single network round-trip for maximum throughput.

listen

$storage->listen($channel, sub {
    my ($channel, $payload, $sender_pid) = @_;
    # Handle notification
});

Subscribe to PostgreSQL LISTEN/NOTIFY notifications on the given channel. The callback fires each time a notification arrives.

unlisten

$storage->unlisten($channel);

Unsubscribe from a notification channel.

notify

$storage->notify($channel, $payload?);

Send a PostgreSQL NOTIFY to the given channel with an optional payload. Returns a Future that resolves when the NOTIFY has been dispatched.

Unlike "listen", this does not require a dedicated connection — it uses a pooled connection from the normal pool.

copy_in

$storage->copy_in($table, \@columns, sub {
    my ($put) = @_;
    $put->(['Miles Davis', 'Jazz']);
    $put->(['John Coltrane', 'Jazz']);
});

Bulk load data via PostgreSQL COPY FROM STDIN. The callback receives a writer function that accepts arrayrefs of column values.

AUTHOR

DBIO Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors

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