Reputation: 5454
I'm not really sure why this won't work. My table is simple (I even changed everything to varchar's for the time being) and I can INSERT if I use 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;
}
});
I get the following error when I run it:
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)
Upvotes: 1
Views: 1200
Reputation: 446
You need to initiate the connection with the connect
function before you can execute the CQL in the callback.
A simple example would look like this:
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!');
}
});
}
});
Upvotes: 2