Hey folks! I'm curious about the usage of raw SQL versus ORMs among developers. My current tech stack consists of Svelte SPA with Node/Express and Knex.js, primarily using Better-sqlite3 for MVPs. I've found that I don't enjoy the conventions of Knex.js or any other query builders, so I lean towards using raw SQL while being mindful of security by using binding techniques to avoid SQL injection. I'm also handling credentials with sessions and cookies, and using Axios for the client API instead of JWT. What about the rest of you? How do you approach database interactions?
5 Answers
It really depends on the situation. For code that's sensitive to latency and requires handling lots of data, I often go for raw SQL to utilize specific Postgres features that ORMs might not support. For routine backend tasks, though, I default to using an ORM for its safety and consistency.
I totally vibe with using raw SQL. While I also work with ORMs like Dapper, nothing beats the straightforwardness and control of writing raw queries, especially for performance-driven tasks. Using stored procedures along with this approach works wonders too!
Dapper + stored procedures is a solid combo; they allow for performance optimizations that can be handled independently from your application code.
Exactly! Keeping things strongly typed is a bonus!
I think it really comes down to the project needs. If I’m doing something like bulk updates or complex queries, I go with raw SQL since it enables better performance. But for simpler CRUD operations, ORMs are my go-to for convenience.
Absolutely! When I was managing billions of records, raw SQL was the only way to go.
Same here! For complex queries or heavy data lifts, raw SQL is unbeatable.
I find a balance between the two. I typically use an ORM for basic queries, but for more specific or complex needs, I don't hesitate to pull in some raw SQL. It’s all about knowing what tool fits the job best.
Right? Having both in your toolkit really expands what you can achieve.
It's all about contextual usage! Use what's best suited for the task at hand.
I personally prefer ORMs for the type safety they offer, especially with frameworks like Laravel. They make it almost second nature to use them; however, when I work with TypeScript, I sometimes switch to something like Drizzle for that added safety and SQL-like syntax.
Eloquent really is pretty robust, can't argue with that!
Check out Convex! It's a nice blend for backend and frontend that's getting some attention.

You can actually achieve `CROSS JOIN LATERAL` with Knex by just using a raw join, so it's not completely off the table!