What if you could break free from framework limits and write exactly the database commands you want?
Why Raw queries when needed in Express? - Purpose & Use Cases
Imagine you have a complex database task that your usual tools can't handle easily, like a very specific search or a custom report.
You try to build it using only the built-in helpers of your framework, but it feels like forcing a square peg into a round hole.
Using only high-level helpers can be slow and limiting.
You might end up writing lots of code just to work around what the helpers don't support.
This makes your app harder to maintain and can cause bugs.
Raw queries let you write exactly the database commands you need.
This gives you full control and flexibility to handle special cases easily.
You can still use your framework but step outside it when necessary.
Model.findAll({ where: { name: { [Op.like]: '%John%' } } })sequelize.query('SELECT * FROM users WHERE name LIKE :search', { replacements: { search: '%John%' }, type: sequelize.QueryTypes.SELECT })
You can solve tricky database problems without waiting for framework updates or hacks.
When you need a report that joins many tables with custom filters and grouping, raw queries let you write the exact SQL to get the data fast and correctly.
High-level helpers are great but sometimes limiting.
Raw queries give you full control over database commands.
Use raw queries to solve complex or special cases easily.