The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

IO::Lambda::DBI - asynchronous DBI

DESCRIPTION

The module implements asynchronous DBI proxy object, that can remote DBI calls using any given stream - sockets, pipes, etc. All calls to DBI methods are implemented as method calls to the object, that return lambdas, which shall be waited for

SYNOPSIS

        use IO::Lambda qw(:all);
        use IO::Lambda::DBI;
        use IO::Lambda::Thread qw(threaded);

    # use threads as a transport
    my $t = threaded {
        my $socket = shift;
        IO::Lambda::Message::DBI-> new( $socket, $socket )-> run;
    };
    $t-> start;
    $t-> join_on_read(0);
    my $dbi = IO::Lambda::DBI-> new( $t-> socket, $t-> 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
    $t-> 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 result, or an error.

The class handles AUTOLOAD methods as proxy methods, so calls like $dbh-> selectrow_array are perfectly legal.

new $class, $r, $w, %options

See "new" in IO::Lambda::Message.

connect($dsn, $user, $auth, %attr) :: dbi_result

Proxies DBI::connect. In case of failure, depending on RaiseError flag, returns either 0 | $error or 1 | $error.

disconnect :: dbi_result

Proxies DBI::disconnect.

call($method, @parameters) :: dbi_result

Proxies DBI::$method(@parameters).

set_attr(%attr)

Sets attributes on a DBI handle.

get_attr(@keys)

Retrieves values for attribute keys from a DBI handle.

IO::Lambda::Message::DBI

Descendant of IO::Lambda::Message::Simple. Implements blocking, server side that does the actual calls to the DBI.

BUGS

DBI::prepare is unimplemented.

SEE ALSO

DBI, eg/dbi.pl.

AUTHOR

Dmitry Karasik, <dmitry@karasik.eu.org>.