Today we complete the vision! We are thrilled to share Hanami 2.2 with you. With this release, we introduce a powerful new database layer and a brand new tool for organizing your business logic.
Hanami’s new database layer gives you a clear home for every aspect of your database interactions, along with the means to build your own clean interface for your app’s business layer to consume.
When you generate a new app, you’ll have a ready-to-go DATABASE_URL in your .env. Our default database for new apps is SQLite, with Postgres and MySQL also supported.
After this, you can generate a new relation: hanami generate relation posts. Relations describe your low-level data sources. Here, this means your database tables. Relations are also your place to add reusable, chainable methods that you can use as the building blocks for expressive, higher-level queries. Add something simple to get started:
While you can interact with relations directly, it’s better to build a repo. With repos, you get to build your very own database interface, so you can better manage how your data is accessed across your app. You can build a post repo with hanami generate repo posts. Here you can define a method to return your latest posts, built using the methods in your relation: