News for hackers. Stuff that matters.
Re:ORMs Are Backwards by jrochkind1 on Tuesday September 03, 2019 @09:30PM (#20873161)
If "SQL is the source of truth" means you have no in-memory state, I'm not sure that's feasible, with or without an ORM.

Once you fetch something from the db, you have it in variables in memory. With or without an ORM. That could no longer be sync'd with the db a ms later. That you will probably re-use for more than one access (if you need it more than once), because issuing the same SQL again the second time you need to reference any data returned, in a given routine, would be insane.

Re:ORMs Are Backwards by derefr on Tuesday September 03, 2019 @09:40PM (#20873204)
I think what they’re proposing is something like “if I want to read and then update a value, incrementing it by one, the proper way to do that is to tell the DB to increment whatever value it has stored; not to increment my local representation of the value and then tell the DB to overwrite the value with it.”
Re:ORMs Are Backwards by jrochkind1 on Tuesday September 03, 2019 @09:48PM (#20873251)
The number of times I've had to increment a value by one are minimal. Or similar things where you want to update one value based on the other values, and do it in an atomic way.

But if I had to increment specifically, and were using ActiveRecord... I'd use the ActiveRecord increment! method. Which has the proper db-atomicity semantics you want, it does execute `UPDATE x SET n = n+1 WHERE pk = y ...`

Re:ORMs Are Backwards by Scarblac on Wednesday September 04, 2019 @04:42AM (#20875200)
ORMs do that fine, for instance it'd be

    MyModel.objects.filter(pk=...).update(myfield=F('myfield') + 1)
In Django's ORM.
Re:ORMs Are Backwards by rubber_duck on Wednesday September 04, 2019 @05:30AM (#20875447)
This is not obvious unless you think about it - I've seen issues like this because the code looks correct if you ignore the update semantics, especially when it wont fail on your local dev env because in memory state will be the same as DB state since you're the only one hitting it...

Having to think about these things because the abstraction is leaky instead of just using the SQL where the transformation is explicit is not worth the hassle.

Using Clojure and yesql was a real pleasure for this - Clojure is immutable so you're working with values all over the place - and working with SQL query is just passing values in it and getting values out - no magic mapping - it's just values - if you want the latest value - query again, if you want to store a new value - send the new value. No mutation, no magic, just data.

Re:ORMs Are Backwards by jayd16 on Wednesday September 04, 2019 @04:58AM (#20875283)
So obvious and simple! ...or you could just use SQL.
Re:ORMs Are Backwards by ben509 on Wednesday September 04, 2019 @09:23AM (#20876931)
> Once you fetch something from the db, you have it in variables in memory. With or without an ORM. That could no longer be sync'd with the db a ms later.

Nope. The DBMS is making the same transaction isolation guarantees to an ORM as to any other client.

I think the larger "source of truth" issue is how the schema is represented.

All of these systems that provide their set of schema objects that are then pushed to the database. This works fine for LAMP stacks, but as soon as you grow it becomes apparent that you've put the horse before the cart.