Module: Switchman::Arel::Visitors::ToSql

Defined in:
lib/switchman/arel.rb

Instance Method Summary collapse

Instance Method Details

#quote_local_table_name(name) ⇒ Object

rubocop:enable Naming/MethodName rubocop:enable Naming/MethodParameterName



69
70
71
72
73
# File 'lib/switchman/arel.rb', line 69

def quote_local_table_name(name)
  return name if ::Arel::Nodes::SqlLiteral === name

  @connection.quote_local_table_name(name)
end

#visit_Arel_Attributes_Attribute(o, collector) ⇒ Object



36
37
38
39
# File 'lib/switchman/arel.rb', line 36

def visit_Arel_Attributes_Attribute(o, collector)
  join_name = o.relation.table_alias || o.relation.name
  collector << quote_local_table_name(join_name) << "." << quote_column_name(o.name)
end

#visit_Arel_Nodes_Cte(o, collector) ⇒ Object

rubocop:disable Naming/MethodName rubocop:disable Naming/MethodParameterName



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/switchman/arel.rb', line 16

def visit_Arel_Nodes_Cte(o, collector)
  collector << quote_local_table_name(o.name)
  collector << " AS "

  case o.materialized
  when true
    collector << "MATERIALIZED "
  when false
    collector << "NOT MATERIALIZED "
  end

  visit o.relation, collector
end

#visit_Arel_Nodes_HomogeneousIn(o, collector) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/switchman/arel.rb', line 42

def visit_Arel_Nodes_HomogeneousIn(o, collector)
  collector.preparable = false

  collector << quote_local_table_name(o.table_name) << "." << quote_column_name(o.column_name)

  collector << if o.type == :in
                 " IN ("
               else
                 " NOT IN ("
               end

  values = o.casted_values

  if values.empty?
    collector << @connection.quote(nil)
  else
    collector.add_binds(values, o.proc_for_binds, &bind_block)
  end

  collector << ")"
  collector
end

#visit_Arel_Nodes_TableAlias(o, collector) ⇒ Object



30
31
32
33
34
# File 'lib/switchman/arel.rb', line 30

def visit_Arel_Nodes_TableAlias(o, collector)
  collector = visit o.relation, collector
  collector << " "
  collector << quote_local_table_name(o.name)
end