Class: Atomically::OnDuplicateSqlService

Inherits:
Object
  • Object
show all
Defined in:
lib/atomically/on_duplicate_sql_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, columns) ⇒ OnDuplicateSqlService

Returns a new instance of OnDuplicateSqlService.



4
5
6
7
# File 'lib/atomically/on_duplicate_sql_service.rb', line 4

def initialize(klass, columns)
  @klass = klass
  @columns = columns
end

Instance Method Details

#mysql_quote_columns_for_plusObject



9
10
11
12
13
14
# File 'lib/atomically/on_duplicate_sql_service.rb', line 9

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

#pg_quote_columns_for_plusObject



16
17
18
19
20
21
# File 'lib/atomically/on_duplicate_sql_service.rb', line 16

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