logoalt Hacker News

hatefulheartyesterday at 4:03 PM6 repliesview on HN

I have seen many ORM enjoyers argue the point about “you can just use SQL!” but I have never once seen an ORM enjoyer allow it, much less do it themselves in an actual codebase. They will time and time again prefer you write 100 lines of Typescript/Python for what could be achieved with 15 lines of SQL.


Replies

smwtoday at 5:09 PM

Even the 'worst' of the ORMs (according to the people in these threads) makes this very easy:

  users = User.find_by_sql(<<~SQL)
    SELECT users.*,
           COUNT(posts.id) AS posts_count
    FROM users
    LEFT JOIN posts ON posts.user_id = users.id
    GROUP BY users.id
    HAVING COUNT(posts.id) > 10
  SQL

  users.first.posts_count
  # => 17
jghnyesterday at 4:15 PM

To make matters worse, most of the time I've successfully argued a project to just use SQL instead of an ORM, what has happened is that people over time built a home rolled ORM in the development language.

It's like people can't just let go.

show 1 reply
zadikianyesterday at 4:35 PM

And then the 100 lines of JS/Py ends up being way slower than the manual SQL, plus the autogen'd SQL part of it is slow, plus you can't even get the SQL query to profile without running the actual thing with prints.

show 1 reply
pjmlpyesterday at 4:19 PM

Worse, that code will be executed on the receiving end, and waste a bunch of network traffic.

nfw2yesterday at 4:15 PM

The reason given to use raw SQL is for the performance not the perceived code clarity.

show 2 replies
7bityesterday at 4:46 PM

Great anecdote. Doesn't validate your claim

show 1 reply