1
votes

How to update Azure node.js functions to update/retrieve an entity in azure table storage . Only method I found in functions is for inserting an entry. So how can the table be queried/updated?

The task is to simpy retrieve data on the basis of rowkey and partition key and then increment the value of key value pair stored as {"num":val}.

1

1 Answers

0
votes

Please read through "Storage table input binding" at Azure Functions Storage table bindings. It has examples of function.json and Node function.

If something is still not clear, please refine your question with the exact problem.

UPDATE:

Here is a sample solution for your refined problem. I only have it in C#, I hope you can derive node implementation.

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
}