Class: Sequel::SeekPagination::OrderedColumnSet
- Inherits:
-
Object
- Object
- Sequel::SeekPagination::OrderedColumnSet
- Defined in:
- lib/sequel/extensions/seek_pagination.rb
Instance Attribute Summary collapse
-
#include_exact_match ⇒ Object
readonly
Returns the value of attribute include_exact_match.
-
#not_null ⇒ Object
readonly
Returns the value of attribute not_null.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
Instance Method Summary collapse
- #apply(dataset) ⇒ Object
-
#initialize(order_values, include_exact_match:, not_null:) ⇒ OrderedColumnSet
constructor
A new instance of OrderedColumnSet.
Constructor Details
#initialize(order_values, include_exact_match:, not_null:) ⇒ OrderedColumnSet
Returns a new instance of OrderedColumnSet.
67 68 69 70 71 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 67 def initialize(order_values, include_exact_match:, not_null:) @not_null = not_null @include_exact_match = include_exact_match @orders = order_values.map { |order, value| OrderedColumn.new(self, order, value) } end |
Instance Attribute Details
#include_exact_match ⇒ Object (readonly)
Returns the value of attribute include_exact_match.
65 66 67 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 65 def include_exact_match @include_exact_match end |
#not_null ⇒ Object (readonly)
Returns the value of attribute not_null.
65 66 67 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 65 def not_null @not_null end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
65 66 67 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 65 def orders @orders end |
Instance Method Details
#apply(dataset) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 73 def apply(dataset) length = orders.length conditions = # Handle the common case where we can do a simpler (and faster) # WHERE (non_nullable_1, non_nullable_2) > (1, 2) clause. if length > 1 && orders.all?(&:not_null) && has_uniform_order_direction? Sequel.virtual_row do |o| o.__send__( orders.first.inequality_method(include_exact_match), orders.map(&:name), orders.map(&:value) ) end else Sequel.&( *length.times.map { |i| allow_equal = include_exact_match || i != length - 1 conditions = orders[0..i] if i.zero? conditions[0].ineq(eq: allow_equal) else c = conditions[-2] list = if filter = conditions[-1].ineq(eq: allow_equal) [Sequel.&(c.eq_filter, filter)] else [c.eq_filter] end list += conditions[0..-2].map { |c| c.ineq(eq: false) } Sequel.|(*list.compact) end }.compact ) end dataset.where(conditions) end |