【发布时间】:2017-09-19 16:59:34
【问题描述】:
如何更新 Azure node.js 函数以更新/检索 Azure 表存储中的实体。我在函数中找到的唯一方法是插入条目。 那么如何查询/更新表呢?
任务是根据rowkey和partition key简单地检索数据,然后将存储为{"num":val}的键值对的值递增。
【问题讨论】:
标签: azure azure-storage azure-functions azure-table-storage
如何更新 Azure node.js 函数以更新/检索 Azure 表存储中的实体。我在函数中找到的唯一方法是插入条目。 那么如何查询/更新表呢?
任务是根据rowkey和partition key简单地检索数据,然后将存储为{"num":val}的键值对的值递增。
【问题讨论】:
标签: azure azure-storage azure-functions azure-table-storage
请通读Azure Functions Storage table bindings 处的“存储表输入绑定”。它有function.json和Node函数的例子。
如果仍有不清楚的地方,请用确切的问题细化您的问题。
更新:
这是针对您的细化问题的示例解决方案。我只有C#的,希望你能推导出node实现。
csx
#r "Microsoft.WindowsAzure.Storage"
using System;
using System.Net;
using Microsoft.WindowsAzure.Storage.Table;
public class Entity : TableEntity
{
public int num {get; set;}
}
public static HttpResponseMessage Run(HttpRequestMessage req, string partition,
string rowkey, Entity inputEntity, out Entity outputEntity)
{
if (inputEntity == null)
outputEntity = new Entity { PartitionKey = partition, RowKey = rowkey, num = 1};
else
{
inputEntity.num += 1;
outputEntity = inputEntity;
}
return req.CreateResponse(HttpStatusCode.OK, $"Done, num = {outputEntity.num}");
}
function.json:
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "HttpTriggerTableUpdate/{partition}/{rowkey}"
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "table",
"name": "inputEntity",
"tableName": "MyTable",
"partitionKey": "{partition}",
"rowKey": "{rowkey}",
"connection": "my_STORAGE",
"direction": "in"
},
{
"type": "table",
"name": "outputEntity",
"tableName": "MyTable",
"partitionKey": "{partition}",
"rowKey": "{rowkey}",
"connection": "my_STORAGE",
"direction": "out"
}
],
"disabled": false
}
【讨论】: