Hello Friends,
Welcome To Infinitbility!
This article based on sequelize where in and where not in query, here you will learn to write where in query in sequelize and also how many way to do.
For managing where in and not in types of query sequelize provide operators.
Let start today article Sequelize where in and where not in array example
In this article, you will get examples of query using where in or where not in array.
Sequelize where in array
First Option: You have to just set array in where clause, Sequelize auto understand where in query like below.
const { Op } = require("sequelize");
Post.findAll({
where: {
id: [1,2,3,4]
}
});
Second Option: Sequelize also provide Op.in
operator to create where in query like below.
const { Op } = require("sequelize");
Post.findAll({
where: {
id: {[Op.in]: [1,2,3,4]}
}
});
Sequelize where not in array
Sequelize provide Op.notin
operator to make where not in query like below example.
const { Op } = require("sequelize");
Post.findAll({
where: {
id: {[Op.notin]: [1,2,3,4]}
}
});
Thanks for reading…