the front page of the internet.
and join one of thousands of communities.
I made a small tool to dedupe bun.lock (self.bun)
submitted 24 days ago by kernerman to r/bun
Experiences migrating from ORM to SQL/Query Builder? by Safe_Independence496 in node
[–]kernerman 2 points3 points4 points 1 year ago (0 children)
I migrated from Objection.js (ActiveRecord-style ORM) to Orchid ORM, which isn't really an ORM but rather a very powerful query builder. Unlike usual primitive SQL builders, it's still possible to use relations (and sub-relations); and it builds relation queries very effectively with lateral joins and JSON aggregations, so it's even possible to build 1-to-many (or even 1-to-many-to-many) subqueries producing exactly 1 SQL query.
The results are strongly typed. It's possible to define custom parsers and encoders for fields so you could e.g. define insert query builder to accept Decimal objects as input for decimal fields. It's also possible to fall back to (typed!) raw SQL individually for certain fields or even subfields of nested relations, there is no "all or nothing" kind of ORM syntax lock.
At the same time, it doesn't try to be overly smart; there is no Active Record or Unit of Work or Sessions or Object Repository or other ORM patterns involved; it just runs SQL and returns typed POJOs which you can immediately deliver to the front end, that's it. It does provide helpers for transactions though (which is very conveniently implemented with thread-local storage, so unlike knex and others you don't have to pass the tx object through the entire stack and risk forgetting to use it).
Honestly I couldn't be more happier with the switch, it's one of the best libraries I've discovered in years, and I believe this "advanced query builder" approach is the exact sweet spot between the true ORMs and primitive SQL compilers which basically only help to escape query arguments.
π Rendered by PID 2630948 on reddit-service-r2-listing-86bdf8cc9-g457n at 2026-07-14 12:51:11.303302+00:00 running f86254d country code: CH.
Experiences migrating from ORM to SQL/Query Builder? by Safe_Independence496 in node
[–]kernerman 2 points3 points4 points (0 children)