javascript - Node js 中的 Azure 表存储延续 token

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

我正在尝试借助以下链接在 Azure 表存储中实现延续 token , https://learn.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 中实现的正确方法吗?

最佳答案

尝试将代码更改为如下所示:

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

关于javascript - Node js 中的 Azure 表存储延续 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47786874/

相关文章:

javascript - REST : Return complex nested data vs. 多次调用

node.js - 使用 mongoose 对子子文档进行 CRUD

azure - Azure 机器学习平均 CPU 利用率指标是如何计算的?

javascript - 无法正确绑定(bind) observables 的 observableArray

javascript - HTML5 photoshop 喜欢多边形套索选择

node.js - 如何获取node.js中通过require加载的包的版本

Azure Blob 自定义角色

javascript - Highcharts:箭头在错误的图表上呈现

javascript - show() 方法从 dom 中删除 html 元素而不是显示它

c# - 如何使用访问 token 管理每个 Microsoft Azure 用户资源?