Discussion summary

Discussions highlight that learning SQL is valuable as LLMs can translate ORM to SQL accurately. Some prefer raw SQL for complex queries, while others find ORMs sufficient for most use cases.

What the discussion says

  • LLMs can now translate ORM to SQL with high accuracy.
  • Many users find ORMs sufficient for typical use cases.
  • Raw SQL is preferred for complex or performance-critical queries.
  • NoSQL is seen as more efficient for operational data by some.
  • Using both ORMs and raw SQL is common depending on the scenario.
“LLMs can translate ORM to SQL with ~100% accuracy.”
— nomilk
“Relational DBs are an operational anti-pattern, NoSQL is more efficient.”
— ChicagoDave

Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • I'm totally on board with the idea that ORMs create a variety of inefficiencies, pain points, and make it really easy to create bad queries or querying strategies. But I use them anyways because the convenience of mapping a row to a code object makes writing programs feel fast and simple. And if you know how ORMs can cause problems and how to watch out for them, you can still get a lot of mileage out of them.

    That being said, what's the closest alternative that satisfies this - "mapping rows to a code object" - that doesn't suffer the same problems as an ORM? A middle ground between an ORM (like SQLAlchemy, for example) and "your rows are returned as a key/value dictionary where the column names are keys" type approach like Python's DB-API's DictCursor or PHP's mysqli_fetch_assoc. Is there a middle ground here?

  • Related:

    What ORMs have taught me: just learn SQL - https://news.ycombinator.com/item?id=28812506 - Oct 2021 (24 comments)

    What ORMs Have Taught Me: Just Learn SQL (2014) - https://news.ycombinator.com/item?id=24845300 - Oct 2020 (291 comments)

    What ORMs have taught me: just learn SQL (2014) - https://news.ycombinator.com/item?id=21031187 - Sept 2019 (634 comments)

    What ORMs have taught me: just learn SQL (2014) - https://news.ycombinator.com/item?id=15949144 - Dec 2017 (348 comments)

    What ORMs have taught me: just learn SQL (2014) - https://news.ycombinator.com/item?id=11981045 - June 2016 (295 comments)

    What ORMs have taught me: just learn SQL - https://news.ycombinator.com/item?id=8133835 - Aug 2014 (234 comments)

    by dang
  • I used to love ORMs so much that I built one for Java, in the early 90s, and it was one of the main offerings of a startup that I joined. I have come around 180 degrees. My rethink started when a developer at a Wall Street bank said: having Oracle on my resume is valuable. Having your ORM on my resume is not.

    And then there’s the “now you have two problems” dynamic. You not only have to write high-performing queries, but you have to get the ORM to generate that query for you. And sometimes you don’t want objects. And the schema mapping has to track schema changes.

    Just write the damned SQL, it’s not that difficult.

  • I generally like ORMs but recognize that they have a lot of problems. The most common problem that I've seen is when an ORM makes it easy to select records in a way that looks efficient but really is not. Strictly speaking, this isn't a failure of the ORM itself -- it's the fault of the developer who is using the ORM and also the developer that didn't catch it in code review. But it's a case where the ORM is making work for everyone and obscuring legibility into the code instead of saving time and providing clarity.

    I've written complicated stuff where an ORM isn't appropriate, but if I'm honest, a large fraction of what I've done in my career is just making boring software to automate menial clerical work, and ORMs are good enough for those kinds of projects.

  • Feels like everyone has to go on the journey.

    ORMs are bad - I’ll just use SQL.

    Hmm - I need to map these results onto objects I can use.

    Hmm - wouldn’t it be great if the object tracked changes and could save itself.

    I need related/child objects - wouldn’t it be great if I could auto fetch them. …

  • Why not both? ORMs for the simpler CRUD operations, SQL when it gets a little hectic.

    The author basically says this in the first paragraph, but the title (and some of the language the author uses) implies that people should just use SQL.

    It's a reasonable article pointing out some of the annoyances and problems of ORMs (especially in the Java world, where they tend to be overengineered) but there are still a lot of advantages to them if you are in an OO language and they used in a reasonable way.

  • People have been making these same arguments for decades and at this point I'm convinced they are all based on the same strawman:

    That ORM's absolve you from having to learn SQL.

    Once you understand that was never actually true to begin with you can treat the ORM as a tool that simply helps you generate repetitive boilerplate queries and hydrates result rows back into objects for you.

    Furthermore, if your objects are long lived (e.g. client-side apps) then ORMs offer you helpful features like identity mapping, unit of work, and change tracking/events.

    I'm also convinced most of the people poo-pooing on ORMs just haven't worked on problems where these kinds of features are useful. I mean, if you're writing a reporting tool that just queries the database and dumps the result to a table then yeah you might not need an ORM for that. It doesn't mean that ORMs don't solve useful problems for other use cases though.

  • I don't disagree with any of the major gripes people have with orms and I find SQL to be much cleaner in a lot of circumstances.

    That being said, if orms didn't force you to explicitly define your domain models about 60% of developers would simply never do it. And you would see differently structured, ad-hoc interfaces defined all over the code base completely entangled with whatever action they are trying to perform.

    ORMs being a forcing function for domain modeling is enough benefit for me that it outweighs all of their obvious limitations.

Explore Birbla archives