
DBIx::MoCo::DataBase - Data Base Handler for DBIx::MoCo

package MyDataBase;
use base qw(DBIx::MoCo::DataBase);
__PACKAGE__->dsn('dbi:mysql:myapp');
__PACKAGE__->username('test');
__PACKAGE__->password('test');
1;
# In your scripts
MyDataBase->execute('select 1');
# Configure your replication databases
__PACKAGE__->dsn(
master => 'dbi:mysql:dbname=test;host=db1',
slave => ['dbi:mysql:dbname=test;host=db2','dbi:mysql:dbname=test;host=db3'],
);

Controlls cache behavior for dbh connection. (default 1) If its set to 0, DBIx::MoCo::DataBase uses DBI->connect instead of DBI->connect_cached.
DBIx::MoCo::DataBase->cache_connection(0);
Configures dsn(s). You can specify single dsn as string, multiple dsns as an array, master/slave dsns as hash.
If you specify multiple dsns, they will be rotated automatically in round-robin. MoCo will use slave dsns when the sql begins with SELECT if you set up slave(s).
MyDataBase->dsn('dbi:mysql:dbname=test');
MyDataBase->dsn(['dbi:mysql:dbname=test;host=db1','dbi:mysql:dbname=test;host=db2']);
MyDataBase->dsn(
master => ['dbi:mysql:dbname=test;host=db1','dbi:mysql:dbname=test;host=db2'],
);
MyDataBase->dsn(
master => 'dbi:mysql:dbname=test;host=db1',
slave => ['dbi:mysql:dbname=test;host=db2','dbi:mysql:dbname=test;host=db3'],
);


Junya Kondo, <jkondo@hatena.com>

Copyright (C) Hatena Inc. All Rights Reserved.
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.