Hello I am using the Windows Azure SDK for node but can't figure out how to do a batch update using this library:
as I couldn't find any examples on how to do it. Has anybody used the isInBatch property of the tableService.js file to do batch updates, deletes and inserts?
Any help or advice would be appreciated.
Cheers
In the Windows Azure SDK for node github repo, take a look at the Blog example under /examples/blog
. Specifically, blog.js. Here, you'll see sample code, starting around line 91, where a series of blog posts are written to the same partition, in an entity group transaction:
provider.tableClient.beginBatch();
var now = new Date().toString();
provider.tableClient.insertEntity(tableName, { PartitionKey: partition, RowKey: uuid(), title: 'Post one', body: 'Body one', created_at: now });
provider.tableClient.insertEntity(tableName, { PartitionKey: partition, RowKey: uuid(), title: 'Post two', body: 'Body two', created_at: now });
provider.tableClient.insertEntity(tableName, { PartitionKey: partition, RowKey: uuid(), title: 'Post three', body: 'Body three', created_at: now });
provider.tableClient.insertEntity(tableName, { PartitionKey: partition, RowKey: uuid(), title: 'Post four', body: 'Body four', created_at: now });
provider.tableClient.commitBatch(function () {
console.log('Done');
Note the point about partition. This is the only way you can write multiple entities within a single transaction: They must be in the same partition.
EDIT - As @Igorek rightly points out, a single entity group transaction is limited to 100 entities. Also, the entire payload of the transaction may not exceed 4MB. See this MSDN article for all the details around entity group transactions.