class Dynamoid::AdapterPlugin::AwsSdkV2::ItemUpdater

Mimics behavior of the yielded object on DynamoDB’s update_item API (high level).

Constants

ADD
DELETE
PUT

Attributes

key[R]
range_key[R]
table[R]

Public Class Methods

new(table, key, range_key = nil) click to toggle source
# File lib/dynamoid/adapter_plugin/aws_sdk_v2.rb, line 692
def initialize(table, key, range_key = nil)
  @table = table; @key = key, @range_key = range_key
  @additions = {}
  @deletions = {}
  @updates   = {}
end

Public Instance Methods

add(values) click to toggle source

Adds the given values to the values already stored in the corresponding columns. The column must contain a Set or a number.

@param [Hash] vals keys of the hash are the columns to update, vals are the values to

add. values must be a Set, Array, or Numeric
# File lib/dynamoid/adapter_plugin/aws_sdk_v2.rb, line 706
def add(values)
  @additions.merge!(values)
end
delete(values) click to toggle source

Removes values from the sets of the given columns

@param [Hash] values keys of the hash are the columns, values are Arrays/Sets of items

to remove
# File lib/dynamoid/adapter_plugin/aws_sdk_v2.rb, line 716
def delete(values)
  @deletions.merge!(values)
end
set(values) click to toggle source

Replaces the values of one or more attributes

# File lib/dynamoid/adapter_plugin/aws_sdk_v2.rb, line 723
def set(values)
  @updates.merge!(values)
end
to_h() click to toggle source

Returns an AttributeUpdates hash suitable for passing to the V2 Client API

# File lib/dynamoid/adapter_plugin/aws_sdk_v2.rb, line 730
def to_h
  ret = {}

  @additions.each do |k,v|
    ret[k.to_s] = {
      action: ADD,
      value: v
    }
  end
  @deletions.each do |k,v|
    ret[k.to_s] = {
      action: DELETE,
      value: v
    }
  end
  @updates.each do |k,v|
    ret[k.to_s] = {
      action: PUT,
      value: v
    }
  end

  ret
end