sequelize / sequelize/sequelize
Add the ability to modify the SQL in `beforeQuery`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Feature Description
Describe the feature you'd like to see implemented
Currently, sequelize.query creates a Query object, then calls beforeQuery with it, and only after that does it give the SQL to the Query object.
That means the SQL string & bind parameters are not available in beforeQuery
I think we should change that method to something like this:
const query = new this.dialect.Query({ sql, connection, sequelize: this, options, bindParameters });
await this.hooks.runAsync('beforeQuery', options, query);
checkTransaction();
return await query.run();
Not 100% about the signature. We need to prepare for the eventual addition of prepared statements, which would impact this API
Describe why you would like this feature to be added to Sequelize
Here is such a use-case https://github.com/sequelize/sequelize/discussions/15382
Is this feature dialect-specific?
- No. This feature is relevant to Sequelize as a whole.
- Yes. This feature only applies to the following dialect(s):
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.
Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read src/sequelize.js around lines 709-712 and trace how sequelize.query creates the Query object before assigning SQL and bind parameters. Clarify the beforeQuery hook contract, including its signature and future prepared-statement concerns; done means the hook can access the SQL and bind parameters before query execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, sql, typescript
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100