如何使用 node.js 和 Azure 存储 table 在异步函数中使用 continuationKey

How to use continuationKey in an async function using node.js & Azure storage table

我正在尝试使用 Azure table 存储在异步函数中实现延续令牌,

下面是我的代码,

async function acceleration_threshold1_exceed(carId){
  PartitionKey = carId + "_" + "acceleration_threshold1_exceed";
  return new Promise((resolve, reject) => {
   query = new azure.TableQuery()
  .select(['*'])
  .where('PartitionKey eq?', PartitionKey);
   tableSvc.queryEntities('eventsdata',query,null, function (error, result){
          if(!error){
            if(result.entries.length != 0){
              resolve(result.entries.length);
            }else{
              reject(NaN);
            }    
          }else{
              reject(error);
          }
        });
      });
    }


module.exports = {
  acceleration_threshold1_exceed
}
 
 

如果使用包azure-storage查询Azuretable存储实体,请参考以下代码


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

async function queryAllEntities(table){
    var tableQuery = new azure.TableQuery();
    
    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;
}