TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Why hasn't anyone invented a converter for ORM/raw SQL?

2 pointsby jlei523almost 3 years ago
Take Prisma. Very useful to autocomplete tables and column names. Catches mistakes early.<p>But my workflow generally goes like this: Write raw SQL in TablePlus to see what data comes back, then translate this raw SQL query into a Prisma query.<p>Why not have a converter convert raw sql queries into Prisma queries?<p>Another use case is as soon as any of my SQL queries get complicated (20+ lines), raw SQL becomes much easier to write. It&#x27;d be nice to automatically translate this to a Prisma query.

2 comments

russellbeattiealmost 3 years ago
There&#x27;s always an impedence mismatch for anything but the simplest data structures. It&#x27;s SQL 101. Try it a few times and you&#x27;ll see what a pain in the ass it is - there&#x27;s always tradeoffs. Remember, the objects need to write data as well as read it. If your SQL Query is especially complex, reversing the joins to update individual tables can be a nightmare.<p><a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Object%E2%80%93relational_impedance_mismatch" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Object%E2%80%93relational_im...</a>
techdragonalmost 3 years ago
Because ORMs exist to <i>avoid</i> writing the SQL. The workflow is ORM first, then if it’s not good enough, optimise, then if that’s not enough, drop down to raw SQL. If your just writing the SQL then you kinda don’t need it. Most ORMs have a mechanism to pass on a raw SQL query and serialise the results into the appropriate objects&#x2F;structs.