Reputation: 159
I am using Node.js with Helenus to connect to a Cassandra DB.
I have a query: SELECT score FROM team_scores WHERE team_name = 'foo'
When run from cqlsh, I get results that look like this:
score
-------
10
I then move the query over to Node and Helenus using cqlVersion 3.0.0. When I run this code:
pool.cql("SELECT score FROM team_scores WHERE team_name = 'foo'", function(err, results){
console.log(results);
});
The console reports:
[ <Row: Key: 'foo', ColumnCount: 1, Columns: [ 'score' ]> ]
What am I missing to get Helenus to return me the actual value of score rather than whatever it seems to be returning?
Upvotes: 1
Views: 711
Reputation: 87
results.forEach(function(row){
var score = row.get('score').value;
console.log(score); //will give you 10
});
Upvotes: 2
Reputation: 243
results is actually a list of row objects. You are probably seeing the result of a toString implementation.
Here is some good code to log out the results of a select:
results.forEach(function(row){
//all row of result
row.forEach(function(name,value,ts,ttl){
//all column of row
console.log(name,value,ts,ttl);
});
});
you can read more at the helenus github. See the stuff on the bottom about the row object.
Upvotes: 2