17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sequel/extensions/keyset_pagination.rb', line 17
def self.cursor_conditions(columns, cursor, reverse: false)
zipped = columns.zip(cursor)
desc = reverse ? :> : :<
asc = reverse ? :< : :>
segments = zipped.each_with_index.reverse_each.reduce([]) do |acc, ((column, cursor_value), idx)|
segment = [Sequel[column.expression].send(column.descending ? desc : asc, cursor_value)]
zipped.slice(0, idx).each do |(col, cur)|
segment << Sequel[col.expression].send(:=~, cur)
end
acc << Sequel.&(*segment)
end
Sequel.|(*segments)
end
|