[HN Gopher] Ask HN: ORM or Native SQL?
___________________________________________________________________
Ask HN: ORM or Native SQL?
Do you use ORM or native SQL, or both? which ORM are you using and
how did you choose it?
Author : sh_tomer
Score : 9 points
Date : 2023-01-06 21:37 UTC (1 hours ago)
| kevincox wrote:
| I started a project recently using no ORM and having the
| flexibility to easily merge queries and extract exactly the data
| I need is very helpful. Converting the rows to objects hasn't
| been a major concern and I have compile-time type checking
| against the database schema (for non-dynamically built queries).
|
| I'd say that the only real issue I have is building dynamic
| queries and some helpers for joins to make it easy to confirm
| that joins are against the right keys and tables. But that hasn't
| been much of an issue.
| themadsens wrote:
| My absolute most horrid work experiences have all involved
| Hibernate / JPA. It slows everything to a grinding crawl, works
| somewhat 99.9 % of the time and creates inexplicable un-
| debuggable errors for the remaining 0.1%
|
| On top of that you have to ditch referential integrity to make it
| at least limp along
|
| Give me plain SQL or something lowlevel like sql2o any day
| postalrat wrote:
| No ORM. Sucks having to learn a new ORM every project.
|
| Even worse when you need to do something in a new ORM one step
| more advance than the tutorials show you.
| NetOpWibby wrote:
| Off the top, ORM all the way. I don't like SQL syntax, it makes
| my head hurt. Boooo.
|
| I recently switched from RethinkDB to EdgeDB, and it uses SQL
| under the hood. I love it, it's awesome. I don't need raw SQL but
| I think EdgeDB allows you to write queries if you want.
| nextaccountic wrote:
| The best solution I've ever seen is this Rust library
| https://github.com/cornucopia-rs/cornucopia
|
| You write plain SQL for you schema (just a schema.sql is enough)
| and plain SQL functions for your queries. Then it generates Rust
| types and Rust functions from from that. If you don't use Rust,
| maybe there's a library like that for your favorite language.
|
| Optionally, pair it with https://github.com/bikeshedder/tusker or
| https://github.com/blainehansen/postgres_migrator (both are based
| off https://github.com/djrobstep/migra) to generate migrations by
| diffing your schema.sql files, and https://github.com/rust-
| db/refinery to perform those migrations.
|
| Now, if you have simple crud needs, you should probably use
| https://postgrest.org/en/stable/ and not an ORM. There are
| packages like https://www.npmjs.com/package/@supabase/postgrest-
| js (for JS / typescript) and probably for other languages too.
|
| If you insist on an ORM, the best of the bunch is prisma
| https://www.prisma.io/ - outside of the typescript/javascript
| ecosystem it has ports for some other languages (with varying
| degrees of completion), the one I know about is the Rust one
| https://prisma.brendonovich.dev/introduction
| Canada wrote:
| I strongly prefer SQL over any ORM.
___________________________________________________________________
(page generated 2023-01-06 23:01 UTC)