首页 > 解决方案 > Sequalize js如何使用OR操作制作多个类似的条件

问题描述

我有一组单词,我想用这些单词在数据库中搜索Sequalize ['orange', 'apple', 'apricot']

我怎样才能实现这样的查询

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

Sequalize

标签: javascriptsqlsequelize.js

解决方案


像这样的东西:

const { Op } = require('Sequelize')

...

TableModel.findAll({
  where: {
    [Op.or]: [{
      text: {
        [Op.iLike]: '%orange%'
      }
    }, {
      text: {
        [Op.iLike]: '%apple%'
      }
    }, {
      text: {
        [Op.iLike]: '%apricot%'
      }
    }]
  }
})

推荐阅读