sequel-seek-pagination 0.2.0 → 0.2.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e681598557874a5b7102fd630deef04e48dd08ec
|
4
|
+
data.tar.gz: 176755ad95e8e78978dac323661a9b9f55762a0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4581a836e385d1f061b984fbc14a94d7225d3010d67efb8b1e169f76ff80445044ec1d727bfe28c38761272e68629b1023cea8f683bf87be9c86d42c1bcca124
|
7
|
+
data.tar.gz: 7c191afc86655d078da0d2c49b2aab2b6bbb42f21af9558c3ada83a8053ad45f60e3c4e39a2eeb8f251f4e0b9c952b1aacc01fc66c701fb0e7afbcf2de91dc5a
|
@@ -26,16 +26,21 @@ module Sequel
|
|
26
26
|
raise Error, "passed the wrong number of values in the :#{from ? 'from' : 'after'} option to seek_paginate"
|
27
27
|
end
|
28
28
|
elsif pk = from_pk || after_pk
|
29
|
-
|
30
|
-
# need to fetch the actual expressions being ordered by.
|
31
|
-
expressions = order.map { |o| Sequel::SQL::OrderedExpression === o ? o.expression : o }
|
29
|
+
target_ds = where(model.qualified_primary_key_hash(pk))
|
32
30
|
|
31
|
+
# Need to load the values to order from for that pk from the DB, so we
|
32
|
+
# need to fetch the actual expressions being ordered by. Also,
|
33
33
|
# Dataset#get won't like it if we pass it expressions that aren't
|
34
|
-
# simple columns, so give it aliases for everything.
|
34
|
+
# simple columns, so we need to give it aliases for everything.
|
35
35
|
al = :a
|
36
|
-
gettable =
|
36
|
+
gettable = order.map do |o, i|
|
37
|
+
expression = Sequel::SQL::OrderedExpression === o ? o.expression : o
|
38
|
+
Sequel.as(expression, (al = al.next))
|
39
|
+
end
|
37
40
|
|
38
|
-
values =
|
41
|
+
unless values = target_ds.get(gettable)
|
42
|
+
raise NoMatchingRow.new(target_ds)
|
43
|
+
end
|
39
44
|
end
|
40
45
|
|
41
46
|
if values
|
@@ -211,5 +211,10 @@ class SeekPaginationSpec < Minitest::Spec
|
|
211
211
|
assert_equal %(SELECT * FROM "seek" WHERE (("not_nullable_1", "not_nullable_2", "id") > (1, 2, 3)) ORDER BY "not_nullable_1", "not_nullable_2", "id" LIMIT 5),
|
212
212
|
SeekModel.order(:not_nullable_1, :not_nullable_2, :id).seek_paginate(5, after: [1, 2, 3]).sql
|
213
213
|
end
|
214
|
+
|
215
|
+
it "should raise an error when passed a pk for a record that doesn't exist in the dataset" do
|
216
|
+
assert_raises(Sequel::NoMatchingRow) { SeekModel.order(:id).seek_paginate(5, after_pk: -45) }
|
217
|
+
assert_raises(Sequel::NoMatchingRow) { SeekModel.order(:id).seek_paginate(5, from_pk: -45) }
|
218
|
+
end
|
214
219
|
end
|
215
220
|
end
|