最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何在Sequelize中使用and运算符

IT培训 admin 11浏览 0评论

如何在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%'}
    } 
})

如何在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. 暂无评论