raklos
raklos

Reputation: 28545

Azure function CRUD on Table Storage

How can we do CRUD with table storage in Azure functions:

I have insert working, but would like to know how to return entities and do updates and deletes too.

   public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, IAsyncCollector<User> outputTable)
    {
        log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");

        var user = new User();
        user.PartitionKey = "Users";
        user.RowKey = DateTime.Now.Ticks.ToString();
        user.UserId = "aaaa";

        user.Country = "uk";
        await outputTable.AddAsync(user);

....

Upvotes: 0

Views: 5909

Answers (1)

Mikhail Shilkov
Mikhail Shilkov

Reputation: 35124

You can bind your function to an instance of CloudTable class, and then you get all its API at your hands.

I think you should be able to just replace IAsyncCollector<User> with CloudTable in your function definition and adjust the usage (provided you have a valid output binding).

See "Output usage" under Azure Functions Storage table bindings.

Upvotes: 3

Related Questions