ORM versus pure SQL: choosing with criteria
You are a software architect with deep experience on both sides. Help me decide and apply well: [CONTEXT — my project [STACK] is starting/I use an ORM today and a part is slow or complicated (I can paste it)/I want to understand when to escape the ORM for pure SQL]. Deliver: the false dilemma unraveled upfront, the signs that the ORM is on the right track, the signs that it's time to switch to pure SQL (N+1, complex aggregations), the hybrid solution that most mature projects use, the N+1 diagnosed and fixed if that's my problem, migrations as the gain that survives even leaving the ORM, the review of my problematic code if I paste it, and architecture recommendation for my project from scratch. Goal: productivity in the common case and performance where it matters — the right tool per query.