Module: DynamoRecord::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- Document
- Defined in:
- lib/dynamo_record/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#destroy ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/dynamo_record/persistence.rb', line 105 def destroy = self.class. key = { 'id' => self.id } if range_key = self.class.range_key key[range_key] = self.class.dump_field(self.read_attribute(range_key), self.class.attributes[range_key]) end response = self.class.client.delete_item( .merge(key: key ) ) end |
#save ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/dynamo_record/persistence.rb', line 89 def save = self.class. if id.nil? self.id = SecureRandom.uuid elsif @new_record # New item. Don't overwrite if id exists .merge!(condition_expression: 'id <> :s', expression_attribute_values: { ':s' => self.id }) end .merge!(item: self.class.unload(attributes)) response = self.class.client.put_item() @new_record = false true rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException false end |