Hanami components are decoupled from each other. This level of separation allows you to use the ORM (data layer) of your choice.
Here’s how to do it:
- Edit your
Gemfile
:- Remove
hanami-model
. - Add the gem(s) for your ORM.
- Remove
- Run
bundle install
. - Remove folders that are no longer needed:
- Remove
lib/project_name/entities/
andlib/projectname/repositories/
- Remove
spec/project_name/entities/
andspec/project_name/repositories/
.
- Remove
- Edit
config/environment.rb
:- Remove
require 'hanami/model'
- Remove
require_relative '../lib/projectname'
- Remove
model
block inHanami.configure
- Remove
- Edit
Rakefile
:- Remove
require 'hanami/rake_tasks'
.
- Remove
In general, lib/project_name/
is a good place to put code that’s used across apps, so we don’t recommend getting rid of it entirely. That’s also where Hanami’s mailers live. We recommend that you put your new ORM code into that folder, but you’re free to put it elsewhere, and get rid of lib/
entirely, if you choose.
Please be aware that if hanami-model
is removed from the project features like database commands and migrations won’t be available.
Hanami + ROM 4.0
If you want to use latest rom version without hanami-model you can use this repository as a tutorial for this:
https://github.com/solnic/hanami-bookshelf-rom/