Class: OrderQuery::SQL::Where
- Inherits:
-
Object
- Object
- OrderQuery::SQL::Where
- Defined in:
- lib/order_query/sql/where.rb
Overview
Build 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) ⇒ 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.
9 10 11 12 |
# File 'lib/order_query/sql/where.rb', line 9 def initialize(point) @point = point @columns = point.space.columns end |
Instance Attribute Details
#point ⇒ Object (readonly)
Returns the value of attribute point.
6 7 8 |
# File 'lib/order_query/sql/where.rb', line 6 def point @point end |
Instance Method Details
#build(side) ⇒ query, parameters
Join column pairs with OR, and nest within each other with AND
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/order_query/sql/where.rb', line 22 def build(side) # generate pairs of terms such as sales < 5, sales = 5 terms = @columns.map { |col| [where_side(col, side, true), where_tie(col)].reject { |x| x == WHERE_IDENTITY } } # group pairwise with OR, and nest with AND query = foldr_terms terms.map { |pair| join_terms 'OR'.freeze, *pair }, 'AND'.freeze 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 |