lib/arel/extensions/insert_statement.rb in arel_toolkit-0.2.0 vs lib/arel/extensions/insert_statement.rb in arel_toolkit-0.3.0

- old
+ new

@@ -4,13 +4,20 @@ module Arel module Nodes # https://www.postgresql.org/docs/9.5/sql-insert.html Arel::Nodes::InsertStatement.class_eval do attr_accessor :with - attr_accessor :on_conflict + attr_accessor :conflict attr_accessor :override attr_accessor :returning + + alias_method :old_initialize, :initialize + def initialize + old_initialize + + @returning = [] + end end end module Visitors class ToSql @@ -30,11 +37,11 @@ quote_column_name x.name end.join ', '})" end case o.override - when 0 + when nil, 0 collector << '' when 1 collector << ' OVERRIDING USER VALUE' when 2 collector << ' OVERRIDING SYSTEM VALUE' @@ -53,10 +60,10 @@ unless o.returning.empty? collector << ' RETURNING ' collector = inject_join o.returning, collector, ', ' end - visit(o.on_conflict, collector) if o.on_conflict + visit(o.conflict, collector) if o.conflict collector end # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/PerceivedComplexity