DBIx::Class::Storage::DBI::Replication(3p)

NAME
DBIx::Class::Storage::DBI::Replication - EXPERIMENTAL Replicated database support

SYNOPSIS
  # change storage_type in your schema class
    $schema->storage_type( '::DBI::Replication' );
    $schema->connect_info( [
                     [ "dbi:mysql:database=test;hostname=master", "username", "password", { AutoCommit => 1 } ], # master
                     [ "dbi:mysql:database=test;hostname=slave1", "username", "password", { priority => 10 } ],  # slave1
                     [ "dbi:mysql:database=test;hostname=slave2", "username", "password", { priority => 10 } ],  # slave2
                     <...>,
                     { limit_dialect => 'LimitXY' } # If needed, see below
                    ] );

DESCRIPTION
Warning: This class is marked EXPERIMENTAL. It works for the authors but does not currently have automated tests so your mileage may vary.

This class implements replicated data store for DBI. Currently you can define one master and numerous slave database connections. All write-type queries (INSERT, UPDATE, DELETE and even LAST_INSERT_ID) are routed to master database, all read-type queries (SELECTs) go to the slave database.

For every slave database you can define a priority value, which controls data source usage pattern. It uses DBD::Multi, so first the lower priority data sources used (if they have the same priority, the are used randomized), than if all low priority data sources fail, higher ones tried in order.

CONFIGURATION

  Limit dialect
If you use LIMIT in your queries (effectively, if you use SQL::Abstract::Limit), do not forget to set up limit_dialect (perldoc SQL::Abstract::Limit) by passing it as an option in the (optional) hash reference to connect_info. DBIC can not set it up automatically, since it can not guess DBD::Multi connection types.

SEE ALSO
DBI::Class::Storage::DBI, DBD::Multi, DBI

AUTHOR
Norbert Csongradi <bert@cpan.org>

Peter Siklosi <einon@einon.hu>

LICENSE
You may distribute this code under the same terms as Perl itself.