-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue description
BeforeQuery promises are not awaited before query execution
Expected Behavior
When using a Subscriber, beforeQuery promises should be awaited and executed before the actual query.
Actual Behavior
beforeQuery and afterQuery promises are all executed after the query
Steps to reproduce
Enable requests logs, create a Subscriber with an async beforeQuery, and it will be run after the query.
My Environment
| Dependency | Version |
|---|---|
| Operating System | Ubuntu 24.04 / Containers with node:18.20.4-alpine3.20 |
| Node.js version | 18.20.4 |
| Typescript version | 5.0.4 |
| TypeORM version | 0.3.20 |
Additional Context
It seems that it is due to the fact that await broadcasterResult.wait() is only called after the query execution in the finally statement. Is there a reason behind this technical choice ?
The beforeQuery and afterQuery where implemented after this issue, maybe it was only intended for logging purposes ?
Context: i am trying to implement RLS on our project, and i would like to use subscribers to set the current tenant_id before executing some queries on tables with RLS enabled.
Since there is no beforeLoad event (it was proposed in this issue but it was closed), i wanted to try to use the beforeQuery method
Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
Yes, I have the time, and I know how to start.