hanami-bookshelf-rom
hanami-bookshelf-rom copied to clipboard
Hanami 1.x bookshelf app based on tutorial, tweaked to use rom-rb 4.x standalone
Bookshelf Hanami app using rom-rb standalone
This is the bookshelf hanami application based on the official Getting Started guide with the following tweaks:
- hanami-model was replaced with a standalone rom-rb setup
- entities are under
Bookshelf::Entitiesnamespace - repositories are under
Bookshelf::Repositoriesnamespace - repository instances can be accessed through a convenient method, ie
Bookshelf::Repositories[:Book] DELETE /books/:idwas also implemented
rom-rb setup
The entire rom-rb configuration is handled by config/initializers/rom.rb which defines Bookshelf::Persistence module which exposes the following global methods:
Bookshelf::Persistence.dbreturns a configuredROM::ContainerBookshelf::Persistence.relationsrelation registry (mostly useful in tests)Bookshelf::Persistence.configurationreturnROM::Configurationthat can be useful in rake tasks or scripts that need db connection without the wholeROM::Container
You can tweak this initializer if you need to access more databases, need extra plugins to be enabled etc.
Setup
How to run tests:
% bundle exec rake
How to run the development console:
% bundle exec hanami console
How to run the development server:
% bundle exec hanami server
How to prepare (create and migrate) DB for development and test environments:
% bundle exec rake db:migrate
% HANAMI_ENV=test bundle exec rake db:migrate
Learn more about Hanami
Explore Hanami guides, API docs, or jump in chat for help. Enjoy! 🌸