Class: Polo::Adapters::MySQL

Inherits:
Object
  • Object
show all
Defined in:
lib/polo/adapters/mysql.rb

Instance Method Summary collapse

Instance Method Details

#ignore_transform(inserts, records) ⇒ Object



17
18
19
20
21
# File 'lib/polo/adapters/mysql.rb', line 17

def ignore_transform(inserts, records)
  inserts.map do |insert|
    insert.gsub("INSERT", "INSERT IGNORE")
  end
end

#on_duplicate_key_update(inserts, records) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/polo/adapters/mysql.rb', line 4

def on_duplicate_key_update(inserts, records)
  insert_and_record = inserts.zip(records)
  insert_and_record.map do |insert, record|
    values_syntax = record.attributes.keys.map do |key|
      "#{key} = VALUES(#{key})"
    end

    on_dup_syntax = "ON DUPLICATE KEY UPDATE #{values_syntax.join(', ')}"

    "#{insert} #{on_dup_syntax}"
  end
end