News for hackers. Stuff that matters.
Re:ORMs Are Backwards by zzzeek on Tuesday September 03, 2019 @09:46PM (#20873236)
> ActiveRecord for example, treats SQL as “the source of truth”, per his definition.

SQLAlchemy author here. I can't imagine how someone would not consider SQLAlchemy to treat "SQL" as the "source of truth" as well. All of SQLAlchemy's constructs map directly to SQL syntactically. Our most grumpy users are the ones who don't know SQL. This blog post would certainly benefit from some actual examples. "ORM-light tools that coerce responses into native structs and allow for type-checking are less offensive to me." - that is...an ORM?

Re:ORMs Are Backwards by taffer on Tuesday September 03, 2019 @10:33PM (#20873459)
What the blog probably means by "SQL as a source of truth" is that you first design your database and then generate the domain classes from it and not vice versa. This is for example what myBatis and JOOQ do.
Re:ORMs Are Backwards by deathanatos on Tuesday September 03, 2019 @10:57PM (#20873601)
I don't think there is enough information from the database schema to feed an ORM reliably. E.g., take a "boolean" in MySQL: MySQL doesn't have proper booleans, it just represents them as a `tinyint`. But you'd really like your ORM to convert those to your language's `bool`!

There is certainly a lot of information in a schema, and you definitely want your ORM's idea of the database and the database's idea of it to be in close alignment, but I feel like any serious attempt would find all sorts of holes like the above when it actually came to doing it.

Re:ORMs Are Backwards by setr on Wednesday September 04, 2019 @12:19AM (#20873969)
Wouldn’t you just offer user-modifiable translators for such cases (presumably with some sane default)? It seems more preferable than writing the domain model in code first, resulting in N copies of the schema definition for N applications utilizing the db..
Re:ORMs Are Backwards by skissane on Wednesday September 04, 2019 @01:21AM (#20874228)
> N copies of the schema definition for N applications utilizing the db..

Is multiple applications talking to a shared DB schema a common practice, especially nowadays?

In my mind, each app/service should have a DB schema which only it talks to, and other apps/services needing data in that DB go through services exposed by that app/service (REST, RPC, GraphQL, whatever) rather than talking to its DB directly. That means you can rearchitect the DB schema, change which DB you use completely, etc., and only the app/service which owns that DB needs to be modified.

Re:ORMs Are Backwards by jacobush on Wednesday September 04, 2019 @02:22AM (#20874519)
Yes, it is common practice just about in every organically grown system, ever. Also anything corporate.
Re:ORMs Are Backwards by falcolas on Wednesday September 04, 2019 @10:18AM (#20877417)
I've done this repeatedly with SQLAlchemy. It does require that I do a bit of additional record keeping in my models, but it's not exactly hard to do.
Re:ORMs Are Backwards by jayd16 on Wednesday September 04, 2019 @04:30AM (#20875127)
Why use an ORM when I have to know SQL and its a direct syntactical mapping?

>"ORM-light tools that coerce responses into native structs and allow for type-checking are less offensive to me." - that is...an ORM?

Yeah...its a light ORM that focuses on turning a result set into an object but not the syntax remapping of queries. Object mapping is almost universally liked but ORMs usually include query syntax mappings and not the addition of a transaction lifecycle into your data objects.

Re:ORMs Are Backwards by zzzeek on Wednesday September 04, 2019 @09:56AM (#20877222)
because an ORM has nothing to do with writing your SQL for you. You can use textual SQL with an ORM and an ORM like SQLAlchemy has a query language that mirrors the structure of SQL in any case. nobody is taking your SQL away. Additionally, you most certainly do want a tool that will write most of your DML for you, there is no deep wisdom or joy in writing the same INSERT / UPDATE statement over and over again.
Re:ORMs Are Backwards by cozos on Wednesday September 04, 2019 @01:12AM (#20874187)
I've used SQLAlchemy a bunch and found that it has excellent support for complex (for me anyways) query options. For example, avoiding N+1 selects with eager joins has been a breeze.