azure-table-storage-async
Azure table storage API's that return promises to support async/await syntax. This package was born primarily out of my desire to have an Azure Storage API for TableStorage that supported async/await syntax to avoid callback hell.
Getting Started
Install
npm install azure-table-storage-async
Usage
var azureTS = require('azure-table-storage-async');
Many of the methods provided in the azure-storage npm package have been wrapped in this package to provide methods that may be called using async/await syntax. Many methods are named just like their counterparts in azure-storage and in general they simply execute that method and return a promise (exceptions are noted). There are additional methods provided that build upon the azure-storage methods for additional capabilities.
Methods
- queryAllAsync
- queryPartitionAsync
- queryCustomAsync
- queryEntitiesAsync
- retrieveEntityAsync
- insertEntityAsync
- insertOrReplaceEntityAsync
- replaceEntityAsync
- deleteEntityAsync
- createTableAsync
- createTableIfNotExistsAsync
- doesTableExistAsync
- executeBatchAsync
- batchMerge
- batchDelete
queryAllAsync(tableSvc, tableName)
Queries all entities from a table. This is done by calling queryEntitiesAsync
repeatedly with no partition until no continuation token is returned.
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
tableName | name of the table to query |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var tableSvc = azure;const result = await azureTS;// loop through results log the partition key and rowkeyfor let r of result console;
queryPartitionAsync(tableSvc, tableName, partitionName)
Queries all entities from a partition. This is done by calling queryEntitiesAsync
repeatedly for the specified partition until no continuation token is returned.
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
tableName | name of the table to query |
partitionName | name of the partition to be queried |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey you want to query goes here';var tableSvc = azure;const result = await azureTS;// loop through results log the row keyfor let r of result console;
queryCustomAsync(tableSvc, tableName, query)
Executes a custom query defined in an azure-storage TableQuery
. This is done by calling queryEntitiesAsync
repeatedly wiht the specified query until no continuation token is returned.
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
tableName | name of the table to query |
query | an azure table query object created with a custom where clause, etc. |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey you want to query goes here';var myattr1 = 'The value of attr1 to look for goes here';var tableSvc = azure;// create a query to get entities from partition mypartition with attr1 = myattr1const query = ;const result = await azureTS;// loop through results log the row key and attr1for let r of result console;
queryEntitiesAsync(tableSvc, table, query, cont)
Executes the azure-storage queryEntities
method.
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to query |
query | query object |
cont | continuation token |
retrieveEntityAsync(tableSvc, table, partition, rowkey)
Executes the azure-storage retrieveEntity
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to query |
partition | name of the partition to query |
rowkey | RowKey of entity to be queried |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey you want to query goes here';var myrowkey = 'The RowKey you want to query goes here';var tableSvc = azure;const result = await azureTS;// log attr1 from entity (any attribute from the entity)console;
insertEntityAsync(tableSvc, table, entity)
Executes the azure-storage insertEntity
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to insert into |
entity | the entity to be inserted |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey goes here';var myrowkey = 'The RowKey goes here';var myattr1 = 'The value of attr1 goes here';var tableSvc = azure;var entGen = azureTableUtilitiesentityGenerator;var myentity = PartitionKey: entGen RowKey: entGen attr1: entGen ;await azureTS;
insertOrReplaceEntityAsync(tableSvc, table, entity)
Executes the azure-storage insertOrReplaceEntity
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to insert/replace in |
entity | the entity to be inserted or replaced |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey goes here';var myrowkey = 'The RowKey goes here';var myattr1 = 'The value of attr1 goes here';var tableSvc = azure;var entGen = azureTableUtilitiesentityGenerator;var myentity = PartitionKey: entGen RowKey: entGen attr1: entGen ;await azureTS;
replaceEntityAsync(tableSvc, table, entity)
Executes the azure-storage replaceEntity
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to update |
entity | the entity to be replaced |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey goes here';var myrowkey = 'The RowKey goes here';var myattr1 = 'The value of attr1 goes here';var tableSvc = azure;var entGen = azureTableUtilitiesentityGenerator;var myentity = PartitionKey: entGen RowKey: entGen attr1: entGen ;await azureTS;
deleteEntityAsync(tableSvc, table, entity)
Executes the azure-storage deleteEntity
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to delete from |
entity | the entity to be deleted |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey goes here';var myrowkey = 'The RowKey goes here';var tableSvc = azure;var entGen = azureTableUtilitiesentityGenerator;var myentity = PartitionKey: entGen RowKey: entGen ;await azureTS;
createTableAsync(tableSvc, table)
Executes the azure-storage createTable
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to create |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var tableSvc = azure;await azureTS;
createTableIfNotExistsAsync(tableSvc, table)
Executes the azure-storage createTableIfNotExists
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to check existence of and create if necessary |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var tableSvc = azure;await azureTS;
doesTableExistAsync(tableSvc, table)
Executes the azure-storage doesTableExist
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table to check existence of |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var tableSvc = azure;await azureTS;
executeBatchAsync(tableSvc, table, batch)
Executes the azure-storage executeBatch
method
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table the batch will operate against |
batch | a batch object created using azure-storage.TableBatch |
batchMerge(tableSvc, table, list)
Perform a batch merge on an array of entites. The array may be as large as you would like as it will create batches of 100 as the azure-storage batch operations only support 100 entites at a time.
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table the batch will operate against |
list | an array of entities to be merged into the table |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey goes here';var tableSvc = azure;var entGen = azureTableUtilitiesentityGenerator;// create 10 records to insert/merge in a batchvar mylist = ;for var i=0; i<10; i++ mylist;;await azureTS;
batchDelete(tableSvc, table, list)
Perform a batch delete on an array of entites. The array may be as large as you would like as it will create batches of 100 as the azure-storage batch operations only support 100 entites at a time.
Parameter | Description |
---|---|
tableSvc | table service object created using azure-storage.createTableService |
table | name of the table the batch will operate against |
list | an array of entities to be deleted from the table |
Example
var azure = ;var azureTS = ;var accountname = 'Your azure account name goes here';var accountkey = 'Your azure account key goes here';var mytable = 'The table you want to query goes here';var mypartition = 'The PartitionKey goes here';var tableSvc = azure;// query a partition and then delete all records queried in a batchvar result = await azureTS;await azureTS;