Class: Lotus::Model::Adapters::Abstract
- Inherits:
-
Object
- Object
- Lotus::Model::Adapters::Abstract
- Defined in:
- lib/lotus/model/adapters/abstract.rb
Overview
Abstract adapter.
An adapter is a concrete implementation that allows a repository to communicate with a single database.
Lotus::Model is shipped with Memory and SQL adapters. Third part adapters MUST implement the interface defined here. For convenience they may inherit from this class.
These are low level details, and shouldn’t be used directly. Please use a repository for entities persistence.
Direct Known Subclasses
Instance Method Summary collapse
-
#all(collection) ⇒ Array
Returns all the records for the given collection.
-
#clear(collection) ⇒ Object
Empties the given collection.
-
#command(query) ⇒ Object
Executes a command for the given query.
-
#connection_string ⇒ String
Returns a string which can be executed to start a console suitable for the configured database.
-
#create(collection, entity) ⇒ Object
Creates a record in the database for the given entity.
-
#delete(collection, entity) ⇒ Object
Deletes a record in the database corresponding to the given entity.
-
#disconnect ⇒ Object
Disconnects the connection by freeing low level resources.
-
#execute(raw) ⇒ NilClass
Executes a raw command.
-
#fetch(raw, &blk) ⇒ Enumerable<Hash>, Array<Hash>
Fetches raw records from.
-
#find(collection, id) ⇒ Object
Returns a unique record from the given collection, with the given identity.
-
#first(collection) ⇒ Object
Returns the first record in the given collection.
-
#initialize(mapper, uri = nil) ⇒ Abstract
constructor
Initialize the adapter.
-
#last(collection) ⇒ Object
Returns the last record in the given collection.
-
#persist(collection, entity) ⇒ Object
Creates or updates a record in the database for the given entity.
-
#query(collection, &blk) ⇒ Object
Returns a query.
-
#transaction(options = {}) ⇒ Object
Wraps the given block in a transaction.
-
#update(collection, entity) ⇒ Object
Updates a record in the database corresponding to the given entity.
Constructor Details
#initialize(mapper, uri = nil) ⇒ Abstract
Initialize the adapter
89 90 91 92 |
# File 'lib/lotus/model/adapters/abstract.rb', line 89 def initialize(mapper, uri = nil) @mapper = mapper @uri = uri end |
Instance Method Details
#all(collection) ⇒ Array
Returns all the records for the given collection
148 149 150 |
# File 'lib/lotus/model/adapters/abstract.rb', line 148 def all(collection) raise NotImplementedError end |
#clear(collection) ⇒ Object
Empties the given collection.
192 193 194 |
# File 'lib/lotus/model/adapters/abstract.rb', line 192 def clear(collection) raise NotImplementedError end |
#command(query) ⇒ Object
Executes a command for the given query.
201 202 203 |
# File 'lib/lotus/model/adapters/abstract.rb', line 201 def command(query) raise NotImplementedError end |
#connection_string ⇒ String
Returns a string which can be executed to start a console suitable for the configured database.
242 243 244 |
# File 'lib/lotus/model/adapters/abstract.rb', line 242 def connection_string raise NotSupportedError end |
#create(collection, entity) ⇒ Object
Creates a record in the database for the given entity. It should assign an id (identity) to the entity in case of success.
115 116 117 |
# File 'lib/lotus/model/adapters/abstract.rb', line 115 def create(collection, entity) raise NotImplementedError end |
#delete(collection, entity) ⇒ Object
Deletes a record in the database corresponding to the given entity.
137 138 139 |
# File 'lib/lotus/model/adapters/abstract.rb', line 137 def delete(collection, entity) raise NotImplementedError end |
#disconnect ⇒ Object
Disconnects the connection by freeing low level resources
272 273 274 |
# File 'lib/lotus/model/adapters/abstract.rb', line 272 def disconnect raise NotImplementedError end |
#execute(raw) ⇒ NilClass
Executes a raw command
253 254 255 |
# File 'lib/lotus/model/adapters/abstract.rb', line 253 def execute(raw) raise NotImplementedError end |
#fetch(raw, &blk) ⇒ Enumerable<Hash>, Array<Hash>
Fetches raw records from
265 266 267 |
# File 'lib/lotus/model/adapters/abstract.rb', line 265 def fetch(raw, &blk) raise NotImplementedError end |
#find(collection, id) ⇒ Object
Returns a unique record from the given collection, with the given identity.
161 162 163 |
# File 'lib/lotus/model/adapters/abstract.rb', line 161 def find(collection, id) raise NotImplementedError end |
#first(collection) ⇒ Object
Returns the first record in the given collection.
172 173 174 |
# File 'lib/lotus/model/adapters/abstract.rb', line 172 def first(collection) raise NotImplementedError end |
#last(collection) ⇒ Object
Returns the last record in the given collection.
183 184 185 |
# File 'lib/lotus/model/adapters/abstract.rb', line 183 def last(collection) raise NotImplementedError end |
#persist(collection, entity) ⇒ Object
Creates or updates a record in the database for the given entity.
102 103 104 |
# File 'lib/lotus/model/adapters/abstract.rb', line 102 def persist(collection, entity) raise NotImplementedError end |
#query(collection, &blk) ⇒ Object
Returns a query
214 215 216 |
# File 'lib/lotus/model/adapters/abstract.rb', line 214 def query(collection, &blk) raise NotImplementedError end |
#transaction(options = {}) ⇒ Object
Wraps the given block in a transaction.
For performance reasons the block isn’t in the signature of the method, but it’s yielded at the lower level.
Please note that it’s only supported by some databases. For this reason, the options may vary from adapter to adapter.
232 233 234 |
# File 'lib/lotus/model/adapters/abstract.rb', line 232 def transaction( = {}) raise NotImplementedError end |
#update(collection, entity) ⇒ Object
Updates a record in the database corresponding to the given entity.
127 128 129 |
# File 'lib/lotus/model/adapters/abstract.rb', line 127 def update(collection, entity) raise NotImplementedError end |