Module: Sequel::KeysetPagination::Utils

Defined in:
lib/sequel/extensions/keyset_pagination.rb

Class Method Summary collapse

Class Method Details

.cursor_conditions(columns, cursor, reverse: false) ⇒ Object



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 ? :< : :>

  # Reduce the dimensions
  segments = zipped.each_with_index.reverse_each.reduce([]) do |acc, ((column, cursor_value), idx)|
    # We always start of with the leaf
    segment = [Sequel[column.expression].send(column.descending ? desc : asc, cursor_value)]

    # Scope the leaf to its higher level dimensions
    zipped.slice(0, idx).each do |(col, cur)|
      segment << Sequel[col.expression].send(:=~, cur)
    end

    acc << Sequel.&(*segment)
  end
  Sequel.|(*segments)
end

.qualify_order(expression) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/sequel/extensions/keyset_pagination.rb', line 8

def self.qualify_order(expression)
  case expression
  when Sequel::SQL::OrderedExpression
    expression
  else
    Sequel::SQL::OrderedExpression.new(expression, false)
  end
end