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
- #build_conditions ⇒ 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.
111 112 113 114 115 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 111 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.
109 110 111 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 109 def include_exact_match @include_exact_match end |
#not_null ⇒ Object (readonly)
Returns the value of attribute not_null.
109 110 111 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 109 def not_null @not_null end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
109 110 111 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 109 def orders @orders end |
Instance Method Details
#build_conditions ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/sequel/extensions/seek_pagination.rb', line 117 def build_conditions length = orders.length # 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].inequality_condition(allow_equal: allow_equal) else c = conditions[-2] list = if filter = conditions[-1].inequality_condition(allow_equal: allow_equal) [Sequel.&(c.eq_filter, filter)] else [c.eq_filter] end list += conditions[0..-2].map { |c| c.inequality_condition(allow_equal: false) } Sequel.|(*list.compact) end }.compact ) end end |