【问题标题】:Azure node.js functions to update/retrieve an entity in azure table storageAzure node.js 函数用于更新/检索 azure 表存储中的实体
【发布时间】:2017-09-19 16:59:34
【问题描述】:

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

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

【问题讨论】:

    标签: azure azure-storage azure-functions azure-table-storage


    【解决方案1】:

    请通读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
    }
    

    【讨论】:

    • 该链接不提供使用 node.js 天蓝色函数绑定在天蓝色表中查询/更新/删除实体的方法。你能提供一个代码sn-p吗?链接stackoverflow.com/questions/42492777/… 也解决了同样的问题。是否有解决方法。
    • replaceEntity等标准的azure-table方法显示错误
    • @sameeksha 如果您需要任意查询/删除等,则必须手动执行此操作,而无需函数绑定的直接帮助。对于您未指定的任务,我无法为您提供 sn-p。
    • 手动输入?任务是根据 rowkey 和 partition key 简单地检索数据,然后递增存储为 {"num":val} 的键值对的值。你能提供一些我可以阅读的来源的链接吗?对 azure 和 msdn 博客和文档来说非常新,很难赶上。
    • @sameeksha 添加了一个示例以连续增加一个键。下次请尽可能详细地说明您的用例,不要被多次询问。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多