sequel-schema-sharding 0.8.0 → 0.9.0
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/README.md +9 -0
- data/lib/sequel/schema-sharding/model.rb +4 -0
- data/lib/sequel/schema-sharding/version.rb +1 -1
- data/spec/schema-sharding/model_spec.rb +30 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9643f5ed78031832422c6535ae8fc932ecc2f94a
|
4
|
+
data.tar.gz: 1239e9c62b491cd34f05a5968ce290e1a254e0b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
@@ -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
|