Filter Records From Tables in Sequelize

Sequelize·2 min read·Jan 1, 2025

In Sequelize, the Op object provides a list of built-in operators, such as Op.eq for =, Op.and for AND, Op.between for BETWEEN ... AND ..., etc:

const { Op } = require('sequelize');

To filter records based on conditions, you can use the where property combined with a built-in operator of the Op object:

{  where: {    <attribute>: {      [Op.<operator>]: <value>    }  }}

Where:

  • attribute is the name of the column you want to perform a comparison of (e.g., first_name).
  • operator is a built-in operator (e.g., eq).
  • value is the value you want to compare the specified column to (e.g., 3).

Retrieve records in a list