Class: Lotus::Model::Adapters::DynamodbAdapter Private
- Inherits:
-
Abstract
- Object
- Abstract
- Lotus::Model::Adapters::DynamodbAdapter
- Includes:
- Implementation
- Defined in:
- lib/lotus/model/adapters/dynamodb_adapter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Adapter for Amazon DynamoDB.
Instance Method Summary collapse
-
#_collection(name) ⇒ Lotus::Model::Adapters::Dynamodb::Collection
private
private
Returns a collection from the given name.
-
#clear(collection) ⇒ Object
private
Deletes all the records from the given collection.
-
#command(collection) ⇒ Lotus::Model::Adapters::Dynamodb::Command
private
Fabricates a command for the given query.
-
#create(collection, entity) ⇒ Object
private
Creates a record in the database for the given entity.
-
#delete(collection, entity) ⇒ Object
private
Deletes a record in the database corresponding to the given entity.
-
#find(collection, *key) ⇒ Object
private
Returns an unique record from the given collection, with the given id.
-
#first(collection) ⇒ Object
private
This method is not implemented.
-
#initialize(mapper) ⇒ Lotus::Model::Adapters::DynamodbAdapter
constructor
private
Initialize the adapter.
-
#last(collection) ⇒ Object
private
This method is not implemented.
-
#query(collection, context = nil, &blk) ⇒ Lotus::Model::Adapters::Dynamodb::Query
private
Fabricates a query.
-
#update(collection, entity) ⇒ Object
private
Updates a record in the database corresponding to the given entity.
Constructor Details
#initialize(mapper) ⇒ Lotus::Model::Adapters::DynamodbAdapter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the adapter.
It takes advantage of AWS::DynamoDB::Client to perform all operations.
33 34 35 36 37 38 39 40 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 33 def initialize(mapper) super @client = AWS::DynamoDB::Client.new( api_version: Lotus::Dynamodb::API_VERSION ) @collections = {} end |
Instance Method Details
#_collection(name) ⇒ Lotus::Model::Adapters::Dynamodb::Collection (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a collection from the given name.
180 181 182 183 184 185 186 187 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 180 def _collection(name) @collections[name] ||= Dynamodb::Collection.new( @client, Lotus::Model::Adapters::Dynamodb::Coercer.new(_mapped_collection(name)), name, _identity(name), ) end |
#clear(collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes all the records from the given collection.
This works terribly slow at the moment, and this is only useful for testing small collections. Consider re-creating table from scratch.
90 91 92 93 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 90 def clear(collection) blk = Proc.new {} query(collection, blk).each { |entity| delete(collection, entity) } end |
#command(collection) ⇒ Lotus::Model::Adapters::Dynamodb::Command
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fabricates a command for the given query.
147 148 149 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 147 def command(collection) Dynamodb::Command.new(_collection(collection), _mapped_collection(collection)) end |
#create(collection, entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a record in the database for the given entity. It assigns the ‘id` attribute, in case of success.
52 53 54 55 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 52 def create(collection, entity) entity.id = command(collection).create(entity) entity end |
#delete(collection, entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes a record in the database corresponding to the given entity.
77 78 79 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 77 def delete(collection, entity) command(collection).delete(entity) end |
#find(collection, *key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an unique record from the given collection, with the given id.
105 106 107 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 105 def find(collection, *key) command(collection).get(key) end |
#first(collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method is not implemented. DynamoDB does not allow table-wide sorting.
119 120 121 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 119 def first(collection) raise NotImplementedError end |
#last(collection) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method is not implemented. DynamoDB does not allow table-wide sorting.
133 134 135 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 133 def last(collection) raise NotImplementedError end |
#query(collection, context = nil, &blk) ⇒ Lotus::Model::Adapters::Dynamodb::Query
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fabricates a query
164 165 166 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 164 def query(collection, context = nil, &blk) Dynamodb::Query.new(_collection(collection), _mapped_collection(collection), &blk) end |
#update(collection, entity) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Updates a record in the database corresponding to the given entity.
66 67 68 |
# File 'lib/lotus/model/adapters/dynamodb_adapter.rb', line 66 def update(collection, entity) command(collection).update(entity) end |