Azure node.js 用于 update/retrieve Azure table 存储中的实体

Azure node.js functions to update/retrieve an entity in azure table storage

如何将 Azure node.js 功能更新为 update/retrieve Azure table 存储中的实体。我在函数中找到的唯一方法是插入一个条目。 那么table怎么可能是queried/updated呢?

任务是简单的根据rowkey和partition key检索数据,然后递增存储为{"num":val}.

的键值对的值

请通读 "Storage table input binding" Azure Functions Storage table bindings。它有 function.json 和 Node 函数的例子。

如果还有什么不明白的地方,请用确切的问题细化你的问题。

更新:

这是针对您的优化问题的示例解决方案。我只有C#的,希望大家推导出节点实现

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
}