README.md in ebisu_connection-1.0.0 vs README.md in ebisu_connection-2.0.0

- old
+ new

@@ -1,13 +1,63 @@ # EbisuConnection - [![Gem Version](https://badge.fury.io/rb/ebisu_connection.svg)](http://badge.fury.io/rb/ebisu_connection) [![Build Status](https://travis-ci.org/tsukasaoishi/ebisu_connection.svg?branch=master)](https://travis-ci.org/tsukasaoishi/ebisu_connection) [![Code Climate](https://codeclimate.com/github/tsukasaoishi/ebisu_connection/badges/gpa.svg)](https://codeclimate.com/github/tsukasaoishi/ebisu_connection) -EbisuConnection supports to connect with Mysql slave servers. It doesn't need Load Balancer. -You can assign a performance weight to each slave server. And slave config is reflected dynamic. -EbisuConnection uses FreshConnection (https://github.com/tsukasaoishi/fresh_connection). +EbisuConnection allows access to slave servers. +You could assign a performance weight to each slave server. +``` +Rails ------------ Master DB + | + | + +---- Slave1 DB (weight 10) + | + | + +---- Slave2 DB (weight 20) +``` + +If you could put a load balancer in front of slave servers, should use [FreshConnection](https://github.com/tsukasaoishi/fresh_connection). + +## Usage +### Access to Slave +Read query goes to the slave server. + +```ruby +Article.where(:id => 1) +``` + +### Access to Master +If read query want to access to the master server, use `read_master`. +In before version 0.3.1, can use `readonly(false)`. + +```ruby +Article.where(:id => 1).read_master +``` + +In transaction, All queries go to the master server. + +```ruby +Article.transaction do + Article.where(:id => 1) +end +``` + +Create, Update and Delete queries go to the master server. + +```ruby +article = Article.create(...) +article.title = "FreshConnection" +article.save +article.destory +``` + +## Support Rails version +EbisuConnection supports Rails version 4.0 or later. +If you are using Rails 3.2, could use EbisuConnection version 1.0.0 or before. + +## Support DB +EbisuConnection supports MySQL and PostgreSQL. + ## Installation Add this line to your application's Gemfile: ```ruby @@ -46,25 +96,25 @@ username: slave password: slave host: slave ``` -```slave``` is base config to connect to slave servers. -Others will use the master setting. If you want to change, write in the slave. +```slave``` is a config to connect to slave servers. +Others will use the master server settings. + +Config of each slave server fill out to `config/slave.yml` -Config of each slave server fill out config/slave.yaml - ```yaml production: - "slave1, 10" - "slave2, 20" - host: "slave3" weight: 30 ``` -config/slave.yaml is checked by end of action. If config changed, it's reflected dynamic. Application doesn't need restart. +If ``config/slave.yml`` changed, it is reflected dynamic. Application doesn't need restart. ```yaml "hostname, weight" ``` @@ -94,11 +144,11 @@ username: slave password: slave host: admin_slaves ``` -Config of each slave server fill out config/slave.yaml +Config of each slave server fill out to `config/slave.yml` ```yaml production: slave: - "slave1, 10" @@ -109,11 +159,10 @@ admin_slave: - "slave3, 10" - "slave4, 20" ``` - And call establish_fresh_connection method in model that access to ```admin_slave``` slave group. ```ruby class AdminUser < ActiveRecord::Base establish_fresh_connection :admin_slave @@ -146,36 +195,10 @@ ``` If model that always access to master servers is exist, You may want to write ```master_db_only!``` in model. The model that master_db_only model's child is always access to master db. -## Usage - -Read query will be access to slave server. - -```ruby -Article.where(:id => 1) -Article.count -``` - -If you want to access to the master server, use read_master. - -```ruby -Article.where(:id => 1).read_master -``` - -It is possible to use readonly(false) instead of read_master, but it will be depricated at future version. - -In transaction, Always will be access to master server. - -```ruby -Article.transaction do - Article.where(:id => 1) -end -``` - - ### for Unicorn ```ruby before_fork do |server, worker| ... @@ -203,15 +226,14 @@ I'm glad that you would do test! To run the test suite, you need mysql installed. How to setup your test environment. ```bash -bundle install --path .bundle -bundle exec appraisal install +./bin/setup ``` This command run the spec suite for all rails versions supported. ```base -bundle exec appraisal rake test +./bin/test ```