Class: Arel::Visitors::ToSql

Inherits:
Visitor
  • Object
show all
Defined in:
lib/postgres_with/arel/visitors/to_sql.rb

Instance Method Summary collapse

Instance Method Details

#collect_ctes(children, collector) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/postgres_with/arel/visitors/to_sql.rb', line 10

def collect_ctes(children, collector)
  children.each_with_index do |child, i|
    collector << ", " unless i == 0

    case child
    when Arel::Nodes::As, Arel::Nodes::AsMaterialized
      name = child.left.name
      relation = child.right
    when Arel::Nodes::TableAlias
      name = child.name
      relation = child.relation
    end

    collector << quote_table_name(name)
    if child.class == Arel::Nodes::AsMaterialized
      collector <<  " AS MATERIALIZED "
    else
      collector <<  " AS "
    end
    visit relation, collector
  end

  collector
end

#visit_Arel_Nodes_AsMaterialized(o, collector) ⇒ Object



4
5
6
7
8
# File 'lib/postgres_with/arel/visitors/to_sql.rb', line 4

def visit_Arel_Nodes_AsMaterialized o, collector
  collector = visit o.left, collector
  collector << " AS MATERIALIZED "
  visit o.right, collector
end