Module: ActiveRecordUpsert::Arel::Visitors::ToSqlExtensions

Defined in:
lib/active_record_upsert/arel/visitors/to_sql.rb

Instance Method Summary collapse

Instance Method Details

#table_exists?(name) ⇒ Boolean



46
47
48
# File 'lib/active_record_upsert/arel/visitors/to_sql.rb', line 46

def table_exists?(name)
  schema_cache.data_source_exists?(name)
end

#visit_Arel_Nodes_DoNothing(_o, collector) ⇒ Object



20
21
22
# File 'lib/active_record_upsert/arel/visitors/to_sql.rb', line 20

def visit_Arel_Nodes_DoNothing _o, collector
  collector << "DO NOTHING"
end

#visit_Arel_Nodes_DoUpdateSet(o, collector) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_record_upsert/arel/visitors/to_sql.rb', line 24

def visit_Arel_Nodes_DoUpdateSet o, collector
  wheres = o.wheres

  collector << "DO UPDATE "
  unless o.values.empty?
    collector << " SET "
    collector = inject_join o.values, collector, ", "
  end

  unless wheres.empty?
    collector << " WHERE "
    collector = inject_join wheres, collector, " AND "
  end

  collector
end

#visit_Arel_Nodes_ExcludedColumn(o, collector) ⇒ Object



41
42
43
44
# File 'lib/active_record_upsert/arel/visitors/to_sql.rb', line 41

def visit_Arel_Nodes_ExcludedColumn o, collector
  collector << "EXCLUDED.#{quote_column_name o.column}"
  collector
end

#visit_Arel_Nodes_InsertStatement(o, collector) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/active_record_upsert/arel/visitors/to_sql.rb', line 5

def visit_Arel_Nodes_InsertStatement(o, collector)
  collector = super
  if o.on_conflict
    maybe_visit o.on_conflict, collector
  else
    collector
  end
end

#visit_Arel_Nodes_OnConflict(o, collector) ⇒ Object



14
15
16
17
18
# File 'lib/active_record_upsert/arel/visitors/to_sql.rb', line 14

def visit_Arel_Nodes_OnConflict o, collector
  collector << "ON CONFLICT "
  collector << " (#{quote_column_name o.target.name}) ".gsub(',', '","')
  maybe_visit o.action, collector
end