gpt4 book ai didi

node.js - sequelize 动态查询参数

转载 作者:搜寻专家 更新时间:2023-10-31 23:38:32 26 4
gpt4 key购买 nike

我在 req.query.p 中从我的前端 MVC 框架发送查询参数作为 JSON 格式,关键是这可能是一个动态键和值,例如:

req.query.p = {nombre : 'juan'}

req.query.p = {pais : 'chile'}

所以我需要键和值将它们放在 where 语句中,就像这样

exports.select = function(req, res){
console.log('=> GET | Obtener peliculas'.bold.get);
db.Pelicula
.findAndCountAll({
limit : req.query.limit,
offset : req.query.offset,
where : req.query.p ? [req.query.p.KEY + " = ?", req.query.p.VAL] : null
})
.success(function(resp){
console.log(JSON.stringify(resp.rows, null, 4).bold.get);
res.json({peliculas : resp.rows, meta : { total : resp.count}});
});
}

最佳答案

where参数可以是一个对象,所以你可以只传递where: req.query.p

关于node.js - sequelize 动态查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26106165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com