【发布时间】:2018-07-06 00:39:05
【问题描述】:
我正在设置一个 API。服务器从客户端接收一个 JSON 格式的过滤器,供 sequelize 在查询 MySQL 数据库时使用。
我一直在用 postman 测试。
下面的json,可以发送到服务器,但是sequelize不喜欢"[Op.or]",因为应该是[Op.or]不带引号。
但是,如果我不添加引号,那么它不是有效的 JSON,我无法发布数据。
//Sequelize does not like this because of the quotes around "[Op.or]"
{
"filters": {"week": 201740, "project": 8, "itemgroup": {"[Op.or]": ["group1", "group2"]}}
}
//This is can not be sent as a JSON body in an API request because there are
//no quotes around [Op.or]
{
"filters": {"week": 201740, "project": 8, "itemgroup": {[Op.or]: ["group1", "group2"]}}
}
这是我的脚本文件,其中进行了 sequelize 调用。JSON 过滤器通过函数头中的过滤器变量传入。
module.exports = {
getAOLDataCount: function (res, filters) {
let result = '';
wd = new WeeklyData(sequelize, Sequelize.DataTypes);
wd.count({where: filters}).then(function (aolCount) {
res.send('the value ' + aolCount);
});
return result;
}
};
【问题讨论】:
标签: json node.js api sequelize.js