Query Azure Table Storage using F#

When looking at the signature of the TableClient.QueryAsync method in Azure.Data.Tables SDK, it is not clear how to use it. It returns a AsyncPageable<T>. Fortunately that again implements the IAsyncEnumerable<T>, which means that we can use the Fsharp.Control.TaskSeq library to get the resulting entities.

  1. Install FSharp.Control.TaskSeq NuGet-package to your project.
  2. open FSharp.Control
  3. Write your code using the TaskSeq module
let getPartitionRows (tableClient: TableClient) (partition: string) =
    task {
        return!
            tableClient.QueryAsync<TableEntity>(filter = $"PartitionKey eq '{partition}'")
            |> TaskSeq.map fromEntity
            |> TaskSeq.toArrayAsync
    }

This is written as a reminder to myself, so that I can easily find it again

Leave a comment

Your email address will not be published. Required fields are marked *