Hanami my personal return of experience

~/coding > blog ·

2 min read Original article ↗

Skip to content

TL;DR Hanami may be nice on paper but it’s too constraining when it comes to work on real life situations. I’m sorry to say this but Hanami is a hipster framework.

Hanami documentation consits of a starter guide and that’s all. No in-depth documentation. You’ll rapidly notice that if you look for a problem on the web, you won’t get any Stackoverflow answers cause it’s not used that much.

Few weeks ago, I had a problem I was not able to fix, I’ve posted a question on Gitter and nobody replied. The question have posted twice.

Yesterday, I had a problem with Hanami to execute a ‘group by’ and ‘count’ query. Reading the Rom-rb documentation – not the Hanami one – I found the method group_and_count. Perfect isn’t it? But no! It was to good to be true. In Hanami, the repository running a query will always map the result with attributes of its associated entity. And what about extra fields from the result? There are omitted. As simple as that. No easy way to get the raw data fron the query. No, it would be too easy.

One guy had kind of the same problem (https://github.com/hanami/model/issues/466), he got the advice to use another entity with the same fields as the query result. Ok, where is the documentation about how to map the result to another entity? Please tell me, cause personally I don’t know.

There is a map_to method that could do the job but it returns the same object without any modification. Maybe I did something wrong but again, where is the documentation to tell me I’m wrong?

I’ve reproduced my problem with a Rom-rb example and I’ve been able to fix it easily with the as_hash method but in Hanami this method is not accessible on the Rom::Relation object we have access to. Why? I guess it’s because Hanami developers like restrictions.

To be able to fix my problem with this framework, I had to get access to the Sequel::Dataset object and do the call by myself.

As a conclusion, Hanami is too hipster for me. When I use a tool it’s to get things done with not to have hard time trying to fix problems that should not exist.