Sha256: c9845396039b3f3ff9867b18bb021d5c7a59ff4d3c7cfc982985562eb45d27e6

Contents?: true

Size: 685 Bytes

Versions: 3

Compression:

Stored size: 685 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.2 lib/atomically/on_duplicate_sql_service.rb
atomically-1.1.1 lib/atomically/on_duplicate_sql_service.rb
atomically-1.1.0 lib/atomically/on_duplicate_sql_service.rb