Method: OceanDynamo::Persistence::ClassMethods#delete_all

Defined in:
lib/ocean-dynamo/persistence.rb

#delete_allObject

Deletes all records without instantiating them first.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ocean-dynamo/persistence.rb', line 51

def delete_all
  _late_connect?
  ean = { "#H" => table_hash_key }
  ean["#R"] = table_range_key if table_range_key
  options = {
    consistent_read: true,
    projection_expression: "#H" + (table_range_key ? ", #R" : ""),
    expression_attribute_names: ean
  }
  in_batches :scan, options do |attrs|
    if table_range_key
      delete attrs[table_hash_key.to_s], attrs[table_range_key.to_s]
    else
      delete attrs[table_hash_key.to_s]
    end
  end
  nil
end