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 (String, Array)

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

  • options (Hash) (defaults to: {})

    allowed only range_key - range key or array of range keys of the record to delete, can also be a string of just one range_key, and conditions



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

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)
    ids = if range_key.respond_to?(:each)
            # turn ids into array of arrays each element being hash_key, range_key
            ids.each_with_index.map { |id, i| [id, range_key[i]] }
          else
            range_key ? ids.map { |id| [id, range_key] } : ids
          end

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