Home / Learn Secure SQL / ORMs Have a Raw-Query Escape Hatch, and It Needs the Same Care
ORMs Have a Raw-Query Escape Hatch, and It Needs the Same Care
The "raw()" or "executeRaw()" method in your ORM is not a different language.
Theory in plain words
What it is
Nearly every ORM offers an escape hatch for writing raw SQL directly, for cases the ORM's normal API cannot express conveniently. That escape hatch is plain SQL, with all the same rules.
Why it matters
Developers sometimes assume an ORM's raw query method is "inside the safe ORM", and skip the care they would apply to a manually written query elsewhere; the method name does not change the underlying mechanics.
Mechanically speaking
Use the raw method's own parameter-passing option (every major ORM has one) instead of building the SQL string with f-strings, string concatenation, or template literals.
Shows up in
- Web application code review
- Backend development
- Database administration
The "ORMs and query builders" part of this course later shows the exact safe raw-query syntax for Django, SQLAlchemy, Sequelize, Prisma, and others, each with a runnable example.
Check yourself
1. An ORM's "raw SQL" escape hatch...
Same rules apply inside it.