lib/rom/sql/extensions/postgres/commands.rb in rom-sql-3.6.4 vs lib/rom/sql/extensions/postgres/commands.rb in rom-sql-4.0.0.alpha1

- old
+ new

@@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'rom/sql/commands/create' -require 'rom/sql/commands/update' +require "rom/sql/commands/create" +require "rom/sql/commands/update" module ROM module SQL module Postgres module Commands @@ -81,33 +81,37 @@ # This implementation uses Sequel's API underneath, the docs are available at # http://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/Postgres/DatasetMethods.html#method-i-insert_conflict # # @api public class Upsert < SQL::Commands::Create - adapter :sql + config.component.adapter = :sql - defines :constraint, :conflict_target, :conflict_where, :update_statement, :update_where + setting :constraint + setting :conflict_target + setting :conflict_where + setting :update_statement + setting :update_where # @!attribute [r] constraint # @return [Symbol] the name of the constraint expected to be violated - option :constraint, default: -> { self.class.constraint } + option :constraint, default: -> { config.constraint } # @!attribute [r] conflict_target # @return [Object] the column or expression to handle a violation on - option :conflict_target, default: -> { self.class.conflict_target } + option :conflict_target, default: -> { config.conflict_target } # @!attribute [r] conflict_where # @return [Object] the index filter, when using a partial index to determine uniqueness - option :conflict_where, default: -> { self.class.conflict_where } + option :conflict_where, default: -> { config.conflict_where } # @!attribute [r] update_statement # @return [Object] the update statement which will be executed in case of a violation - option :update_statement, default: -> { self.class.update_statement } + option :update_statement, default: -> { config.update_statement } # @!attribute [r] update_where # @return [Object] the WHERE clause to be added to the update - option :update_where, default: -> { self.class.update_where } + option :update_where, default: -> { config.update_where } # Tries to insert provided tuples and do an update (or nothing) # when the inserted record violates a unique constraint and hence # cannot be appended to the table # @@ -135,29 +139,7 @@ end end end Commands::Postgres = Postgres::Commands - - Gateway.subscribe('configuration.commands.class.before_build') do |event| - klass = event[:command] - - # TODO: remove this conditional in favor of `adapter: :sql` in subscribe - # this is here for backward compatibilty with rom-core 4.x - if klass.adapter == :sql - dataset = event[:dataset] - type = dataset.db.database_type - - if type == :postgres - ext = - if klass < Commands::Create - Postgres::Commands::Create - elsif klass < Commands::Update - Postgres::Commands::Update - end - - klass.include(ext) if ext - end - end - end end end