javascript - Sequalize js如何使用OR操作制作多个类似的条件
问题描述
我有一组单词,我想用这些单词在数据库中搜索Sequalize
['orange', 'apple', 'apricot']
我怎样才能实现这样的查询
SELECT * FROM Table WHERE text LIKE '%orange%' OR text LIKE '%apple%' OR text LIKE '%apricot%'
与Sequalize
?
解决方案
像这样的东西:
const { Op } = require('Sequelize')
...
TableModel.findAll({
where: {
[Op.or]: [{
text: {
[Op.iLike]: '%orange%'
}
}, {
text: {
[Op.iLike]: '%apple%'
}
}, {
text: {
[Op.iLike]: '%apricot%'
}
}]
}
})
推荐阅读
- dart - 如何将回调传递给另一个 StatefulWidget?
- c - 遇到 srand 错误,想知道是否有其他方法可以改进此代码
- powershell - 为什么我的 powershell Base64 字符串被截断为 36 个字符?
- javascript - 排序 Dropzone.js
- sql - Update statement taking more than 24 hours for updating 32k rows
- java - 客户端-服务器模式下的 InputStreamReader 和 OutputStreamWriter
- matlab - 导入带有空格和制表符分隔符的 matlab
- java - 配置spring boot嵌入式tomcat——更新setenv文件
- elixir - 将列表拆分为 N 个部分
- qt - 如何在 QML 中创建在线/离线地图?