NAME

DBIO::PostgreSQL::EV - Async PostgreSQL storage for DBIO via EV::Pg

VERSION

version 0.900001

SYNOPSIS

package MyApp::Schema;
use base 'DBIO::Schema';
__PACKAGE__->load_components(qw(PostgreSQL PostgreSQL::EV));

package MyApp::Schema::Result::Artist;
use base 'DBIO::Core';
__PACKAGE__->load_components('PostgreSQL');
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw( id name ));

# Async is opt-in per connection
my $schema  = MyApp::Schema->connect(
    'dbi:Pg:dbname=myapp', $user, $pass,
    { async => 'ev' },
);
my $storage = $schema->storage;        # DBIO::PostgreSQL::Storage

# Sync still works exactly as before
my @all = $schema->resultset('Artist')->all;

# Storage-level async runs real non-blocking over EV::Pg
$storage->select_async($source, $select, $where, $attrs)->then(sub {
    my @rows = @_;
    ...
});

# Pipeline mode, LISTEN/NOTIFY and COPY are async-only — not routed
# through the sync storage. Reach them on the embedded async backend
# via $storage->async (see DBIO::PostgreSQL::EV::Storage):
$storage->async->listen('changelog', sub { my ($chan, $payload) = @_; ... });
$storage->async->copy_in('artist', [qw( id name )], sub { my $put = shift; ... });

DESCRIPTION

Real async PostgreSQL for DBIO via EV::Pg, a non-blocking client built on libpq's async protocol. The async work itself lives in DBIO::PostgreSQL::EV::Storage.

This module is an inert marker component. Loading it via load_components('PostgreSQL::EV') does not by itself switch the storage to async: it only tags the schema so the DBIO::PostgreSQL::Storage MRO arm can resolve the ev mode. Async is an explicit, per-connection choice (ADR 0030); you opt in at connect time with { async => 'ev' }:

my $schema = MyApp::Schema->connect(
    $dsn, $user, $pass,
    { async => 'ev' },
);

The ev mode resolves to DBIO::PostgreSQL::EV::Storage (this distribution) and is registered by DBIO::PostgreSQL::Storage (the sync driver, in the DBIO::PostgreSQL distribution). With { async = 'ev' }> on a schema that has loaded this component, $rs->all still runs sync over DBI/DBD::Pg, while the storage-level *_async methods run real async over EV::Pg against the same connection info.

Without the opt-in, the *_async methods degrade to the universal forked fallback (DBIO::Forked::Storage, core ADR 0029); no compile-time dependency on EV is added to the sync driver.

EVENT LOOP COMPATIBILITY

EV::Pg uses the EV event loop. This works with:

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.