Node js中的Azure表存储延续令牌

时间:2017-12-13 06:30:38

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

我试图在以下链接的帮助下在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中实现正确的方法吗?

1 个答案:

答案 0 :(得分:2)

尝试将代码更改为以下内容:

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 {
            // ...
        }   
    });
}