gpt4 book ai didi

node.js - 错误 : where: "raw query" has been removed, 请使用 where ["raw query", [replacements]]

转载 作者:搜寻专家 更新时间:2023-11-01 00:21:14 28 4
gpt4 key购买 nike

Unhandled rejection Error: where: "raw query" has been removed, please use where ["raw query", [replacements]]

我在渲染以下代码时遇到了这个错误。这是一个动态的 where 子句,由用户在 search 字段中输入的值生成:

var queryWhere = {id: {$ne: null}};
if (req.query) {
if (req.query.gender && req.query.gender !== '') {
searchGender = "gender = '" + req.query.gender + "'";
} else if (req.query.gender && req.query.gender === '') {
searchGender = "gender IS NOT NULL ";
}
if (req.query.experience && req.query.experience !== '') {
searchExperience = "experience = '" + req.query.experience + "'";
} else if (req.query.gender && req.query.experience === '') {
searchExperience = "experience IS NOT NULL ";
}
queryWhere = {
$and: [
{$or: [
searchGender,
searchExperience]}
]
};

models.Users.findAll({
offset: numPerPage * 50,
limit: 50,
where: queryWhere,
include: [
{model: models.Users_Answers}
],
order: [
[models.Sequelize.col('id'), 'ASC'],
[models.Users_Answers, 'id', 'ASC']
]
}).then(function(answers) {
res.render('answers', {answers: answers, search: req.query.searchParam, moment: moment, pagesize: (numPerPage+1), total: totalCount / 50});
});
} else {
res.render('answers');
}

我该如何解决?

最佳答案

原始查询应该是数组

queryWhere = {
$and: [
{$or: [
[searchGender],
[searchExperience]]}
]
};

关于node.js - 错误 : where: "raw query" has been removed, 请使用 where ["raw query", [replacements]],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44297624/

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