gpt4 book ai didi

node.js - 从azure存储表中检索超过1000条记录 - js

转载 作者:行者123 更新时间:2023-12-02 06:16:09 26 4
gpt4 key购买 nike

我在检索超过一千条记录时遇到问题。不知何故,只检索到前 1000 个。根据我的研究,我发现我必须使用 getContinuation Token 来获取后续记录。请告知我应该如何将其添加到我的代码中。

tableService.queryEntities(table, tableQuery, null, function(error, results) {
if (error) {
alert('List table entities error, please open browser console to view detailed error');
console.log(error);
} else {
//display records

});

最佳答案

要根据您的代码使用回调,请使用递归。

var entities = [];
function queryEntitiesSegmented(table, tableQuery, continuationToken){
tableService.queryEntities(table, tableQuery, continuationToken, (error, results)=> {
if (error) { console.log(error); }
else {
entities.push.apply(entities, results.entries);
if(results.continuationToken){
queryEntitiesSegmented(table, tableQuery, results.continuationToken);
}
else{
entities.forEach(entity=>{
// display each one
})
}
}
});
}

queryEntitiesSegmented(table, tableQuery, null);

另一个选择是异步和等待。

const queryEntitiesSegmented = async(table, tableQuery, continuationToken)=>{
return new Promise((resolve,reject)=>{
tableService.queryEntities(table, tableQuery, continuationToken, (error, results)=> {
if (error) { reject(error); }
else { resolve(results); }
});
});
}

async function queryAllEntities(){
var tableQuery = new azure.TableQuery();
var table = 'tableName';
var continuationToken = null;
var entities = [];
do{
var results = await queryEntitiesSegmented(table, tableQuery, continuationToken);
continuationToken = results.continuationToken;
entities.push.apply(entities, results.entries);
}
while(continuationToken!=null);
return entities;
}

queryAllEntities().then(entities=>{
entities.forEach(entity=>{
//display each one
})
}).catch(error=>{ console.log(error); })

关于node.js - 从azure存储表中检索超过1000条记录 - js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53385166/

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