In MySQL, I can do:
SELECT * FROM some_table WHERE MOD(attr, 2) = 0;
it gives me all rows which attr
is even.
How can I do it in Sequelize? I didn’t find in the docs.
Something like:
MyModel.findAll({
where: {
attr: {
[Op.mod]: [2, 0]
}
}
})
2
Answers
Use
literal
(https://sequelize.org/docs/v6/other-topics/sub-queries/) if you need full flexibility:Otherwise you can just call the desired function using
fn
(https://sequelize.org/docs/v6/core-concepts/model-querying-basics/#advanced-queries-with-functions-not-just-columns):Why not
sequelize.fn()
? The "core concepts" docs illustrate almost exactly what you’re trying to do: