-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Support specifying the type of a bind param / replacement #14410
Copy link
Copy link
Open
Description
Issue Creation Checklist
- I have read the contribution guidelines
Feature Description
Is your feature request related to a problem? Please describe.
Right now, Sequelize automatically determines the type of bind params & replacements based on their JS type. But a JS type can be mapped to more than one SQL type.
It guesses these types in https://github.com/sequelize/sequelize/blob/main/src/sql-string.js
This leads to things like:
// "permissions" and ":permissions" are both SQL arrays.
sequelize.query('SELECT * FROM users WHERE permissions @> :permissions', {
replacements: {
permissions: ['read', 'write']
},
});generating
SELECT * FROM users WHERE permissions @> 'read', 'write';instead of
SELECT * FROM users WHERE permissions @> ARRAY['read', 'write'];Describe the solution you'd like
It should be possible to specify the DataType of a given replacement or bind parameter.
// "permissions" and ":permissions" are both SQL arrays.
sequelize.query('SELECT * FROM users WHERE permissions @> :permissions', {
parameterTypes: {
permissions: DataTypes.ARRAY(DataTypes.STRING),
},
replacements: {
permissions: ['read', 'write']
},
});Why should this be in Sequelize
To continue making raw queries first class citizen.
Describe alternatives/workarounds you've considered
Use replacementTypes and bindTypes instead of parameterTypes.
Other ideas to solve this feature welcome.
Is this feature dialect-specific?
- No. This feature is relevant to Sequelize as a whole.
Would you be willing to implement this feature by submitting a Pull Request?
- Eventually, at some point.
Reactions are currently unavailable