NAME
DBIx::MoCo::DataBase - Data Base Handler for DBIx::MoCo
SYNOPSIS
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'],
);
METHODS
- cache_connection
-
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);
- dsn
-
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'], );
SEE ALSO
AUTHOR
Junya Kondo, <jkondo@hatena.com>
COPYRIGHT AND LICENSE
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.