Hey everyone! I'm developing a web application and considering how best to manage my database interactions. My plan is to use an ORM like TypeORM, Prisma, or Sequelize for basic CRUD operations, while resorting to raw SQL for more complex queries or performance-sensitive situations. I'm curious to know if this mixed strategy is practical. Does anyone have experience with it? Does this method improve maintainability and productivity? Are there any pitfalls I should watch out for when combining ORM and raw SQL? I'd appreciate input, especially from folks who have worked on medium to large-scale projects with teams.
9 Answers
I've been in situations where I've had to ditch ORMs entirely. For smaller applications with a handful of tables and simple joins, using an ORM can be okay. But personally, I've witnessed some pretty messy situations over the years once projects start to scale up.
I'm with you on that. SQL is so powerful and straightforward. Just remember, writing SQL is different from procedural coding—focus on what you want, not how to get it done.
It's super common to mix the two. ORMs often struggle with complex queries, making raw SQL necessary. Just make sure your transaction management is well thought out.
I've seen apps go this route too. Custom queries are part of reality, just be cautious with migrations affecting your handcrafted SQL.
In my experience, ORMs don't really provide a win over raw SQL. I once worked with an ORM, and as the project progressed, we had to bend it to our needs so much that it became a hassle. Eventually, we ditched it.
No issues on my end mixing ORM and SQL. I've often found times where ORMs slowed down queries because they tried to handle too many relationships, so replacing it with a hand-written SQL view worked wonders for performance.
If you're going the ORM route, mixing it up is just fine. But do keep in mind that ORMs introduce a lot of complexity. If all they help with is simple CRUD, the balance may not be worth it.
Mixing formats can be a practical solution! I often whip up something quick with an ORM, but as the project scales, I migrate to a more straightforward architecture.
Absolutely doable! Just ensure that your custom SQL queries are well-typed and tested with your actual database in integration tests as your application evolves.
Sometimes, especially when using extensions like Postgres, mixing is unavoidable. I suggest using DAOs with your ORM and keeping raw SQL for queries that don't have ORM alternatives.

Totally understand. For anything complex, raw SQL tends to win out, plus having developers who know their databases helps a lot.