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%' } }] } })