2017 © Pedro Peláez
 

silverstripe-module silverstripe-splitdb

Provides functionality to configure separate read/write database connections

image

silverstripe-australia/silverstripe-splitdb

Provides functionality to configure separate read/write database connections

  • Thursday, January 7, 2016
  • by nyeholt
  • Repository
  • 2 Watchers
  • 4 Stars
  • 50 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 2 Versions
  • 9 % Grown

The README.md

SilverStripe Split Database module

This module contains an implementation of Read/Write splitting for database queries to allow for master/slave database implementations, (*1)

Basic Usage

For using aspects, which is effectively database agnostic, read the 'ReadWriteSplitterAspect' section. For using a custom database class against MySQL, read the 'ReadWriteMySQLDatabase' section., (*2)

ReadWriteSplitterAspect

Use this aspect to direct READ queries to a particular database, and WRITE queries (ie queries that modify) to a specific master server (that is replicating to those slaves). It is assumed replication is managed externally to SilverStripe., (*3)

Add configuration in your project along the lines of, (*4)


Injector: WriteMySQLDatabase: class: MySQLDatabase constructor: - type: MySQLDatabase server: write.master.database.hostname username: user password: pass database: project_database ProxiedMySQLDatabase: class: MySQLDatabase constructor: - type: MySQLDatabase server: readonly.slavecluster.hostname username: user password: pass database: project_database MySQLWriteDbQueryAspect: class: \SilverStripe\Aspects\Database\ReadWriteSplitterAspect properties: writeDb: %$WriteMySQLDatabase MySQLDatabase: class: AopProxyService properties: proxied: %$ProxiedMySQLDatabase beforeCall: query: - %$MySQLWriteDbQueryAspect manipulate: - %$MySQLWriteDbQueryAspect getGeneratedID: - %$MySQLWriteDbQueryAspect affectedRows: - %$MySQLWriteDbQueryAspect

ReadWriteMySQLDatabase

Similar to the previous ReadWrite aspect, the ReadWriteMySQLDatabase relies on setting up a separate write database connection for directing queries to. So the initial database configuration is the same as usual, however instead of using MySQLDatabase, use ReadWriteMySQLDatabase (or ReadWriteSQLiteDatabase). This configuration must point to the readonly database., (*5)

Then, via YAML config, create configuration for the write specific database (note that the configured Injector object MUST be called SplitterWriteDatabase), (*6)


Injector: SplitterWriteDatabase: class: MySQLDatabase constructor: - type: MySQLDatabase server: write.master.database.hostname username: user password: pass database: project_database

Maintainer Contacts

Requirements

  • SilverStripe 3.1.?

License

This module is licensed under the BSD license at http://silverstripe.org/BSD-license, (*7)

The Versions

07/01 2016

dev-master

9999999-dev

Provides functionality to configure separate read/write database connections

  Sources   Download

BSD-3-Clause

The Requires

 

database silverstripe

29/09 2015

1.0.0

1.0.0.0

Provides functionality to configure separate read/write database connections

  Sources   Download

BSD-3-Clause

The Requires

 

database silverstripe