You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might contain a little mistake or two but it should be an okay starting-off point. If you search Google, you'll find some useful pointers on its usage.
this code loose field name in generated query. Like WHERE @? '$.** ? (@.tagName == "a" && (@.attr.href like_regex "^/[^/]") )'
working only crazy construction
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
Hello! Want to reopen this because lot of json postgresql operators absent in Sequelize. In particular it will be convinient to have some function to register own operators like '?' for searching in jsonb postgreslq arrays and do not use raw in business logic.
I think the best way to support custom operators is going to be by implementing #14299 & #14297. Once they are ready, a custom operator could be implemented like this:
import{sql}from'@sequelize/core';functiongreaterThan(left,right){// thanks to the sql tag, value will be escaped before inlining.returnsql`${left} >= ${right}`;}User.findAll({where: greaterThan(sql.attribute('friendCount'),10,),})
The alternative would be to support hooking into QueryGenerator, which would be incredibly complicated to do & to use. I don't think we want to do that.
Is it possible to achieve this using v6? sql in only available in v7, and migrating from v6 to v7 is like recoding our entire project.
This is a total no go.
Somewhat, but definitely not with the same ergonomics
The best we have in Sequelize 6 is a mix of literal and sequelize.escape, but there is no good alternative to sql.attribute, nor can you easily reference a column in literal
While digging, I found out other issues. E.g. sequelize is not able to build simple MySQL query like: WHERE NOT (a <=> 2)
NOT implementation probably can't handle right side.
Activity
Spekpannenkoek commentedon Feb 8, 2021
Don't know off the top of my head how to define a custom
Sequelize.Op, but you can drop down to raw SQL withliteral:Use placeholders if the queried value is dynamic:
This might contain a little mistake or two but it should be an okay starting-off point. If you search Google, you'll find some useful pointers on its usage.
TrurlMcByte commentedon Feb 9, 2021
this code loose field name in generated query. Like
WHERE @? '$.** ? (@.tagName == "a" && (@.attr.href like_regex "^/[^/]") )'working only crazy construction
but this way not compatible with jsonb subkeys and query includes ( just "body" in this case must be "some_table_alias"."body" )
github-actions commentedon Oct 27, 2021
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂
rusekr commentedon Aug 11, 2022
Hello! Want to reopen this because lot of json postgresql operators absent in Sequelize. In particular it will be convinient to have some function to register own operators like '?' for searching in jsonb postgreslq arrays and do not use raw in business logic.
ephys commentedon Sep 17, 2022
I think the best way to support custom operators is going to be by implementing #14299 & #14297. Once they are ready, a custom operator could be implemented like this:
The alternative would be to support hooking into QueryGenerator, which would be incredibly complicated to do & to use. I don't think we want to do that.
GuillaumeCisco commentedon Jun 29, 2023
Is it possible to achieve this using v6?
sqlin only available in v7, and migrating from v6 to v7 is like recoding our entire project.This is a total no go.
ephys commentedon Jun 29, 2023
Somewhat, but definitely not with the same ergonomics
The best we have in Sequelize 6 is a mix of
literalandsequelize.escape, but there is no good alternative tosql.attribute, nor can you easily reference a column inliteralBest I can come up with in Sequelize 6:
GuillaumeCisco commentedon Jun 29, 2023
But how do you work with others classic operators?
GuillaumeCisco commentedon Jun 29, 2023
Ok looks like it can be achieved by wrapping everything in an
Op.andoperator...GuillaumeCisco commentedon Jun 29, 2023
And by the way,
escapeis not present in v6...#13225
ephys commentedon Jun 29, 2023
It's
sequelize.escape, notqueryInterface.escapeGuillaumeCisco commentedon Jun 29, 2023
sequelize.escapedoes not exist either...ephys commentedon Jun 29, 2023
Woops, misclick from using github on mobile
sequelize.escape:
sequelize/src/sequelize.js
Line 704 in a3213f0
sequelize/src/sequelize.d.ts
Line 1301 in a3213f0
GuillaumeCisco commentedon Jun 30, 2023
GuillaumeCisco commentedon Jun 30, 2023
escapeworks on a sequelize instance, not on the sequelize packageephys commentedon Jun 30, 2023
escapeis an instance method, not a static onemysuf commentedon Oct 28, 2024
It looks like atleast in v6, it can be done also this way:
where(col('body'), "@?", "$.** ? (@.tagName == \"a\" && (@.attr.href like_regex \"^/[^/]\") )")While digging, I found out other issues. E.g. sequelize is not able to build simple MySQL query like:
WHERE NOT (a <=> 2)NOT implementation probably can't handle right side.