Windows Azure SDK for Node.js 表存储批量更新

Paz*_*man 5 windows sdk azure node.js

您好,我正在使用 Windows Azure SDK for Node,但不知道如何使用此库进行批量更新:

https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/services/table/batchserviceclient.js

因为我找不到任何关于如何做到这一点的例子。有人使用 tableService.js 文件的 isInBatch 属性来进行批量更新、删除和插入吗?

任何帮助或建议将不胜感激。

干杯

Dav*_*gon 5

在 Windows Azure SDK for Node github 存储库中,查看下面的博客示例/examples/blog。具体来说,是 blog.js。在这里,您将看到从第 91 行左右开始的示例代码,其中一系列博客文章在实体组事务中写入同一分区:

  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');
Run Code Online (Sandbox Code Playgroud)

请注意分区的要点。这是在单个事务中写入多个实体的唯一方法:它们必须位于同一分区中。

编辑- 正如 @Igorek 正确指出的那样,单个实体组交易仅限于 100 个实体。此外,交易的整个有效负载不得超过 4MB。有关实体组事务的所有详细信息,请参阅此 MSDN 文章。