NAME
DBIx::Class::Async::Storage::DBI - DBI-based async storage backend for DBIx::Class::Async
VERSION
Version 0.40
SYNOPSIS
use DBIx::Class::Async::Schema;
my $schema = DBIx::Class::Async::Schema->connect(
"dbi:SQLite:dbname=mydb.db",
undef,
undef,
{ sqlite_unicode => 1 },
{ workers => 4, schema_class => 'MyApp::Schema' }
);
my $storage = $schema->storage;
# $storage is a DBIx::Class::Async::Storage::DBI instance
# Create a cursor for async iteration
my $rs = $schema->resultset('User');
my $cursor = $storage->cursor($rs);
DESCRIPTION
This class provides a DBI-based storage backend for DBIx::Class::Async::Schema. It extends DBIx::Class::Async::Storage and implements DBI-specific functionality for managing database connections and operations in an asynchronous worker pool environment.
Unlike traditional DBIx::Class::Storage::DBI, this storage class does not maintain database handles in the parent process. Instead, database handles are managed by worker processes, allowing for non-blocking asynchronous database operations using Future objects.
This class is automatically instantiated when you connect to a database using "connect" in DBIx::Class::Async::Schema and generally does not need to be instantiated directly.
METHODS
dbh
my $dbh = $storage->dbh;
Returns undef in async storage mode.
Unlike traditional DBIx::Class::Storage::DBI, the async storage layer does not maintain a database handle in the parent process. Instead, database handles are held by worker processes in the background worker pool, which execute queries asynchronously.
This method exists for API compatibility with standard DBIx::Class storage objects, but always returns undef to indicate that direct database handle access is not available in async mode.
my $storage = $schema->storage;
my $dbh = $storage->dbh; # Always undef in async mode
if (!defined $dbh) {
say "Running in async mode - no direct DBH access";
}
If you need to perform database operations, use the ResultSet and Row methods which handle async execution transparently through the worker pool.
cursor
my $cursor = $storage->cursor($resultset);
Creates and returns a DBIx::Class::Async::Storage::DBI::Cursor object for asynchronously iterating through a ResultSet's rows.
The cursor provides a low-level interface for fetching rows one at a time using Futures, which is useful for processing large result sets without loading all rows into memory at once.
Arguments
$resultset- A DBIx::Class::Async::ResultSet object
Returns
A DBIx::Class::Async::Storage::DBI::Cursor object configured for the given ResultSet.
use Future::AsyncAwait;
my $rs = $schema->resultset('User');
my $cursor = $storage->cursor($rs);
my $iter = async sub {
while (my $row = await $cursor->next) {
say $row->name;
}
};
$iter->get;
The cursor respects the ResultSet's rows attribute for batch fetching:
my $rs = $schema->resultset('User')->search(undef, { rows => 50 });
my $cursor = $storage->cursor($rs); # Fetches 50 rows at a time
See DBIx::Class::Async::Storage::DBI::Cursor for available cursor methods.
debug
# Get current debug level
my $level = $storage->debug;
# Set debug level
$storage->debug(1);
Gets or sets the debug level for the storage layer.
When called without arguments, returns the current debug level (defaults to 0). When called with an argument, sets the debug level to the specified value and returns it.
Arguments
$level(optional) - Integer debug level (0 = off, higher values = more verbose)
Returns
The current or newly set debug level.
# Enable debugging
$storage->debug(1);
# Check if debugging is enabled
if ($storage->debug) {
say "Debug mode is on at level " . $storage->debug;
}
# Disable debugging
$storage->debug(0);
Note: The actual debug output behavior may vary depending on the storage implementation and connected database driver.
ARCHITECTURE
This storage class operates differently from traditional DBIx::Class::Storage::DBI:
No Parent Process DBH
The parent process does not hold database handles. All database connections are managed by worker processes.
Async Operations
All database operations return Future objects, enabling non-blocking asynchronous execution.
Worker Pool
Database queries are distributed across a pool of worker processes, allowing for parallel execution and improved throughput.
Transparent API
Despite the async architecture, the API remains similar to standard DBIx::Class, making migration easier.
SEE ALSO
DBIx::Class::Async::Storage - Base async storage class
DBIx::Class::Async::Storage::DBI::Cursor - Async cursor implementation
DBIx::Class::Async::Schema - Async schema class
DBIx::Class::Async::ResultSet - Async ResultSet class
DBIx::Class::Storage::DBI - Traditional synchronous DBI storage
Future - Asynchronous result objects
IO::Async - Asynchronous event-driven programming
AUTHOR
Mohammad Sajid Anwar, <mohammad.anwar at yahoo.com>
REPOSITORY
https://github.com/manwar/DBIx-Class-Async
BUGS
Please report any bugs or feature requests through the web interface at https://github.com/manwar/DBIx-Class-Async/issues. I will be notified and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc DBIx::Class::Async::Storage::DBI
You can also look for information at:
BUG Report
CPAN Ratings
Search MetaCPAN
LICENSE AND COPYRIGHT
Copyright (C) 2026 Mohammad Sajid Anwar.
This program is free software; you can redistribute it and / or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License.By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you,you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement,then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.