by wvenable · 7y ago · 0 comments
Simple tasks are done maybe thousands of times in any one application. It's the complex tasks are rare.
That's not a fair comparison unless you include the time and effort involved in creating your ORM models, before you can even write those 3 lines of ORM code. The effort to construct those models isn't even fully amortized over your project, since it must be maintained through schema migrations.
ORMs are like putting on an exoskeleton to go buy groceries because it will let you carry your bags more easily. In my opinion, the complexity and indirection they introduce for accomplishing simple tasks do not justify their existence in the vast majority of cases.
It's no more difficult than building tables by hand. There isn't any extra work that you wouldn't also have to do when not using an ORM.
cursor.execute("""
UPDATE employees
INNER JOIN merits ON employees.performance = merits.performance
SET salary = salary + salary * percentage;
""")
Please show me how much simpler and fewer lines that would be in ORM code + model definitions.It's not much more effort to type "create table employees" with all the fixings as it is to type "class employees" with all the fixings.
$db->employees->update({
salary => $Q{salary} + $Q{salary} * $Q{merit}{percentage}
});
Not that much simpler in that case, but at least lets you define the JOIN once rather than repeating it per-query.The Hibernate repo is 700 thousand lines of java code!
There's a tendency amongst some (especially "enterprise" programmers) to forget that dependencies are also just code. If they break, you are on the hook too. You own that complexity.
A good SQL access library can validate queries against the database itself at build time.
await client.query(`
update table set c1 = $1, c2 = $2
where id = $3 and userId = $4
`, [c1, c2, id, userId]);