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

Viewed 90

I am trying to implement the continuation tokens in an async function with Azure table storage,

Below is my code,

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
}
 
 
1 Answers

If you use package azure-storage to query Azure table storage entity, please refer to the following code


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;
}
Related