Sha256: 9e56a196da9569ecc6cf4c906c564046527e475a0ba5d5733248842f5f51e266

Contents?: true

Size: 850 Bytes

Versions: 129

Compression:

Stored size: 850 Bytes

Contents

# frozen-string-literal: true

module Sequel
  class Dataset
    module Replace
      # Execute a REPLACE statement on the database (deletes any duplicate
      # rows before inserting).
      def replace(*values)
        execute_insert(replace_sql(*values))
      end

      # SQL statement for REPLACE
      def replace_sql(*values)
        clone(:replace=>true).insert_sql(*values)
      end

      # Replace multiple rows in a single query.
      def multi_replace(*values)
        clone(:replace=>true).multi_insert(*values)
      end

      # Databases using this module support REPLACE.
      def supports_replace?
        true
      end

      private

      # If this is an replace instead of an insert, use replace instead
      def insert_insert_sql(sql)
        sql << (@opts[:replace] ? 'REPLACE' : 'INSERT')
      end
    end
  end
end

Version data entries

129 entries across 112 versions & 2 rubygems

Version Path
sequel-5.88.0 lib/sequel/adapters/utils/replace.rb
sequel-5.87.0 lib/sequel/adapters/utils/replace.rb
sequel-5.86.0 lib/sequel/adapters/utils/replace.rb
sequel-5.85.0 lib/sequel/adapters/utils/replace.rb
sequel-5.84.0 lib/sequel/adapters/utils/replace.rb
sequel-5.83.1 lib/sequel/adapters/utils/replace.rb
sequel-5.83.0 lib/sequel/adapters/utils/replace.rb
sequel-5.82.0 lib/sequel/adapters/utils/replace.rb
sequel-5.81.0 lib/sequel/adapters/utils/replace.rb
sequel-5.80.0 lib/sequel/adapters/utils/replace.rb
sequel-5.79.0 lib/sequel/adapters/utils/replace.rb
sequel-5.78.0 lib/sequel/adapters/utils/replace.rb
sequel-5.77.0 lib/sequel/adapters/utils/replace.rb
sequel-5.76.0 lib/sequel/adapters/utils/replace.rb
sequel-5.75.0 lib/sequel/adapters/utils/replace.rb
sequel-5.74.0 lib/sequel/adapters/utils/replace.rb
sequel-5.73.0 lib/sequel/adapters/utils/replace.rb
sequel-5.72.0 lib/sequel/adapters/utils/replace.rb
sequel-5.71.0 lib/sequel/adapters/utils/replace.rb
sequel-5.70.0 lib/sequel/adapters/utils/replace.rb