Class: SqlQueryExecutor::Query::Normalizers::QueryNormalizer

Inherits:
BaseNormalizer
  • Object
show all
Defined in:
lib/sql_query_executor/query/normalizers/query_normalizer.rb

Constant Summary collapse

CONVERT_METHODS =
{"String" => "get_query", "Array" => "interpolate_query", "Hash" => "convert_hash"}

Class Method Summary collapse

Class Method Details

.attributes_from_query(query) ⇒ Object



22
23
24
25
26
# File 'lib/sql_query_executor/query/normalizers/query_normalizer.rb', line 22

def self.attributes_from_query(query)
  return {} if query.empty?
  selector = query.class == Hash ? query : Base.new([], query).selector
  super(selector)
end

.clean_query(query) ⇒ Object



18
19
20
# File 'lib/sql_query_executor/query/normalizers/query_normalizer.rb', line 18

def self.clean_query(query)
  remove_placeholders execute(query).gsub('!=', '<>')
end

.execute(query) ⇒ Object



11
12
13
14
15
16
# File 'lib/sql_query_executor/query/normalizers/query_normalizer.rb', line 11

def self.execute(query)
  query = clean_query_attribute(query)
  method = CONVERT_METHODS[query.class.name]

  query = sanitize(send(method, query))
end