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, options = {}) ⇒ 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, options = {}) ⇒ Abstract
Initialize the adapter
91 92 93 94 95 |
# File 'lib/lotus/model/adapters/abstract.rb', line 91 def initialize(mapper, uri = nil, = {}) @mapper = mapper @uri = uri @options = end |
Instance Method Details
#all(collection) ⇒ Array
Returns all the records for the given collection
151 152 153 |
# File 'lib/lotus/model/adapters/abstract.rb', line 151 def all(collection) raise NotImplementedError end |
#clear(collection) ⇒ Object
Empties the given collection.
195 196 197 |
# File 'lib/lotus/model/adapters/abstract.rb', line 195 def clear(collection) raise NotImplementedError end |
#command(query) ⇒ Object
Executes a command for the given query.
204 205 206 |
# File 'lib/lotus/model/adapters/abstract.rb', line 204 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.
245 246 247 |
# File 'lib/lotus/model/adapters/abstract.rb', line 245 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.
118 119 120 |
# File 'lib/lotus/model/adapters/abstract.rb', line 118 def create(collection, entity) raise NotImplementedError end |
#delete(collection, entity) ⇒ Object
Deletes a record in the database corresponding to the given entity.
140 141 142 |
# File 'lib/lotus/model/adapters/abstract.rb', line 140 def delete(collection, entity) raise NotImplementedError end |
#disconnect ⇒ Object
Disconnects the connection by freeing low level resources
275 276 277 |
# File 'lib/lotus/model/adapters/abstract.rb', line 275 def disconnect raise NotImplementedError end |
#execute(raw) ⇒ NilClass
Executes a raw command
256 257 258 |
# File 'lib/lotus/model/adapters/abstract.rb', line 256 def execute(raw) raise NotImplementedError end |
#fetch(raw, &blk) ⇒ Enumerable<Hash>, Array<Hash>
Fetches raw records from
268 269 270 |
# File 'lib/lotus/model/adapters/abstract.rb', line 268 def fetch(raw, &blk) raise NotImplementedError end |
#find(collection, id) ⇒ Object
Returns a unique record from the given collection, with the given identity.
164 165 166 |
# File 'lib/lotus/model/adapters/abstract.rb', line 164 def find(collection, id) raise NotImplementedError end |
#first(collection) ⇒ Object
Returns the first record in the given collection.
175 176 177 |
# File 'lib/lotus/model/adapters/abstract.rb', line 175 def first(collection) raise NotImplementedError end |
#last(collection) ⇒ Object
Returns the last record in the given collection.
186 187 188 |
# File 'lib/lotus/model/adapters/abstract.rb', line 186 def last(collection) raise NotImplementedError end |
#persist(collection, entity) ⇒ Object
Creates or updates a record in the database for the given entity.
105 106 107 |
# File 'lib/lotus/model/adapters/abstract.rb', line 105 def persist(collection, entity) raise NotImplementedError end |
#query(collection, &blk) ⇒ Object
Returns a query
217 218 219 |
# File 'lib/lotus/model/adapters/abstract.rb', line 217 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.
235 236 237 |
# File 'lib/lotus/model/adapters/abstract.rb', line 235 def transaction( = {}) raise NotImplementedError end |
#update(collection, entity) ⇒ Object
Updates a record in the database corresponding to the given entity.
130 131 132 |
# File 'lib/lotus/model/adapters/abstract.rb', line 130 def update(collection, entity) raise NotImplementedError end |