EV-MariaDB
view release on metacpan or search on metacpan
# EV::MariaDB
Async MariaDB/MySQL client for Perl using libmariadb and the EV event loop.
## Features
- Fully asynchronous connect, query, prepared statements
- Query pipelining via `mysql_send_query`/`mysql_read_query_result` (up to 64 in-flight)
- Prepared statements with automatic buffer sizing via max_length detection
- Row streaming via `query_stream` for large result sets
- Transactions: `commit`, `rollback`, `autocommit`
- Connection utilities: ping, reset, change_user, select_db, reset_connection, set_charset
- Graceful async close via `close_async`
- Manual parameter binding with `bind_params` and `send_long_data` for BLOBs
- Column metadata (field names) returned as optional third callback argument
- Multi-result set support
## Synopsis
```perl
use EV;
use EV::MariaDB;
my $m = EV::MariaDB->new(
host => 'localhost',
user => 'root',
password => '',
database => 'test',
on_connect => sub { print "connected\n" },
on_error => sub { warn "error: $_[0]\n" },
);
# simple query
$m->query("select * from users", sub {
my ($rows, $err, $fields) = @_;
if ($err) { warn $err; return }
for my $row (@$rows) {
print join(", ", @$row), "\n";
}
});
# prepared statement
$m->prepare("select * from users where id = ?", sub {
my ($stmt, $err) = @_;
die $err if $err;
$m->execute($stmt, [42], sub {
my ($rows, $err, $fields) = @_;
# ...
$m->close_stmt($stmt, sub { });
});
});
# pipelined queries (all sent before reading results)
for my $id (1..100) {
$m->q("select * from t where id = $id", sub {
my ($rows, $err) = @_;
# callbacks fire in order
});
}
EV::run;
```
## Install
Requires EV and Alien::MariaDB (which finds or builds libmariadb).
```
cpanm EV Alien::MariaDB
perl Makefile.PL && make && make test
( run in 1.044 second using v1.01-cache-2.11-cpan-39bf76dae61 )