Last active
August 29, 2015 14:05
-
-
Save Thorium/92ac23e297eb21d65c8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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