fresh_connection 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +19 -0
- data/README.md +59 -23
- data/lib/fresh_connection/extend/ar_relation.rb +2 -0
- data/lib/fresh_connection/version.rb +1 -1
- data/spec/prepare.rb +6 -0
- data/spec/unit/fresh_connection_spec.rb +4 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da070ea6bf04531b1dad24fd2a6b1f267cbe4455
|
4
|
+
data.tar.gz: 20eb3122e428d4ab78ef6987a11bdba2f885c7eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71365d6a0818a691c86f02e47221c3edce8ea9344542984a72c57f276f4415f8e958cf10971a6c63bbceaf3772605308bd6a37fbda497a4c0a6c9a19569a2966
|
7
|
+
data.tar.gz: 1c1a11a33929b6e0906c3b73ec131954617376c8d04fed23ed8673a0850979071e00afb6f9f203246f57a24f5eef7137f976bb789b63653c6f7dba6f3ecc1a1a
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_script:
|
3
|
+
- mysql -e 'create database fresh_connection_test;'
|
4
|
+
- mysql -e 'create database fresh_connection_test_master;'
|
5
|
+
- mysql -e 'create database fresh_connection_test_slave;'
|
6
|
+
- "bundle exec ruby spec/prepare.rb"
|
7
|
+
rvm:
|
8
|
+
- 1.9.3
|
9
|
+
- 2.0.0
|
10
|
+
- 2.1
|
11
|
+
- 2.2
|
12
|
+
- ruby-head
|
13
|
+
gemfile:
|
14
|
+
- gemfiles/rails3.gemfile
|
15
|
+
- gemfiles/rails40.gemfile
|
16
|
+
- gemfiles/rails41.gemfile
|
17
|
+
notifications:
|
18
|
+
emails:
|
19
|
+
- tsukasa.oishi@gmail.com
|
data/README.md
CHANGED
@@ -1,8 +1,60 @@
|
|
1
1
|
# FreshConnection
|
2
2
|
|
3
|
-
FreshConnection
|
4
|
-
|
5
|
-
|
3
|
+
FreshConnection allows access to Mysql slave servers in Rails.
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/fresh_connection) [](https://travis-ci.org/tsukasaoishi/fresh_connection) [](https://codeclimate.com/github/tsukasaoishi/fresh_connection)
|
6
|
+
|
7
|
+
ActiveRecord can only access a single server by default.
|
8
|
+
FreshConnection can access to replicated Mysql slave servers via a loadbalancer.
|
9
|
+
|
10
|
+
For example.
|
11
|
+
```
|
12
|
+
Rails ------------ Mysql(Master)
|
13
|
+
|
|
14
|
+
| +------ Mysql(Slave1)
|
15
|
+
| |
|
16
|
+
+---- Loadbalancer ---+
|
17
|
+
|
|
18
|
+
+------ Mysql(Slave2)
|
19
|
+
```
|
20
|
+
|
21
|
+
When Rails controller's action begins, FreshConnction connects with one of slave servers behind the loadbalacer.
|
22
|
+
Read query goes to the slave server via the loadbalancer.
|
23
|
+
Write query goes to the master server. Inside transaction, all queries go to the master server.
|
24
|
+
All Mysql connections is disconnected at the end of the Rails controller's action.
|
25
|
+
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Read query goes to the slave server.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Article.where(:id => 1)
|
33
|
+
```
|
34
|
+
|
35
|
+
If you want to access to the master saver, use readonly(false).
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Article.where(:id => 1).readonly(false)
|
39
|
+
```
|
40
|
+
|
41
|
+
In transaction, All queries go to the master server.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Article.transaction do
|
45
|
+
Article.where(:id => 1)
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Create, Update. Delete queries go to the master server.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
article = Article.create(...)
|
53
|
+
article.title = "FreshConnection"
|
54
|
+
article.save
|
55
|
+
article.destory
|
56
|
+
```
|
57
|
+
|
6
58
|
|
7
59
|
## Installation
|
8
60
|
|
@@ -92,11 +144,11 @@ AdminUser and Benefit access to ```admin_slave``` slave group.
|
|
92
144
|
master_db_only!
|
93
145
|
end
|
94
146
|
|
95
|
-
If a model that always access to the master server is exist, You write ```master_db_only!``` in the model.
|
147
|
+
If a model that always access to the master server is exist, You write ```master_db_only!``` in the model.
|
96
148
|
The model that master_db_only model's child is always access to master db.
|
97
149
|
|
98
150
|
### Slave Connection Manager
|
99
|
-
Default slave connection manager is FreshConnection::ConnectionManager.
|
151
|
+
Default slave connection manager is FreshConnection::ConnectionManager.
|
100
152
|
If you would like to change slave connection manager, assign yourself slave connection manager.
|
101
153
|
|
102
154
|
#### config/application.rb
|
@@ -126,22 +178,6 @@ Yourself Slave Connection Manager should be inherited FreshConnection::AbstractC
|
|
126
178
|
end
|
127
179
|
end
|
128
180
|
|
129
|
-
## Usage
|
130
|
-
Read query will be access to slave server.
|
131
|
-
|
132
|
-
Article.where(:id => 1)
|
133
|
-
|
134
|
-
If you want to access to master saver, use readonly(false).
|
135
|
-
|
136
|
-
Article.where(:id => 1).readonly(false)
|
137
|
-
|
138
|
-
In transaction, Always will be access to master server.
|
139
|
-
|
140
|
-
Article.transaction do
|
141
|
-
Article.where(:id => 1)
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
181
|
|
146
182
|
## Contributing
|
147
183
|
|
@@ -153,8 +189,8 @@ In transaction, Always will be access to master server.
|
|
153
189
|
|
154
190
|
## Test
|
155
191
|
|
156
|
-
I'm glad that you would do test!
|
157
|
-
To run the test suite, you need mysql installed.
|
192
|
+
I'm glad that you would do test!
|
193
|
+
To run the test suite, you need mysql installed.
|
158
194
|
How to setup your test environment.
|
159
195
|
|
160
196
|
First of all, you setting the config of the test mysql server in ```spec/database.yml```
|
data/spec/prepare.rb
CHANGED
@@ -42,6 +42,10 @@ describe FreshConnection do
|
|
42
42
|
it "pluck is access to slave1" do
|
43
43
|
expect(User.pluck(:name).first).to be_include("slave")
|
44
44
|
end
|
45
|
+
|
46
|
+
it "pluck returns empty array when result of condition is empty" do
|
47
|
+
expect(User.limit(0).pluck(:name)).to be_empty
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
context "access to master" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fresh_connection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsukasa OISHI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -128,6 +128,7 @@ extensions: []
|
|
128
128
|
extra_rdoc_files: []
|
129
129
|
files:
|
130
130
|
- ".gitignore"
|
131
|
+
- ".travis.yml"
|
131
132
|
- Appraisals
|
132
133
|
- Gemfile
|
133
134
|
- LICENSE.txt
|
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
182
|
version: '0'
|
182
183
|
requirements: []
|
183
184
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.4.1
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: FreshConnection supports to connect with Mysql slave servers via Load Balancers.
|