Sha256: 88c37fe81323bf607490de3ab7fa051d9eb82e87cef75396fb47080e1601e37e

Contents?: true

Size: 713 Bytes

Versions: 3

Compression:

Stored size: 713 Bytes

Contents

# frozen_string_literal: true

class Atomically::OnDuplicateSqlService
  def initialize(klass, columns)
    @klass = klass
    @columns = columns
  end

  def mysql_quote_columns_for_plus
    return @columns.map do |column|
      quoted_column = quote_column(column)
      next "#{quoted_column} = #{quoted_column} + VALUES(#{quoted_column})"
    end
  end

  def pg_quote_columns_for_plus
    return @columns.map do |column|
      quoted_column = quote_column(column)
      next "#{quoted_column} = #{@klass.quoted_table_name}.#{quoted_column} + excluded.#{quoted_column}"
    end
  end

  private

  def quote_column(column)
    @klass.connection.quote_column_name(column)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atomically-1.1.5 lib/atomically/on_duplicate_sql_service.rb
atomically-1.1.4 lib/atomically/on_duplicate_sql_service.rb
atomically-1.1.3 lib/atomically/on_duplicate_sql_service.rb