Skip to content

Instantly share code, notes, and snippets.

@Thorium
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thorium/92ac23e297eb21d65c8e to your computer and use it in GitHub Desktop.
Save Thorium/92ac23e297eb21d65c8e to your computer and use it in GitHub Desktop.
//Using Azure Table Storage with WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage.Table
open Microsoft.WindowsAzure.ServiceRuntime
type Person(partitionKey, rowKey, name) =
inherit TableEntity(partitionKey, rowKey)
new(name) = Person("defaultPartition", System.Guid.NewGuid().ToString(), name)
new() = Person("")
member val Name = name with get, set
(*
Add this into ServiceDefinition.csdef <WorkerRole>:
<ConfigurationSettings>
<Setting name="TableStorageConnectionString" />
</ConfigurationSettings>
Add this into ServiceConfiguration.*.csdef <ConfigurationSettings>:
<Setting name="TableStorageConnectionString" value="UseDevelopmentStorage=true" />
*)
let doAction tableName operation =
let account =
"TableStorageConnectionString"
|> RoleEnvironment.GetConfigurationSettingValue
|> CloudStorageAccount.Parse
//memoize this
let client = account.CreateCloudTableClient()
let table = client.GetTableReference(tableName)
async {
let! created = table.CreateIfNotExistsAsync() |> Async.AwaitTask
return! table.ExecuteAsync(operation) |> Async.AwaitTask
}
let CreatePerson name =
Person(name)
|> TableOperation.Insert //Insert, Delete, Replace, etc.
|> doAction "MyStorageTable"
|> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment