fresh_connection 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e470a4665ec85ef6b012e95e365c5038d996aa6
4
- data.tar.gz: a764c721578fbdc080d2351333dbd34716be123a
3
+ metadata.gz: da070ea6bf04531b1dad24fd2a6b1f267cbe4455
4
+ data.tar.gz: 20eb3122e428d4ab78ef6987a11bdba2f885c7eb
5
5
  SHA512:
6
- metadata.gz: 98a9036418869064befea2b8d7f9e539a30bc11a74ab3b3039057f9a00224339855612de0586bdd7cb1aeef451c09fa65ecb51c6378182a6b43151d3788aed9f
7
- data.tar.gz: 4456c9b0d2798facd1b8b3c83a55f7d61b52c8708ce899266ac4307b1034290474639dde84909099be02c42d253fce5bbfcf07f2182115f5d51aa13e4ddb67a3
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 supports to connect with Mysql slave servers via Load Balancers.
4
- All connections will be disconnected every time at the end of the Rails controller's action.
5
- FreshConnection does not support Rails 2.x.
3
+ FreshConnection allows access to Mysql slave servers in Rails.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/fresh_connection.svg)](http://badge.fury.io/rb/fresh_connection) [![Build Status](https://travis-ci.org/tsukasaoishi/fresh_connection.svg?branch=master)](https://travis-ci.org/tsukasaoishi/fresh_connection) [![Code Climate](https://codeclimate.com/github/tsukasaoishi/fresh_connection/badges/gpa.svg)](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```
@@ -48,6 +48,8 @@ module FreshConnection
48
48
  klass.connection.select_all(select(column_name).arel, nil)
49
49
  end
50
50
 
51
+ return result if result.nil? || result.empty?
52
+
51
53
  last_columns = result.last.keys.last
52
54
 
53
55
  result.map do |attributes|
@@ -1,4 +1,4 @@
1
1
  module FreshConnection
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
4
4
 
data/spec/prepare.rb CHANGED
@@ -1,4 +1,10 @@
1
1
  require 'yaml'
2
+ require 'active_record'
3
+ require 'fresh_connection'
4
+
5
+ unless ActiveRecord::Base.respond_to?('establish_fresh_connection')
6
+ FreshConnection::Initializer.extend_active_record
7
+ end
2
8
 
3
9
  system("mysql -uroot < spec/db_schema.sql")
4
10
 
@@ -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.5
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-08-29 00:00:00.000000000 Z
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.2.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.