F# API for using Windows Azure services
F# Other
Pull request Compare This branch is 15 commits behind fsprojects:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.paket
FSharp.Azure.Storage.IntegrationTests
FSharp.Azure.Storage
media
.gitignore
.travis.yml
FSharp.Azure.Storage.sln
LICENCE.txt
RELEASE_NOTES.md
Readme.md
appveyor.yml
build.cmd
build.fsx
build.sh
paket.dependencies
paket.lock

Readme.md

FSharp.Azure.Storage

FSharp.Azure.Storage is a wrapper over the standard Microsoft WindowsAzure.Storage library that allows you to write idiomatic F# when talking to Azure.

The standard storage API is fine when you're writing C#, however when you're using F# you want to be able to use immutable record types, use the native F# async support and generally write in a functional style.

NuGet

Install-Package FSharp.Azure.Storage

A Quick Taster

Inserting/Updating Table Storage

Imagine we had a record type that we wanted to save into table storage:

open FSharp.Azure.Storage.Table

type Game = 
    { [<PartitionKey>] Developer: string
      [<RowKey>] Name: string
      HasMultiplayer: bool }

Now we'll define a helper function inGameTable that will allow us to persist these Game records to table storage into an existing table called "Games":

open Microsoft.WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage.Table

let account = CloudStorageAccount.Parse "UseDevelopmentStorage=true;" //Or your connection string here
let tableClient = account.CreateCloudTableClient()

let inGameTable game = inTable tableClient "Games" game

Now that the set up ceremony is done, let's insert a new Game into table storage:

let game = { Developer = "343 Industries"; Name = "Halo 4"; HasMultiplayer = true }

let result = game |> Insert |> inGameTable

Let's say we want to modify this game and update it in table storage:

let modifiedGame = { game with HasMultiplayer = false }

let result2 = (modifiedGame, result.Etag) |> Replace |> inGameTable

Querying Table Storage

First we need to set up a little helper function for querying from the "Games" table:

let fromGameTable q = fromTable tableClient "Games" q

Here's how we'd query for an individual record by PartitionKey and RowKey:

let halo4, metadata = 
    Query.all<Game>
    |> Query.where <@ fun g s -> s.PartitionKey = "343 Industries" && s.RowKey = "Halo 4" @>
    |> fromGameTable
    |> Seq.head

If we wanted to find all multiplayer games made by Valve:

let multiplayerValveGames = 
    Query.all<Game>
    |> Query.where <@ fun g s -> s.PartitionKey = "Valve" && g.HasMultiplayer @>
    |> fromGameTable

Further Information

For further documentation and examples, please visit the wiki.

Building

Run build.cmd or build.sh to restore the required dependencies using Paket and then build and run tests using FAKE. You can also build in Visual Studio.

In order to run integration tests against the Storage Emulator, pass the -ef RunEmulatorTests arguments to the build script. To run integration tests against a real storage account, set the FSharpAzureStorageConnectionString environment variable to a Azure Storage account connection string, then pass the -ef RunRemoteTests arguments to the build script.

AppVeyor (Windows)
Build status

Maintainer(s)

The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)