Module: DynamodbRecord::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Document
- Defined in:
- lib/dynamodb_record/persistence.rb
Overview
Persistence Module
Instance Method Summary collapse
Instance Method Details
#destroy ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/dynamodb_record/persistence.rb', line 125 def destroy = self.class. hash_key = self.class.hash_key range_key = self.class.range_key key = {} key[hash_key] = self.class.dump_field(read_attribute(hash_key), self.class.attributes[hash_key]) if range_key.present? key[range_key] = self.class.dump_field(read_attribute(range_key), self.class.attributes[range_key]) end self.class.client.delete_item(.merge(key:)) end |
#save ⇒ Object
100 101 102 103 104 105 |
# File 'lib/dynamodb_record/persistence.rb', line 100 def save save! true rescue StandardError false end |
#save! ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/dynamodb_record/persistence.rb', line 107 def save! = self.class. self.id = SecureRandom.uuid if id.nil? time = DateTime.now.to_s self.created_at = time if created_at.nil? self.updated_at = time if @new_record # New item. Don't overwrite if id exists .merge!(condition_expression: 'id <> :s', expression_attribute_values: {':s' => id}) end .merge!(item: self.class.unload(attributes)) # puts options self.class.client.put_item() @new_record = false end |