我试图创建一个简单的js应用程序来查询这样的cassandra数据库:
var express = require('express');
var cassandra = require('cassandra-driver')
var app = express();
var client = new cassandra.Client({contactPoints: ['127.0.0.1'], keyspace: 'custprd'});
app.get('/', function (req, res) {
res.send('Hello Ronak!');
});
app.get('/customer/:ent_cust_id', function (req, res, next) {
var query = 'Select * from entcustinfo where ent_cust_id = ?';
consolelog('Select * from entcustinfo where ent_cust_id = ?');
client.execute(query, [req.params.ent_cust_id], function (err, result) {
if (err) return next (err);
var row = result.rows[0];
//Response
res.json({ent_cust_id: req.params.ent_cust_id, name: row.get('offers')});
});
});
var server = app.listen(3030, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
现在,当我在网络浏览器中输入呼叫http://10.205.116.141:3030/customer/1013686356
时,我得到了回复:
Error: Expected 4 or 0 byte int (10)
并且控制台日志显示:
Select * from entcustinfo where ent_cust_id = ?
我认为?
是传递网址结束点的方法吗?
编辑:
我认为这与execute vs executeAsPrepared有关...我使用executeAsPrepare,我收到此错误:
TypeError: undefined is not a function
答案 0 :(得分:0)
所以我的工作方式如下:
app.get('/customer/:ent_cust_id', function (req, res, next) {
var query = 'Select * from entcustinfo where ent_cust_id = ?' [req.params.ent_cust_id];
consolelog('Select * from entcustinfo where ent_cust_id = ?');
client.execute(query, function (err, result) {
if (err) return next (err);
var row = result.rows[0];
//Response
res.json({ent_cust_id: req.params.ent_cust_id, name: row.get('offers')});
});
});
我已将[req.params.ent_cust_id]
移至var query