aws / aws-sdk-ruby-record

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
318 stars 41 forks source link

Update Request Parameters #62

Closed IbottaBaier closed 2 years ago

IbottaBaier commented 7 years ago

Record.update! only accepts record attributes as parameters, disallowing the configuration of 'return_value' or 'return_consumed_capacity'.

To reiterate my solution describe in #59:

To handle this I created a SimpleDelegator which delegates an Aws::DynamoDB::Client and provides additional functionality:

  class InterceptClient < SimpleDelegator

    attr_accessor :update_item_params

    # inject additional parameters for update requests
    def update_item(request)
      super(request.merge(update_item_params))
    end
  end

I then created a new_client function for generating clients (mainly exposed to be overridden in test, if necessary):

      # Spawns a new client with necessary request parameter overrides.
      def self.new_client
        client = InterceptClient.new(Aws::DynamoDB::Client.new(stub_responses: Rails.env.test?))
        client.update_item_params = { return_values: 'ALL_NEW' }
        client
      end

This is severely limiting due to the fact that the class and all instances share the same client - this means ALL updates must return 'ALL_NEW' attributes; there is no way to (safely) change that value in a multi-threaded environment (using Shoryuken for processing SQS messages and reading/writing Dynamo).

awood45 commented 7 years ago

I hear what you're saying. I think since a V2 bump is planned anyways to support the modularized SDK, I may look to include some API adjustments.

mullermp commented 2 years ago

Duplicate of #59