快速路由卡桑德拉批处理查询



我有一个 NodeJs/Express 服务器,我需要在其中使用更新、删除和插入路由 Cassandra 批处理查询。

我尝试使用所有方法,但它不起作用。如何使此 API 正常工作?

我正在使用卡桑德拉驱动程序 http://datastax.github.io/nodejs-driver/features/batch/

这是我的路由:

router.all('/:help_id',function(req,res){
const help_id = req.params.help_id;
const question = req.body.question;
const answer = req.body.answer;
const topic = req.body.topic;
const help_order = req.body.help_order;
if(!!help_id && !!question){
const query1 = "UPDATE helps SET question=?, answer=?, topic=?, help_order=? WHERE help_id=?";
const query2 = "DELETE FROM topics WHERE topic=? AND help_order=? AND help_id=?";
const query3 = "INSERT INTO topics(topic,help_order,help_id,question,answer) VALUES (?,?,?,?,?)";
const queries = [
{ query: query1, params: [question,answer,topic,help_order,help_id] },
{ query: query2, params: [topic,help_order,help_id] },
{ query: query3, params: [topic,help_order,help_id,question,answer] }
];
client.batch(queries,{ prepare: true },function(err){
if(!!err){
res.status(404).send({message: 'No help to update found.'});
} else {
const data = [];
data["error"] = 0;
data["Help"] = "Help was updated.";
res.json(data);
}
});
}
});

router.post 似乎适用于更新,删除和插入。

最新更新