Sha256: 6ac9ccc82630afca2a86bd671c614e7837a0c602c95f10228cace6e275829275

Contents?: true

Size: 624 Bytes

Versions: 2

Compression:

Stored size: 624 Bytes

Contents

module Polo
  module Adapters
    class MySQL
      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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polo-0.5.0 lib/polo/adapters/mysql.rb
polo-0.4.1 lib/polo/adapters/mysql.rb