Class: Rom::Dynamo::Dataset
- Inherits:
-
Object
- Object
- Rom::Dynamo::Dataset
- Defined in:
- lib/rom/dynamo/relation.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connection ⇒ Object
(also: #ddb)
readonly
Returns the value of attribute connection.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #delete(hash) ⇒ Object
-
#each(&block) ⇒ Object
READ #############.
- #index_restrict(index, query) ⇒ Object
-
#initialize(name, ddb, conditions = nil) ⇒ Dataset
constructor
A new instance of Dataset.
-
#insert(hash) ⇒ Object
WRITE #############.
- #restrict(query = nil) ⇒ Object
Constructor Details
#initialize(name, ddb, conditions = nil) ⇒ Dataset
Returns a new instance of Dataset.
23 24 25 26 |
# File 'lib/rom/dynamo/relation.rb', line 23 def initialize(name, ddb, conditions = nil) @name, @connection = name, ddb @conditions = conditions || {} end |
Instance Attribute Details
#connection ⇒ Object (readonly) Also known as: ddb
Returns the value of attribute connection.
20 21 22 |
# File 'lib/rom/dynamo/relation.rb', line 20 def connection @connection end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/rom/dynamo/relation.rb', line 20 def name @name end |
Instance Method Details
#delete(hash) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/rom/dynamo/relation.rb', line 57 def delete(hash) connection.delete_item({ table_name: name, key: hash_to_key(hash), expected: to_expected(hash), }) end |
#each(&block) ⇒ Object
READ #############
29 30 31 32 33 34 |
# File 'lib/rom/dynamo/relation.rb', line 29 def each(&block) each_item({ consistent_read: true, key_conditions: @conditions }, &block) end |
#index_restrict(index, query) ⇒ Object
43 44 45 46 47 |
# File 'lib/rom/dynamo/relation.rb', line 43 def index_restrict(index, query) conds = query_to_conditions(query) conds = @conditions.merge(conds) dup_as(GlobalIndexDataset, index: index, conditions: conds) end |
#insert(hash) ⇒ Object
WRITE #############
50 51 52 53 54 55 |
# File 'lib/rom/dynamo/relation.rb', line 50 def insert(hash) connection.put_item({ table_name: name, item: hash }) end |
#restrict(query = nil) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/rom/dynamo/relation.rb', line 36 def restrict(query = nil) return self if query.nil? conds = query_to_conditions(query) conds = @conditions.merge(conds) dup_as(Dataset, conditions: conds) end |