Class: Seaquel::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/seaquel/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ Generator

Returns a new instance of Generator.



8
9
10
# File 'lib/seaquel/generator.rb', line 8

def initialize ast
  @ast = ast
end

Instance Method Details

#compact_sqlObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/seaquel/generator.rb', line 12

def compact_sql
  quoter = Quoter.new
 
  # Construct a statement 
  expression_converter = ExpressionConverter.new(quoter)
  statement = Statement.new(expression_converter)

  # And a visitor for the AST
  visitor = StatementGatherer.new(statement, quoter)

  # Gather statement details from the AST
  @ast.visit(visitor)

  # Turn the statement into SQL.
  statement.to_s(:compact)
end