gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 20:58:50 32 4
gpt4 key购买 nike

我正在尝试借助以下链接在 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com