Re:To ORM or Not to ORM
by scarface74 on Tuesday May 07, 2019 @01:57PM
(#19851837)
This is about the only use case where I find ORMs useful
Also a problem solved by less magic libraries, like MyBatis, jOOQ, SQLAlchemy Core, etc.
I'm currently working on an e-shop. I need to display many tables with different filters.
Administrator wants products starting with string? OK: if filter['category']: qs = qs.filter ... Administrator wants products without category? Ok: if filter['category']: qs = qs.filter ... Add multilang supprt? Ok: subclass model, mark fields and translatable, run migrate script
I can combine any filters, ORM automatically creats query with necessary joins, subqueries, group by expressions etc.
If i didn't use ORM i would have to write code that generate select with cca 200 ifs because almost every filter can generate join or add fields to group by or generate subselect etc.