Class: AdvancedSearch::Adapters::PG::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/advanced_search/adapters/pg/executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_query, ast, connection) ⇒ Executor

Returns a new instance of Executor.



8
9
10
11
12
# File 'lib/advanced_search/adapters/pg/executor.rb', line 8

def initialize(base_query, ast, connection)
  @base_query = base_query
  @ast = ast
  @connection = connection
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
# File 'lib/advanced_search/adapters/pg/executor.rb', line 14

def execute
  visitor = Visitor.new(:dollars)
  @ast.accept(visitor)
  query = visitor.result
  sql = [@base_query, query.body].join(' where ')
  @connection.exec_params(sql, query.params)
end