Class: Kvom::Adapter::DynamodbDocument
- Inherits:
-
Document
- Object
- Document
- Kvom::Adapter::DynamodbDocument
show all
- Defined in:
- lib/kvom/adapter/dynamodb_document.rb
Instance Attribute Summary
Attributes inherited from Document
#key, #persisted_revision
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Document
#[], #[]=, #update_revision
Constructor Details
#initialize(key, attributes, item, from_db = false) ⇒ DynamodbDocument
Returns a new instance of DynamodbDocument.
15
16
17
18
|
# File 'lib/kvom/adapter/dynamodb_document.rb', line 15
def initialize(key, attributes, item, from_db = false)
@dynamo_item = item
super(key, attributes, from_db)
end
|
Class Method Details
.document_from_query(key, item_attributes, item) ⇒ Object
7
8
9
10
11
|
# File 'lib/kvom/adapter/dynamodb_document.rb', line 7
def document_from_query(key, item_attributes, item)
item_attributes.delete("hash_key")
item_attributes.delete("range_key")
new(key, item_attributes, item, true)
end
|
Instance Method Details
#destroy ⇒ Object
33
34
35
36
37
|
# File 'lib/kvom/adapter/dynamodb_document.rb', line 33
def destroy
@dynamo_item.delete(revision_condition)
rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException => e
raise Kvom::WriteConflict.wrap(e)
end
|
#write ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/kvom/adapter/dynamodb_document.rb', line 20
def write
dynamo_attributes = attributes.to_h.merge({
"hash_key" => @dynamo_item.hash_value,
"range_key" => @dynamo_item.range_value,
})
begin
@dynamo_item.table.items.put(dynamo_attributes, revision_condition)
rescue AWS::DynamoDB::Errors::ConditionalCheckFailedException => e
raise Kvom::WriteConflict.wrap(e)
end
end
|