Repository navigation
feat: rewrite the part of QueryGenerator responsible for WHERE - #15598
Conversation
|
With the partial implementation of #14299, we now have a lot of new top-level functions: old:
new:
Some of them, like They can be accessed through Maybe we should make all of them properties of the sql`SELECT * FROM ${sql.identifier('users')} WHERE ${sql.where({ id: 5 })}` |
|
Yes, I think properties of the |
|
This should fix #5409 too thanks to the new (not actually new, just extended to every attributes) casting syntax: Project.destroy({
where: {
'myJsonColumn::text': '{}',
},
});Also #13828: await Foo.count({
where: {
'myUuidColumn::text': { [Op.iLike]: '573b77ae%' },
},
});Something else I'm really happy about in the new implementation: Validation is cast aware ✨✨: User.findAll({
where: {
// This makes Sequelize throw an error "12345678% is not a valid UUID"
myUuid: '12345678%',
},
});
// VS
User.findAll({
where: {
// With the cast, the DataType validator changes to DataTypes.TEXT and the query goes through just fine
'myUuid::text': '12345678%',
},
}); |
- make json path parsing use lodash's get syntax - fix where mapping - fix ON ambiguity
|
Breaking change documentation PR: sequelize/website#417 |
WikiRik
left a comment
There was a problem hiding this comment.
Initial review of tests, including notes to myself on some tests. I still need to go through the integration test files json.test.js, json.test.ts and model/json.test.js since there's also a lot changed there
WikiRik
left a comment
There was a problem hiding this comment.
Now I've gone through the updated code, looks very good. Don't understand all of it though, parts of the new whereSqlBuilder and the BNF parser are very like magic.
Now only those JSON integration tests to go and then slowly resolving my comments before we can start unleashing this to the rest of the alpha users
Co-authored-by: Rik Smale <[email protected]>
Pull Request Checklist
Description Of Change
This PR is a reimplementation of #14020 against the modernized codebase. Hopefully now I'll be able to fix my very first bug report!
Closes #13602
Closes #13753
Closes #13773
Closes #15238
Closes #4494
Closes #13011
Closes #14099
Closes #5409
Closes #10599
Closes #13828
Closes #14066
Closes #10832
Closes #15237 (comment)
Sequelize.where()and pojo where objects (i.e.where: { firstName: 'zoé' }).{ attribute: value }syntax. See thewhere.test.tsto view the list of fixed bugsOp.startsWith,Op.endsWith,Op.substringand their inverse support dynamic values & bind parameters.Sequelize.attr#13773. That feature is used in the new implementationsql.attributeinstead ofattr, but we can change it if you want. If we do, we'll want to consider namingsql.identifier->sql.ident(but it's a bit too close to indent to my liking).fn(),cast(),col(), etc… to be used inliteral()#14299. Everything has been added except forunsafeReplacement(). We'll see if it is even needed.sqltag (e.g.sql.attribute)whereobject should throw with a message describing what is invalid, instead of crashing with an obscure message.where()supports any value for both operands:Sequelize.where([], Op.eq, [])is validCommit message body
Empty first line is important!
Deprecations
Op.colis deprecated. Usesql.col(),sql.identifier()orsql.attribute()json()is deprecated. Usesql.where(),sql.attribute()orsql.jsonPath()Future PRs
{ attribute: { [Op.in]: new Set([1,2,3]) } })Op.startsWith& friends usingsubstringinstead oflikefor performance & to remove the possibility to inject characters with special meaning$containsoperator with JSONB array field #5173IncludeOptions.on#14114