question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Output binding to table storage with fsharp

See original GitHub issue

I’m new to Azure Functions.

Any idea on how I can bind out to a Azure Storage Table with F#? I’m attempting to use ICollector (taken from C# example which works fine) but unfortunately it is not being recognised which I thought it would be as documented here - https://azure.microsoft.com/en-us/documentation/articles/functions-reference-csharp/. (Yes, I see that this is ref to C#)

Code:

open System
open System.IO

type Job = {
    PartitionKey :string; 
    RowKey: string; 
    Name :string
}

let inputPath = Environment.GetEnvironmentVariable("input")
let input = File.ReadAllText(inputPath)
let message = sprintf "F# script processed queue message '%s'" input
System.Console.Out.WriteLine(message)

let b = [{PartitionKey = "Key"; RowKey = Guid.NewGuid().ToString(); Name=input}]

let outputTable = new ICollector<Job>()
outputTable.Add(b)

With wanting to keep with F# as much as I possibly can with Azure Functions, if F# is yet to be fully supported, would you recommend a strategy of using C# for bindings and using F# for helper / supporting methods? Plus, are there any gotcha’s I need to know about?

Warmest regards,

Garrard.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
garrardkitchencommented, Aug 31, 2016

Hi @mathewc, I finally got there!

#if !COMPILED
#I "../../bin/Binaries/WebJobs.Script.Host"
#r "Microsoft.Azure.WebJobs.Host.dll"
#endif
#r "Microsoft.WindowsAzure.Storage"
open  Microsoft.WindowsAzure.Storage.Table
open System
open Microsoft.Azure.WebJobs.Host;

type Job() =
    inherit TableEntity()    
    member val Name = "" with get, set


let Run (input: string, outputTable: ICollector<'Job>, log: TraceWriter) =  
    log.Info(sprintf "F# script processed queue message '%s'" input)

    let b = new Job() 
    b.PartitionKey <- "Key"
    b.RowKey <- Guid.NewGuid().ToString()
    b.Name <- input

    b |> outputTable.Add

Works as expected.

Thanks for all your help today. Very much appreciated.

Warmest regards,

Garrard.

0reactions
mathewccommented, Aug 31, 2016

Awesome 😃 I don’t think you need the #if !COMPILED block though - that’s just for our local project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get started with Azure Table Storage using F# ...
This tutorial shows how to write F# code to do some common tasks using Azure Table Storage or the Azure Cosmos DB Table...
Read more >
Azure Tables output bindings for Azure Functions
Use an Azure Tables output binding to write entities to a table in Azure Cosmos DB for Table or Azure Table Storage.
Read more >
Azure Tables with F# | Compositional IT
storageAcc is creating the necessary storage account and container "blogtablestoragedemo" with a table called "employees". deployment is ...
Read more >
Using FSharp with Table Storage and Azure Functions
A quick look at how to use the FSharp.Azure.Storage package in Azure Functions.
Read more >
functions-bindings-storage-table-output.md
This output binding only supports creating new entities in a table. If you need to update an existing entity from your function code,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found