最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在Sequelize中使用and运算符

网站源码admin17浏览0评论

如何在Sequelize中使用and运算符

如何在Sequelize中使用and运算符

我有以下查询:

const records = await Product.findAll({ 
    where: { 
        name: { 
            [Op.like]: '%iphone%' 
        } 
        Op.and( category {[Op.like]: '%phone%'})
    }
})

如果我只有它,那就很好用了。

const records = await Product.findAll({ 
    where: { 
        name: { 
            [Op.like]: '%iphone%' 
        } 
    } 
})

如何获得查询的行为类似于

SELECT * FROM Product WHERE name LIKE '%iphone%' AND 'category LIKE '%phone%'

我一直收到语法错误,有人可以帮我解决此错误。在此先感谢

回答如下:

您缺少一些逗号。 WHERE clause documentation

const records = await Product.findAll({ 
    where: { 
        name: { [Op.like]: '%iphone%' },
        category: {[Op.like]: '%phone%'}
    } 
})
发布评论

评论列表(0)

  1. 暂无评论