Class: SqlTools::QueryVisitor

Inherits:
TreeStand::Visitor
  • Object
show all
Defined in:
lib/sql_tools/query_visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ QueryVisitor

Returns a new instance of QueryVisitor.



5
6
7
8
9
# File 'lib/sql_tools/query_visitor.rb', line 5

def initialize(node)
  super(node)
  @ctes = {}
  @query = Query.new
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



3
4
5
# File 'lib/sql_tools/query_visitor.rb', line 3

def query
  @query
end

Instance Method Details

#on_cte(node) ⇒ Object



11
12
13
14
# File 'lib/sql_tools/query_visitor.rb', line 11

def on_cte(node)
  cte = CommonTableExpression.new(node)
  @query.common_table_expressions[cte.name] = cte
end

#on_from(node) ⇒ Object



20
21
22
# File 'lib/sql_tools/query_visitor.rb', line 20

def on_from(node)
  @query.from = node
end

#on_join(node) ⇒ Object



24
25
26
# File 'lib/sql_tools/query_visitor.rb', line 24

def on_join(node)
  @query.join_nodes << node
end

#on_select(node) ⇒ Object



16
17
18
# File 'lib/sql_tools/query_visitor.rb', line 16

def on_select(node)
  @query.select = node
end