承接 silverstripe-australia/silverstripe-splitdb 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

silverstripe-australia/silverstripe-splitdb

最新稳定版本:1.0.0

Composer 安装命令:

composer require silverstripe-australia/silverstripe-splitdb

包简介

Provides functionality to configure separate read/write database connections

README 文档

README

This module contains an implementation of Read/Write splitting for database queries to allow for master/slave database implementations

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.

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.

Add configuration in your project along the lines of


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.

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


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

统计信息

  • 总下载量: 59
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-09-29