如何使用prepare读取结果值

时间:2018-12-09 05:10:39

标签: cassandra

我正在查询pepare设置为true的卡桑德拉

client.execute(query, [date], { prepare: true })
        .then((result) => {console.log('Row updated on the cluster');
    });

在这里,我得到了带有参数类型的结果,以及从中得到的值;

假设我得到了这样的东西

{ date: LocalDate: 2018-12-08, calls: Long: 11 }

此类型作为对象出现,但是我无法将其作为对象读取,并且我不想使用regex或split()来读取它。有没有一种方法可以直接读取它,例如:-11和2018-12-08没有数据类型,我将cassandra-driver用于节点js。

2 个答案:

答案 0 :(得分:1)

您会收到一组可以照常访问的JavaScript对象,并带有点标记。这是基于documentation和您的代码的示例:

client.execute(query, [date], { prepare: true })
        .then((result) => {
           var data = result.first();
           console.log('Row updated on the cluster: date=%s calls=%s', data.date, date.calls);
    });

答案 1 :(得分:0)

我对此有一个答案

client.execute(query, [ date ], { prepare: true })
  .then(result => {
    result.rows.forEach(row => console.log(row["calls"].toString()));
  });