Skip to content
Advertisement

Sequalize js how to make multiple like condition with OR operation

I have an array of words which I want to search into a database with Sequalize ['orange', 'apple', 'apricot']

How can I achieve a query like this

SELECT * FROM Table WHERE text LIKE '%orange%' OR text LIKE '%apple%' OR text LIKE '%apricot%'

with Sequalize ?

Advertisement

Answer

Something like this:

const { Op } = require('Sequelize')

...

TableModel.findAll({
  where: {
    [Op.or]: [{
      text: {
        [Op.iLike]: '%orange%'
      }
    }, {
      text: {
        [Op.iLike]: '%apple%'
      }
    }, {
      text: {
        [Op.iLike]: '%apricot%'
      }
    }]
  }
})
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement