使用$like
代替[Op.like],需要设置运算符别名:
const Op = Sequelize.Op;
const operatorsAliases = {
$like: Op.like
}
const sequelize= new Sequelize(db, user, pass, { operatorsAliases })
代码中就可以使用$like运算符:
const getArticleList = async (ctx) => {
let { title } = ctx.query,
titleFilter = title ? { title: { $like: `%${title}%` } } : {}
...
await Article.findAndCountAll({
where: titleFilter,
include: [
...
],
...
})
...
}