1

我正在使用带有 Helenus 的 Node.js 连接到 Cassandra DB。

我有一个查询: 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 向我返回 score 的实际值而不是它似乎返回的任何值,我缺少什么?

4

2 回答 2

2

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

这是一些很好的代码来注销选择的结果:

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上阅读更多内容。请参阅底部关于行对象的内容。

于 2012-12-04T01:46:09.663 回答
2
results.forEach(function(row){
  var score = row.get('score').value;
  console.log(score); //will give you 10
});
于 2012-12-27T17:10:57.830 回答