【问题标题】:Azure table storage continuation tokens in Node jsNode js 中的 Azure 表存储延续令牌
【发布时间】:2017-12-13 17:55:23
【问题描述】:

我正在尝试借助以下链接在 Azure 表存储中实现延续令牌, https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-nodejs

下面是我的代码,

var nextContinuationToken = null;
var query = new azure.TableQuery()
.select([req.query.DataToShow, 'Timestamp'])
.where('Timestamp ge datetime? and Timestamp lt datetime? and 
deviceId eq ?', from, to, deviceSelected);

tableSvc.queryEntities('outTable', query, nextContinuationToken, { 
payloadFormat: "application/json;odata=nometadata" }, function (error, 
result, response) {
if (!error) {
    while(!result.entries){//iterate
    if (result.continuationToken) {
        nextContinuationToken = result.continuationToken;
    }
    else
    {
       console.log("Data  is: " + dataArray.length);
      res.send(dataArray.reverse());
    }
    }
}
else{
}
});

谁能建议在 Nodejs 中实现的正确方法?

【问题讨论】:

  • 这段代码有错误吗?如果是这样,那么请编辑您的问题并将其包括在内。否则,不清楚您到底在寻找什么。
  • 嗨 Gaurav,在我的项目中运行此代码后,我没有得到数据。寻找解决方案,我是否按照设想的方式进行迭代?
  • 您根本没有在代码中进行迭代。您是要发送与查询匹配的所有数据还是要在收到一些数据后立即发送响应?
  • 嗨 Gaurav,我的表中有大约 5000 个条目。我想获取所有数据,然后将其发送给客户端。

标签: javascript node.js azure azure-table-storage


【解决方案1】:

试着把你的代码改成这样:

var dataArray = [];

fetchAllEntities(null, function () {
    res.send(dataArray.reverse());
});

function fetchAllEntities(token, callback) {

    var query = new azure.TableQuery()
        .select([req.query.DataToShow, 'Timestamp'])
        .where('Timestamp ge datetime? and Timestamp lt datetime? and deviceId eq ?', from, to, deviceSelected);

    var options =  { payloadFormat: "application/json;odata=nometadata" }

    tableSvc.queryEntities('outTable', query, token, options, function (error, result, response) {
        if (!error) {

            dataArray.push.apply(dataArray, result.entries);
            var token = result.continuationToken;
            if(token) {
                fetchAllEntities(token, callback);
            } else {
                console.log("Data  is: " + dataArray.length);
                callback();
            }
        } else {
            // ...
        }   
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多