Sha256: dff535464e209bd892938507bd09a1a46d2e15e435ab08af437111aa15b79be6

Contents?: true

Size: 717 Bytes

Versions: 4

Compression:

Stored size: 717 Bytes

Contents

require_relative 'base_adapter'

module BulkInsert
  module StatementAdapters
    class PostgreSQLAdapter < BaseAdapter
      def insert_ignore_statement
        ''
      end

      def on_conflict_statement(columns, ignore, update_duplicates)
        if ignore
          ' ON CONFLICT DO NOTHING'
        elsif update_duplicates
          update_values = columns.map do |column|
            "#{column.name}=EXCLUDED.#{column.name}"
          end.join(', ')
          ' ON CONFLICT(' + update_duplicates.join(', ') + ') DO UPDATE SET ' + update_values
        else
          ''
        end
      end

      def primary_key_return_statement(primary_key)
        " RETURNING #{primary_key}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
bulk_insert-1.9.0 lib/bulk_insert/statement_adapters/postgresql_adapter.rb
bulk_insert-1.8.2 lib/bulk_insert/statement_adapters/postgresql_adapter.rb
bulk_insert2-1.0.0 lib/bulk_insert/statement_adapters/postgresql_adapter.rb
bulk_insert-1.8.1 lib/bulk_insert/statement_adapters/postgresql_adapter.rb