Categories
JavaScript Answers

How to make Sequelize OR query with Node.js?

Spread the love

To make Sequelize OR query with Node.js, we call findAll with an object with the where property.

For instance, we write

Post.findAll({
  where: {
    authorId: {
      [Op.or]: [12, 13],
    },
  },
});

to call findAll with an object to query the Post items with authorId equal to 12 or 13, which is

SELECT * FROM post WHERE authorId = 12 OR authorId = 13;

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *