IO::Lambda::DBI(3)
πΈ NAME πΈ
okay bestie, welcome to IO::Lambda::DBI(3) β a User Contributed Perl Documentation page, manual name IO::Lambda::DBI β and it's literally asynchronous DBI. That's the whole name vibe: IO::Lambda::DBI - asynchronous DBI. π
β¨ DESCRIPTION β¨
The module implements asynchronous DBI proxy object, that remotes DBI calls using any given file handle, such as stream sockets, pipes, etc. All calls to DBI methods are implemented as method calls to the object, which return lambdas, that shall be subsequently called and awaited for completion. So like, you call a method, it hands you a lambda, and then you call and await that lambda until it's done. No cap. π¦
π¦ SYNOPSIS π¦
Here's the iconic starter pack, bestie β copy it exactly:
use IO::Lambda qw(:all);
use IO::Lambda::DBI;
use IO::Lambda::Thread qw(new_thread);
# use threads as a transport
my ($thread, $socket) = new_thread( sub {
IO::Lambda::Message::DBI-> new( shift )-> run;
}, 1);
my $dbi = IO::Lambda::DBI-> new($socket);
# execute a query
print lambda {
context $dbi-> connect('DBI:mysql:database=mysql', '', '');
tail {
return "connect error:$_[0]" unless shift;
context $dbi-> selectrow_array('SELECT 5 + ?', {}, 2);
tail {
my ($ok,$result) = @_;
return "dbi error:$result" unless $ok;
context $dbi-> disconnect;
tail {
return "select=$result";
}}}}-> wait, "\n";
# finalize
$thread-> join;
π IO::Lambda::DBI π
All remoted methods return lambdas of type
dbi_result :: () -> ( 1, @result | 0, $error )
where depending on the first returned item in the array, the other items are either DBI method results, or an error. iykyk π
The class handles AUTOLOAD methods as proxy methods, so calls such as $dbh-> selectrow_array are perfectly legal. main character energy β¨
new $class, $r, $w, %optionsβ See"new" in IO::Lambda::Message. π«Άconnect($dsn, $user, $auth, %attr) :: dbi_resultβ ProxiesDBI::connect. In case of failure, depending onRaiseErrorflag, returns either(0,$error)or(1,$error). πdisconnect :: dbi_resultβ ProxiesDBI::disconnect. πcall($method, @parameters) :: dbi_resultβ ProxiesDBI::$method(@parameters). π₯set_attr(%attr)β Sets attributes on a DBI handle. πΈget_attr(@keys)β Retrieves values for attribute keys from a DBI handle. πprepare($statement)β Returns a new prepared statement object or an error string. All method calls on this object return lambda that also wait until remote methods are executed. π§begin_group(), end_group()β These two methods allow grouping of DBI calls.begin_group()affects aIO::Lambda::DBIobject so that all calls to remoted methods are not stored in the queue (and, consequently, not executed one at a time), but are accumulated instead.end_group()ends such buffering, sends the message incapsulating all stored calls, and returns a lambda that executes when all stored calls are finished and replied to. The lambda returns results to all accumulated calls. π
Note: each stored call registers whether it is called in array or scalar context. The results are returned accordingly in a list, so the caller is responsible for parsing the results if some or all calls were made in the array context. don't skip this part, bestie π
Example:
context
$dbi-> begin_group,
$dbi-> selectrow_arrayref("select * from a"),
$dbi-> selectrow_arrayref("select * from b"),
$dbi-> end_group;
tail {
return warn "error:$_[0]" unless shift;
my ( $a, $b) = @_;
}
π§ IO::Lambda::Message::DBI π§
Descendant of IO::Lambda::Message::Simple. Implements blocking, server side that does the actual calls to the DBI. this is the backend bestie doing the real work π οΈ
π SEE ALSO π
DBI, eg/dbi.pl. Go peek, bestie. π
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>. iconic π
perl v5.42.2, dated 2026-02-15, from IO::Lambda::DBI(3) β mwah π
π¦ where this page comes from
- alpine 3.24: perl-io-lambda-doc 1.34-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms