如何让Helenus返回CQL查询的实际值?

时间:2012-12-04 00:26:29

标签: node.js cassandra cql helenus

我正在使用Node.js和Helenus连接到Cassandra数据库。

我有一个问题: SELECT score from team_scores WHERE team_name ='foo'

从cqlsh运行时,我得到的结果如下:

score
-------
10

然后我使用cqlVersion 3.0.0将查询移到Node和Helenus。当我运行此代码时:

pool.cql("SELECT score FROM team_scores WHERE team_name = 'foo'", function(err, results){
    console.log(results);
  });

控制台报告:

[ <Row: Key: 'foo', ColumnCount: 1, Columns: [ 'score' ]> ]

我错过了什么让Helenus给我的分数的实际价值而不是它似乎返回的东西?

2 个答案:

答案 0 :(得分:2)

结果实际上是一个行对象列表。您可能看到了toString实现的结果。

这是一些很好的代码,用于注销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);
  });

});

您可以在helenus github了解更多信息。查看底部关于行对象的内容。

答案 1 :(得分:2)

results.forEach(function(row){
  var score = row.get('score').value;
  console.log(score); //will give you 10
});