> If you're just using an OEM for the "select * from table where ID in ...", then you're saving practically nothing by using an ORM
You’re saving hundreds of lines of repetitive boilerplate code. Do you enjoy writing something like
users = [
User(name=name, color=color)
for name, color
in db.query("SELECT name, color FROM user")
]
over and over?This might be the last year where we have to write code by hand unless we enjoy it though. ;-)
The number of comments implying that ORMs are required for basic software engineering concepts like proper encapsulation and DRY is baffling.
But this gets to the heart of what I was saying. I'll grant you that ORMs save a little bit of boiler plate up front (but not much - ORMs have plenty of their own boiler plate, just instead of a universally understood language like SQL they have it in their own custom config JSON/yaml/XML), but that is where I spend a teeny fraction of my time coding. Writing "boilerplate" SQL for a decently large project (say 50-100 object types) takes me maybe an extra day in coding time. I have wasted multiples of that time trying to track down a single weird ORM bug, or poorly performing query. Plus, spending that time up front to write my queries is always the least stressful time of the project. What is most stressful is when my site is finally getting a big traffic push, but then something causes the DB to crater and the leaky abstraction of the ORM makes it ten times harder to debug.