Method: OrderQuery::SQL::Where#build

Defined in:
lib/order_query/sql/where.rb

#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