NAME

AnyEvent::MySQL::ConnPool

DESCRIPTION

Adds additional method "pool_connect" to AnyEvent::MySQL package.

SYNOPSIS

Similar to AnyEvent::MySQL->connect();

use AnyEvent;
use AnyEvent::MySQL;
use AnyEvent::MySQL::ConnPool;

my $connpool = AnyEvent::MySQL->connect_pool(
    "DBI:mysql:database=test;host=127.0.0.1;port=3306",
    "ptest",
    "pass", {
        PrintError      =>  1,
        PoolSize        =>  10,
        CheckInterval   =>  5,
    }, 
    sub {
        my($dbh) = @_;
        if( $dbh ) {
            warn "Connect success!";
            $dbh->pre_do("set names latin1");
            $dbh->pre_do("set names utf8");
        }
        else {
            warn "Connect fail: $AnyEvent::MySQL::errstr ($AnyEvent::MySQL::err)";
            $end->send;
        }
    }
);

# if you need only connection methods, you can use dispatcher object as regular AnyEvent::MySQL connection  object.
# the difference is: dispatcher applies connection pool functional to your connection object.
my $dispatcher = $connpool->dispatcher();
$dispatcher->selectall_hashref('SELECT * FROM `table1`', {}, sub {
    ...;
});

METHODS

connect_pool

Returns connected AnyEvent::ConnPool object. All options for connect_pool are similar to the AnyEvent::MySQL->connect method. But pool accepts additional options in parameters hashref(4th parameter).

AnyEvent::MySQL->connect_pool($dsn, $user, $password, {PoolSize => 5, CheckInterval => 10, Dispatcher => 0}, $callback);

PoolSize => how many connections should be created. 5 connections by default.

CheckInterval => Interval for ping connections. 10 seconds by default.

Dispatcher => Determines return-value type. If true, connect_pool will return dispatcher object, instead of pool object. You can use dispatcher object as regular AnyEvent::MySQL connection object, pool will do it's own behind the scene.

new

Same thing as connect_pool.

my $connpool = AnyEvent::MySQL::ConnPool->new($dsn, $user, $password, {PoolSize => 5, CheckInterval => 10, Dispatcher => 0}, $callback);