Beyond ORMs
3 points by noteflakes
3 points by noteflakes
Not gonna argue on the decade old "ORMs are bad" part, to each their own, but:
Another missing feature in ORMs is the ability to use prepared statements.
Not sure what this is about, both Active Record and Sequel support prepared statements.
The article treats “ORM” and ActiveRecord as interchangeable, and that's doing most of the work here. Ruby doesn't really have a session- or value-based ORM to compare against (Sequel exists, but the author abandoned it too), so the specific design choices ActiveRecord made read as inherent to ORMs in general.
In Passing interfaces around, Post.where(...) can be called from a view template because Post is a global constant with an implicit connection behind it, not because it maps rows to objects. SQLAlchemy's Session is a value you pass around; nothing about mapping tables to classes forces the connection itself into global state. The PostsStore pattern the piece lands on is, structurally, a Session with one table's worth of methods on it. I'd call that an argument against ActiveRecord's connection handling, not against ORMs as such.
Same thing with the DSL argument. “SQL knowledge isn't optional, so we don't need a DSL” and “queries are finite, so a general purpose DSL is wasted effort” get treated as one argument, but they're not. SQLAlchemy Core is a DSL that assumes you already know SQL: it's there so you can compose query fragments as values, conditionally add a join, reuse a subquery, not to hide SQL from you. I care more about whether queries need to compose, say to support user-selected filters and sort order, than how many total query shapes an app has. The PostsStore examples in the piece are all fixed-shape, parameterized-only queries. I don't see what query composition would buy those examples.
so you can compose query fragments as values, conditionally add a join, reuse a subquery
Yeah, every time I read a maximalist "ORMs are bad" post, I can't help to wonder if they expect people to do query composition by concatenating strings (or if they somehow never needed query composition???).
While I don't agree with them, I do understand the common arguments against using the "mapper" part of an ORM, but not using a query builder? Even most anti-ORM posts will tell you that query builders are fine.
Ideally I would want databases to be able to accept a JSON representation of, for example, WHERE conditions. I’m sure it could be built with stored procedures or extensions in PostgreSQL, but I haven’t seen it yet. (PostgREST is a similar idea I guess but it’s a whole second application and does a lot more)