Module: Dynomite::Item::Query::Relation::Delete

Included in:
Dynomite::Item::Query::Relation
Defined in:
lib/dynomite/item/query/relation/delete.rb

Instance Method Summary collapse

Instance Method Details

#delete_allObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dynomite/item/query/relation/delete.rb', line 3

def delete_all
  # https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method
  # A single call to BatchWriteItem can transmit up to 16MB of data over the network,
  # consisting of up to 25 item put or delete operations.
  batch_limit = 25 # max batch size for batch_write_item
  each_page.each do |page|
    page.each_slice(batch_limit) do |slice|
      primary_keys = slice.map(&:primary_key)
      delete_requests = primary_keys.map do |primary_key|
        {
          delete_request: {
            key: primary_key,
          },
        }
      end
      request_items = { @source.table_name => delete_requests }
      client.batch_write_item(request_items: request_items)
    end
  end
end

#delete_by(args) ⇒ Object

require args



29
30
31
# File 'lib/dynomite/item/query/relation/delete.rb', line 29

def delete_by(args)
  where(args).delete_all
end

#destroy_allObject



24
25
26
# File 'lib/dynomite/item/query/relation/delete.rb', line 24

def destroy_all
  each(&:destroy)
end

#destroy_by(args) ⇒ Object

require args



34
35
36
# File 'lib/dynomite/item/query/relation/delete.rb', line 34

def destroy_by(args)
  where(args).destroy_all
end