ar-octopus 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.mkdn +2 -2
- data/ar-octopus.gemspec +1 -1
- data/lib/octopus/relation_proxy.rb +3 -0
- data/lib/octopus/scope_proxy.rb +1 -1
- data/lib/octopus/version.rb +1 -1
- data/spec/octopus/model_spec.rb +35 -9
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be74de9c9b6dfacee338dfa5d500da6ce758f501e3be7fa0f154afda07f31f40
|
4
|
+
data.tar.gz: 1892942a155383583a054e4d61cc588ebca2b33749ca191762d550bf9bf13022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0b21eb7e0fa5397b77c5df6c0bdce5fced41b7284ee7fc4869539ec6219bfcbe2f02a7e85239979b7534a298e2b7ad34e6833fdeb0fd81c67c536b17ea73ae9
|
7
|
+
data.tar.gz: 34bd15fbfb892fca1329f69abf85ba4421d563278d846a67014b710b473919d50cfc3425ed76de1580484a4f10554d4464a490e5ac49b3339553b810acdacfd5
|
data/README.mkdn
CHANGED
@@ -67,13 +67,13 @@ First, you need to create a config file, shards.yml, inside your config/ directo
|
|
67
67
|
Octopus adds a method to each AR Class and object: the using method is used to select the shard like this:
|
68
68
|
|
69
69
|
```ruby
|
70
|
-
User.where(:name => "Boba").limit(3).using(:
|
70
|
+
User.where(:name => "Boba").limit(3).using(:read_replica_one)
|
71
71
|
```
|
72
72
|
|
73
73
|
Octopus also supports queries within a block. When you pass a block to the using method, all queries inside the block will be sent to the specified shard.
|
74
74
|
|
75
75
|
```ruby
|
76
|
-
Octopus.using(:
|
76
|
+
Octopus.using(:read_replica_two) do
|
77
77
|
User.create(:name => "Thiago")
|
78
78
|
end
|
79
79
|
```
|
data/ar-octopus.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_development_dependency 'rake'
|
33
33
|
s.add_development_dependency 'rspec', '>= 3'
|
34
34
|
s.add_development_dependency 'rubocop'
|
35
|
-
s.add_development_dependency 'sqlite3', '
|
35
|
+
s.add_development_dependency 'sqlite3', '~> 1.3.6'
|
36
36
|
s.add_development_dependency 'pry-byebug'
|
37
37
|
|
38
38
|
s.license = 'MIT'
|
@@ -27,6 +27,7 @@ module Octopus
|
|
27
27
|
# `find { ... }` etc. should run_on_shard, `find(id)` should be sent to relation
|
28
28
|
ENUM_WITH_BLOCK_METHODS = [:find, :select, :none?, :any?, :one?, :many?, :sum]
|
29
29
|
BATCH_METHODS = [:find_each, :find_in_batches, :in_batches]
|
30
|
+
WHERE_CHAIN_METHODS = [:not]
|
30
31
|
|
31
32
|
def method_missing(method, *args, &block)
|
32
33
|
if !block && BATCH_METHODS.include?(method)
|
@@ -39,6 +40,8 @@ module Octopus
|
|
39
40
|
end
|
40
41
|
elsif ENUM_METHODS.include?(method) || block && ENUM_WITH_BLOCK_METHODS.include?(method)
|
41
42
|
run_on_shard { @ar_relation.to_a }.public_send(method, *args, &block)
|
43
|
+
elsif WHERE_CHAIN_METHODS.include?(method)
|
44
|
+
::Octopus::ScopeProxy.new(@current_shard, run_on_shard { @ar_relation.public_send(method, *args) } )
|
42
45
|
elsif block
|
43
46
|
@ar_relation.public_send(method, *args, &block)
|
44
47
|
else
|
data/lib/octopus/scope_proxy.rb
CHANGED
@@ -28,7 +28,7 @@ module Octopus
|
|
28
28
|
|
29
29
|
# Transaction Method send all queries to a specified shard.
|
30
30
|
def transaction(options = {}, &block)
|
31
|
-
run_on_shard {
|
31
|
+
run_on_shard { klass.transaction(options, &block) }
|
32
32
|
end
|
33
33
|
|
34
34
|
def connection
|
data/lib/octopus/version.rb
CHANGED
data/spec/octopus/model_spec.rb
CHANGED
@@ -500,19 +500,35 @@ describe Octopus::Model do
|
|
500
500
|
expect(user.as_json(:except => [:created_at, :updated_at, :id])).to eq('admin' => nil, 'name' => 'User1', 'number' => nil)
|
501
501
|
end
|
502
502
|
|
503
|
-
|
504
|
-
|
503
|
+
describe 'transaction' do
|
504
|
+
context 'without assigning a database' do
|
505
|
+
it 'works as expected' do
|
506
|
+
_u = User.create!(:name => 'Thiago')
|
505
507
|
|
506
|
-
|
507
|
-
|
508
|
+
expect(User.using(:brazil).count).to eq(0)
|
509
|
+
expect(User.using(:master).count).to eq(1)
|
510
|
+
|
511
|
+
User.using(:brazil).transaction do
|
512
|
+
expect(User.find_by_name('Thiago')).to be_nil
|
513
|
+
User.create!(:name => 'Brazil')
|
514
|
+
end
|
508
515
|
|
509
|
-
|
510
|
-
|
511
|
-
|
516
|
+
expect(User.using(:brazil).count).to eq(1)
|
517
|
+
expect(User.using(:master).count).to eq(1)
|
518
|
+
end
|
512
519
|
end
|
513
520
|
|
514
|
-
|
515
|
-
|
521
|
+
context 'when assigning a database' do
|
522
|
+
it 'works as expected' do
|
523
|
+
klass = User.using(:brazil)
|
524
|
+
|
525
|
+
klass.transaction do
|
526
|
+
klass.create!(:name => 'Brazil')
|
527
|
+
end
|
528
|
+
|
529
|
+
expect(klass.find_by_name('Brazil')).to be_present
|
530
|
+
end
|
531
|
+
end
|
516
532
|
end
|
517
533
|
|
518
534
|
describe "#finder methods" do
|
@@ -532,6 +548,16 @@ describe Octopus::Model do
|
|
532
548
|
expect(result_array).to eq([@user1, @user2, @user3])
|
533
549
|
end
|
534
550
|
|
551
|
+
it "#find_each should work with a where.not(...)" do
|
552
|
+
result_array = []
|
553
|
+
|
554
|
+
User.using(:brazil).where.not(:name => 'User2').find_each do |user|
|
555
|
+
result_array << user
|
556
|
+
end
|
557
|
+
|
558
|
+
expect(result_array).to eq([@user1, @user3])
|
559
|
+
end
|
560
|
+
|
535
561
|
it "#find_each should work as an enumerator" do
|
536
562
|
result_array = []
|
537
563
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-octopus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Pradi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-03-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -134,16 +134,16 @@ dependencies:
|
|
134
134
|
name: sqlite3
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
|
-
- - "
|
137
|
+
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 1.3.
|
139
|
+
version: 1.3.6
|
140
140
|
type: :development
|
141
141
|
prerelease: false
|
142
142
|
version_requirements: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- - "
|
144
|
+
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: 1.3.
|
146
|
+
version: 1.3.6
|
147
147
|
- !ruby/object:Gem::Dependency
|
148
148
|
name: pry-byebug
|
149
149
|
requirement: !ruby/object:Gem::Requirement
|
@@ -350,8 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
350
350
|
- !ruby/object:Gem::Version
|
351
351
|
version: '0'
|
352
352
|
requirements: []
|
353
|
-
|
354
|
-
rubygems_version: 2.4.5.1
|
353
|
+
rubygems_version: 3.0.1
|
355
354
|
signing_key:
|
356
355
|
specification_version: 4
|
357
356
|
summary: Easy Database Sharding for ActiveRecord
|