12 points · by kalodim · 14y ago · 9 comments
Good ORMs like SQLAlchemy first model a relational database and then build the object bits on top of that. That's why you can do an explicit outer join between models so you end up making a constant number of queries (instead of n queries with the naive attribute fetch in a loop).
One almost never has to write SQL when using SQLAlchemy, as opposed to, for example, Django's ORM, which has a much more "mainstream" design. SQLAlchemy is more like a relational/SQL library + an optional ORM-like thing.
Whilst I dare say there're applications where ORM is the only sensible choice, I've yet to see any trace of them in my (fairly) varied experience.
In a language like PHP there's a lot of annoying boilerplate you have to write around every query you run by hand like looping over the result set that an ORM can just convert into a pretty little associative array for you with a consistent structure.
As far as I'm aware, any ORM allows for hand-written queries, so if the argument is that ORM-generated queries are too bloated/slow, you can still write optimized queries where needed and still take advantage of the automatically conversion of the result set to a useful object.
That's valuable and good abstractions are worth some trade-offs.
Of course you also get that if you use an object database like ZODB but you face similar trade-offs most noteably speed which is usually solved by using a RDMS for indexing.