sequel-schema-sharding 0.8.0 → 0.9.0

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: a08abc2196b89b64cf69423f27b9b13b9383ddd1
4
- data.tar.gz: 2b0fa4a892a5999c43554d88a384bc7a5e52aa82
3
+ metadata.gz: 9643f5ed78031832422c6535ae8fc932ecc2f94a
4
+ data.tar.gz: 1239e9c62b491cd34f05a5968ce290e1a254e0b8
5
5
  SHA512:
6
- metadata.gz: 8a7429f701f5e2dd8f5ef8cb228696936c8f74ea61abf4e0735a0afacf2c8d177c2152b005f3bd1905c3030462a6cd6842f643bd7f08d759f8e7de101de1f381
7
- data.tar.gz: a675c35851fb577cca32a4dc772f64a0134c4f2529f6afa1f9c5e3930a7a100085d04bf4aedd53f8c0fe5ab99b9a9f6891c446806834a69bddef0bed564b2909
6
+ metadata.gz: 6fb807e5d933e40ff9eaf95cbb5b91ead02b886783a3dcadc8a92b44b63560a30686ccb8597ee51ed7028a29d9a394d6310a517b0ae857b1b186f8e3353c0889
7
+ data.tar.gz: 48451f4bc2e91416321ad45c41e48042972d8e2b10bb220bfee337afbdeded0425fe2405b2dc92b404ee60c30438f3e7507f463bf10950a8eebfd3e617aaa062
data/README.md CHANGED
@@ -188,6 +188,15 @@ return a dataset that is scoped to the current instance in the database,
188
188
  so that Sequel can update/delete/etc the record when you call methods on
189
189
  the instance that persist, ie `:destroy`, `:save`.
190
190
 
191
+ ## Read/write splitting
192
+
193
+ When using this in conjunction with multiple replicas, you should call `read_only_shard_for`
194
+ instead of `shard_for` when running a select query. This will ensure that anything that needs
195
+ a valid connection while the query is being built will go to a `:read_only` server.
196
+
197
+ This can be helpful when combined with server failover logic, to ensure that read
198
+ queries do not try to reconnect to a downed master.
199
+
191
200
  ## Running tests
192
201
 
193
202
  ```bash
@@ -56,6 +56,10 @@ module Sequel
56
56
  ds
57
57
  end
58
58
 
59
+ def read_only_shard_for(id)
60
+ shard_for(id).server(:read_only)
61
+ end
62
+
59
63
  # The result of a lookup for the given id. See Sequel::SchemaSharding::Finder::Result
60
64
  def result_for(id)
61
65
  Sequel::SchemaSharding::Finder.instance.lookup(self.implicit_table_name, id)
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module SchemaSharding
3
- VERSION = "0.8.0"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
@@ -47,4 +47,34 @@ describe Sequel::SchemaSharding, 'Model' do
47
47
  end
48
48
  end
49
49
 
50
+ describe '#shard_for' do
51
+ let(:dataset) { model.shard_for(2356) }
52
+
53
+ it 'returns a dataset' do
54
+ expect(dataset).to be_a(Sequel::Dataset)
55
+ end
56
+
57
+ it 'connects to the shard for the given id' do
58
+ expect(dataset.db.opts[:database]).to eq('sequel_test_shard2')
59
+ expect(dataset.first_source).to eq(:sequel_logical_artists_17__artists)
60
+ end
61
+ end
62
+
63
+ describe '#read_only_shard_for' do
64
+ let(:dataset) { model.read_only_shard_for(2356) }
65
+
66
+ it 'returns a dataset' do
67
+ expect(dataset).to be_a(Sequel::Dataset)
68
+ end
69
+
70
+ it 'connects to the shard for the given id' do
71
+ expect(dataset.db.opts[:database]).to eq('sequel_test_shard2')
72
+ expect(dataset.first_source).to eq(:sequel_logical_artists_17__artists)
73
+ end
74
+
75
+ it 'is read_only' do
76
+ expect(dataset.opts[:server]).to eq(:read_only)
77
+ end
78
+ end
79
+
50
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-schema-sharding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Henry