gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 14:13:55 25 4
gpt4 key购买 nike

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

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

因为我找不到任何有关如何执行此操作的示例。有人使用 tableService.js 文件的 isInBatch 属性来进行批量更新、删除和插入吗?

如有任何帮助或建议,我们将不胜感激。

干杯

最佳答案

在 Node 的 Windows Azure SDK github repo 中,查看 /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');

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

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

关于Windows Azure SDK for Node.js 表存储批量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10809694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com