Class: Hanami::Repository
- Inherits:
-
ROM::Repository::Root
- Object
- ROM::Repository::Root
- Hanami::Repository
- Defined in:
- gems/gems/hanami-model-1.3.2/lib/hanami/repository.rb
Overview
Mediates between the entities and the persistence layer, by offering an API to query and execute commands on a database.
By default, a repository is named after an entity, by appending the Repository
suffix to the entity class name.
A repository is storage independent. All the queries and commands are delegated to the current adapter.
This architecture has several advantages:
-
Applications depend on an abstract API, instead of low level details (Dependency Inversion principle)
-
Applications depend on a stable API, that doesn't change if the storage changes
-
Developers can postpone storage decisions
-
Isolates the persistence logic at a low level
Hanami::Model is shipped with one adapter:
-
SqlAdapter
All the queries and commands are private. This decision forces developers to define intention revealing API, instead of leaking storage API details outside of a repository.