Method: Dynamoid::Adapter#delete

Defined in:
lib/dynamoid/adapter.rb

#delete(table, ids, options = {}) ⇒ Object

Delete an item from a table.

Parameters:

  • table (String)

    the name of the table to write the object to

  • ids (Array)

    to delete, can also be a string of just one id

  • range_key (Array)

    of the record to delete, can also be a string of just one range_key



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/dynamoid/adapter.rb', line 101

def delete(table, ids, options = {})
  range_key = options[:range_key] #array of range keys that matches the ids passed in
  if ids.respond_to?(:each)
    if range_key.respond_to?(:each)
      #turn ids into array of arrays each element being hash_key, range_key
      ids = ids.each_with_index.map{|id,i| [id,range_key[i]]}
    else
      ids = range_key ? [[ids, range_key]] : ids
    end

    batch_delete_item(table => ids)
  else
    delete_item(table, ids, options)
  end
end