whi-cassie 1.0.0 → 1.0.1
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/HISTORY.txt +4 -0
- data/VERSION +1 -1
- data/lib/cassie/model.rb +10 -3
- data/spec/cassie/model_spec.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03ff68291018701bf3bbd15e8dd2d018f4ef1b65
|
4
|
+
data.tar.gz: 4924128158a74937bf8a307f4208417eec9e2ce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e76d10e1818452fbcea764a54cfdb67bdfa76ca95743264abb3e8e195fa180af7f8cbd7993042544522aa629ef4f7dff3318230f68a28e623d50b77a13ccc95f
|
7
|
+
data.tar.gz: faec19ce6868879cf5c9e8d85ddacfdb8f394d466d314b666735a5b65c3d863ae9eea5be3e91deb96b92d9458a04dd3c608870e611c7e4a95e37d33b52aecbda
|
data/HISTORY.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/cassie/model.rb
CHANGED
@@ -288,13 +288,16 @@ module Cassie::Model
|
|
288
288
|
#
|
289
289
|
# The order argument can be used to specify an order for the ordering key (:asc or :desc).
|
290
290
|
# It will default to the natural order of the last ordering key as defined by the ordering_key method.
|
291
|
-
|
291
|
+
#
|
292
|
+
# The min and max can be used to limit the offset calculation to a range of values (exclusive).
|
293
|
+
def offset_to_id(key, offset, order: nil, batch_size: 1000, min: nil, max: nil)
|
292
294
|
ordering_key = primary_key.last
|
293
295
|
cluster_order = _ordering_keys[ordering_key] || :asc
|
294
296
|
order ||= cluster_order
|
295
297
|
order_cql = "#{ordering_key} #{order}" unless order == cluster_order
|
296
298
|
|
297
|
-
from =
|
299
|
+
from = (order == :desc ? max : min)
|
300
|
+
to = (order == :desc ? min : max)
|
298
301
|
loop do
|
299
302
|
limit = (offset > batch_size ? batch_size : offset + 1)
|
300
303
|
conditions_cql = []
|
@@ -303,12 +306,16 @@ module Cassie::Model
|
|
303
306
|
conditions_cql << "#{ordering_key} #{order == :desc ? '<' : '>'} ?"
|
304
307
|
conditions << from
|
305
308
|
end
|
309
|
+
if to
|
310
|
+
conditions_cql << "#{ordering_key} #{order == :desc ? '>' : '<'} ?"
|
311
|
+
conditions << to
|
312
|
+
end
|
306
313
|
key.each do |name, value|
|
307
314
|
conditions_cql << "#{column_name(name)} = ?"
|
308
315
|
conditions << value
|
309
316
|
end
|
310
317
|
conditions.unshift(conditions_cql.join(" AND "))
|
311
|
-
|
318
|
+
|
312
319
|
results = find_all(:select => [ordering_key], :where => conditions, :limit => limit, :order => order_cql)
|
313
320
|
last_row = results.last if results.size == limit
|
314
321
|
last_id = last_row.send(ordering_key) if last_row
|
data/spec/cassie/model_spec.rb
CHANGED
@@ -97,7 +97,7 @@ describe Cassie::Model do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "won't find all records with a blank where clause" do
|
100
|
-
expect{ Cassie::Thing.find_all(where: {}) }.to raise_error
|
100
|
+
expect{ Cassie::Thing.find_all(where: {}) }.to raise_error(ArgumentError)
|
101
101
|
Cassie::Thing.find_all(where: :all).size.should == 3
|
102
102
|
end
|
103
103
|
end
|
@@ -116,6 +116,8 @@ describe Cassie::Model do
|
|
116
116
|
Cassie::Thing.offset_to_id({:owner => 1}, 3, batch_size: 1).should == 2
|
117
117
|
Cassie::Thing.offset_to_id({:owner => 1}, 4, batch_size: 1).should == nil
|
118
118
|
Cassie::Thing.offset_to_id({:owner => 1}, 4, batch_size: 100).should == nil
|
119
|
+
Cassie::Thing.offset_to_id({:owner => 1}, 1, batch_size: 1, min: 3).should == 4
|
120
|
+
Cassie::Thing.offset_to_id({:owner => 1}, 1, order: :desc, batch_size: 1, max: 5).should == 3
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whi-cassie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- We Heart It
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cassandra-driver
|