Azure table storage continuation tokens in Node js

浪子不回头ぞ 提交于 2019-12-12 18:47:07

问题


I am trying to implement the continuation tokens in Azure table storage with the help of following link, https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-nodejs

Below is my code,

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

can anyone one suggest right way to implement in Nodejs?


回答1:


Try changing your code to something like this:

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


来源:https://stackoverflow.com/questions/47786874/azure-table-storage-continuation-tokens-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!