我正在使用NodeJS Cassandra驱动程序从Cassandra timeuuid列中检索数据。现在将数据检索为缓冲区类型而不是字符串类型。我需要数据为字符串类型
答案 0 :(得分:2)
虽然您仍然很难理解您期望看到的内容,但这会以更易读的格式返回您的PostedDate
:
SELECT DateOf(PostedDate) FROM facehq.timeline;
此外,随着您的数据大小增加,未绑定的查询将变得有问题且速度变慢。因此,请确保尽可能使用WHERE子句限定此类查询。
我需要结果像" posteddate":" f6ca25d0-ffa4-11e4-830a-b395dbb548cd"。
听起来我的问题就在你的node.js代码中。你是如何执行查询的? Node.js driver documentation on the GitHub project page有一个可能有用的示例:
client.stream('SELECT time, val FROM temperature WHERE station_id=', ['abc'])
.on('readable', function () {
//readable is emitted as soon a row is received and parsed
var row;
while (row = this.read()) {
console.log('time %s and value %s', row.time, row.val);
}
})
.on('end', function () {
//stream ended, there aren't any more rows
})
.on('error', function (err) {
//Something went wrong: err is a response error from Cassandra
});
DataStax文档还有working with timeUUIDs的具体示例:
client.execute('SELECT id, timeid FROM sensor', function (err, result) {
assert.ifError(err);
console.log(result.rows[0].timeid instanceof TimeUuid); // true
console.log(result.rows[0].timeid instanceof Uuid); // true, it inherits from Uuid
console.log(result.rows[0].timeid.toString()); // <- xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
console.log(result.rows[0].timeid.getDate()); // <- Date stored in the identifier
});