Cassandra客户端不会插入

我不确定为什么这不起作用。 我的表很简单(我甚至​​改变了一切varchar的暂时),我可以INSERT,如果我使用cqlsh。

var Connection = require('cassandra-client').Connection; var db = new Connection({host: 'cassbx01.qualcomm.com', port: 9160, keyspace: 'foursq'}); db.execute("INSERT INTO checkins (fqid, name, address, city, state, zip, country, lat, lng, hereNow) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [value.id, value.name, value.location.address, value.location.city, value.location.state, value.location.postalCode, value.location.country, value.location.lat, value.location.lng, value.hereNow.count], function (err) { if (err || !saved) { throw err; } }); 

我运行时出现以下错误:

  self.client.execute_cql_query(cql, ttypes.Compression.NONE, function(err, ^ TypeError: Cannot call method 'execute_cql_query' of null at Connection.execute (/usr2/lsacco/nodejs/foursq-poc/node_modules/cassandra-client/lib/driver.js:407:17) at exports.poller (/usr2/lsacco/nodejs/foursq-poc/controller/api.js:80:29) at Array.forEach (native) at Function._.each._.forEach (/usr2/lsacco/nodejs/foursq-poc/node_modules/underscore/underscore.js:76:11) at IncomingMessage.exports.poller (/usr2/lsacco/nodejs/foursq-poc/controller/api.js:77:19) at IncomingMessage.EventEmitter.emit (events.js:115:20) at IncomingMessage._emitEnd (http.js:366:10) at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23) at CleartextStream.socketOnData [as ondata] (http.js:1366:20) at CleartextStream.CryptoStream._push (tls.js:495:27) 

您需要启动与connect函数的连接,然后才能在callback中执行CQL。

一个简单的例子看起来像这样:

 var Connection = require('cassandra-client').Connection; var db = new Connection({host: '127.0.0.1', port: 9160, keyspace: 'foursq'}); db.connect(function(err) { if (err) { throw err; } else { db.execute('INSERT INTO people (key, name) VALUES (?, ?)', ['key1', 'paul'], function (err) { if (err) { throw err; } else { console.log('success!'); } }); } });