2017-08-05 7 views
0

私はUpdate、Delete、InsertでCassandraバッチクエリをルーティングする必要がある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); 
     } 
    }); 
    } 
}); 
+0

副作用として、バッチを最適化として使用することは、cassandraの反パターンであり、書き込みを行うよりも2倍以上のコストがかかります。アトミック(分離なし)プロパティで必要な場合を除き、それらを使用しないことをお勧めします。 –

答えて

0

router.postは、更新のために働く削除と挿入するように思えます。

関連する問題