Node js中的Azure表存储连续令牌 [英] Azure table storage continuation tokens in Node js
本文介绍了Node js中的Azure表存储连续令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过以下链接在Azure表存储中实现延续令牌, https://docs. microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-nodejs
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
下面是我的代码,
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{
}
});
有人可以建议在Node.js中实现的正确方法吗?
can anyone one suggest right way to implement in Nodejs?
推荐答案
尝试将您的代码更改为以下内容:
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 {
// ...
}
});
}
这篇关于Node js中的Azure表存储连续令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文