module ActiveHouse::Querying::Where

Public Instance Methods

build_where_query_part() click to toggle source
# File lib/active_house/querying/where.rb, line 16
def build_where_query_part
  "WHERE\n" + values[:where].join(" AND\n") unless values[:where].empty?
end
format_where_clauses(conditions) click to toggle source
# File lib/active_house/querying/where.rb, line 41
def format_where_clauses(conditions)
  raise ArgumentError, 'wrong number of arguments' if conditions.empty?

  return [ActiveHouse::PreparedStatement.prepare_sql(*conditions)] if conditions.size > 1

  ActiveHouse::PreparedStatement.build_condition(conditions.first)
end
initial_values() click to toggle source
Calls superclass method
# File lib/active_house/querying/where.rb, line 12
def initial_values
  super.merge where: []
end
where(*conditions) click to toggle source
# File lib/active_house/querying/where.rb, line 33
def where(*conditions)
  dup.where!(*conditions)
end
where!(*conditions) click to toggle source
# File lib/active_house/querying/where.rb, line 20
def where!(*conditions)
  formatted_conditions = format_where_clauses(conditions)
  values[:where] = (values[:where] + formatted_conditions).uniq
  self
end
where_not(*conditions) click to toggle source
# File lib/active_house/querying/where.rb, line 37
def where_not(*conditions)
  dup.where_not!(*conditions)
end
where_not!(*conditions) click to toggle source
# File lib/active_house/querying/where.rb, line 26
def where_not!(*conditions)
  formatted_conditions = format_where_clauses(conditions)
  negative_condition = "NOT (#{formatted_conditions.join(' AND ')})"
  values[:where] = (values[:where] + [negative_condition]).uniq
  self
end