Class: OrderQuery::SQL::Where
- Inherits:
-
Object
- Object
- OrderQuery::SQL::Where
- Defined in:
- lib/order_query/sql/where.rb
Overview
Builds where clause for searching around a record in an order space.
Instance Attribute Summary collapse
-
#point ⇒ Object
readonly
Returns the value of attribute point.
Instance Method Summary collapse
-
#build(side, strict = true) ⇒ query, parameters
Join column pairs with OR, and nest within each other with AND.
-
#initialize(point) ⇒ Where
constructor
A new instance of Where.
Constructor Details
#initialize(point) ⇒ Where
Returns a new instance of Where.
10 11 12 13 |
# File 'lib/order_query/sql/where.rb', line 10 def initialize(point) @point = point @columns = point.space.columns end |
Instance Attribute Details
#point ⇒ Object (readonly)
Returns the value of attribute point.
7 8 9 |
# File 'lib/order_query/sql/where.rb', line 7 def point @point end |
Instance Method Details
#build(side, strict = true) ⇒ query, parameters
Join column pairs with OR, and nest within each other with AND
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/order_query/sql/where.rb', line 25 def build(side, strict = true) # generate pairs of terms such as sales < 5, sales = 5 terms = @columns.map.with_index do |col, i| be_strict = i != @columns.size - 1 ? true : strict [where_side(col, side, be_strict), where_tie(col)].reject do |x| x == WHERE_IDENTITY end end # group pairwise with OR, and nest with AND query = foldr_terms terms.map { |pair| join_terms 'OR', *pair }, 'AND' if ::OrderQuery.wrap_top_level_or # wrap in a redundant AND clause for performance query = wrap_top_level_or query, terms, side end query end |