首页 文章

Azure node.js用于更新/检索azure表存储中的实体

提问于
浏览
0

如何更新Azure node.js函数以更新/检索azure表存储中的实体 . 我在函数中找到的方法只是插入一个条目 . 那么如何查询/更新表格呢?

任务是在rowkey和分区键的基础上简单地检索数据,然后增加存储为 {"num":val} 的键值对的值 .

1 回答

  • 0

    请阅读"Storage table input binding"阅读"Storage table input binding" . 它有 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
    }
    

相关问题