How can I disable hooks for a raw query in v6? #18013
Replies: 1 comment
|
In v6 there is no built-in The raw query path still runs the Sequelize instance query hooks. In the v6 branch, await this.runHooks('beforeQuery', options, query)
return await query.run(sql, bindParameters)
...
await this.runHooks('afterQuery', options, query)There is no The cleanest way is to make the hook opt out based on an option you pass to that one query: sequelize.addHook('beforeQuery', (options, query) => {
if (options.skipTenantHook) return
// existing hook logic
})
await sequelize.query(
"SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname LIKE 'tenant_%';",
{
raw: true,
skipTenantHook: true,
}
)If you are using TypeScript, that custom option may need a local cast/module augmentation because Sequelize does not know about I would avoid temporarily removing/re-adding the hook around the query unless this is strictly single-threaded startup code. With concurrent requests, removing the hook globally can affect other queries running at the same time. So the practical answer is: keep the same connection, pass a custom flag in the query options, and have the offending |
Uh oh!
There was an error while loading. Please reload this page.
I have a query like so:
But I'm struggling to understand how I would be able to disable hooks (there's an offending beforeQuery hook) for this single query without creating a new connection....
All reactions