Functional wrapper around Microsoft.Azure.Cosmos.Table SDK. AzureTackle
simplifies the data access when talking to Azure tables.
Library | Version |
---|---|
AzureTackle |
# nuget client
dotnet add package AzureTackle
# or using paket
paket add AzureTackle --project path/to/project.fsproj
open AzureTackle
// get the connection from the environment
let connectionString() = Env.getVar "app_db"
type TestData =
{ PartKey: string
RowKey: RowKey
Date: DateTimeOffset
Exists: bool
Value: float
DoubleValue: double
Text: string }
let! values =
AzureTable.connect connectionString()
|> AzureTable.table testTable
|> AzureTable.execute (fun read ->
{ PartKey = read.partKey
RowKey = read.rowKey
Date = read.dateTimeOffset "Date"
Value = read.float "Value"
DoubleValue = read.double "DoubleValue"
Text = read.string "Text" })
let data =
values
|> function
| Ok r -> r |> Array.tryHead
| Error (exn:Exception) ->
failwithf "no data exn :%s" exn.Message
open AzureTackle
// get the connection from the environment
let connectionString() = Env.getVar "app_db"
type TestData =
{ PartKey: string
RowKey: RowKey
Date: DateTimeOffset
Exists: bool
Value: float
Text: string }
let! values =
AzureTable.connect connectionString()
|> AzureTable.table testTable
|> AzureTable.executeDirect (fun read ->
{ PartKey = read.partKey
RowKey = read.rowKey
Date = read.dateTimeOffset "Date"
Value = read.float "Value"
Text = read.string "Text" })
open AzureTackle
// get the connection from the environment
let connectionString() = Env.getVar "app_db"
type TestData =
{ PartKey: string
RowKey: RowKey
Date: DateTimeOffset
Exists: bool
Value: float
Text: string }
let! value =
connectionString()
|> AzureTable.connect
|> AzureTable.table testTable
|> AzureTable.filterReceive ("PartKey","RowKey")
|> AzureTable.receive (fun read ->
{ PartKey = read.partKey
RowKey = read.rowKey
Date = read.dateTimeOffset "Date"
Value = read.float "Value"
Text = read.string "Text" })
open AzureTackle
// get the connection from the environment
let connectionString() = Env.getVar "app_db"
type TestData =
{ PartKey: string
RowKey: RowKey
Date: DateTimeOffset
Exists: bool
Value: float
Text: string }
let! values =
connectionString()
|> AzureTable.connect
|> AzureTable.table testTable
|> AzureTable.filter [DtmO ("Date",GreaterThanOrEqual, timeModel.DateStart);DtmO ("Date",LessThan, timeModel.DateEnd)]
|> AzureTable.execute (fun read ->
{ PartKey = read.partKey
RowKey = read.rowKey
Date = read.dateTimeOffset "Date"
Value = read.float "Value"
Text = read.string "Text" })
let data =
values
|> function
| Ok r -> r |> Array.tryHead
| Error (exn:Exception) ->
failwithf "no data exn :%s" exn.Message
let testData =
{ PartKey = "PartKey"
RowKey = DateTime.UtcNow |> RowKey.toRowKey
Date = DateTime.UtcNow |> System.DateTimeOffset
Value = 0.2
Exists = true
Text = "isWorking" }
do!
connectionString()
|> AzureTable.connect
|> AzureTable.table TestTable
|> AzureTable.insert
(testData.PartKey, testData.RowKey)
(fun set ->
set.dateTimeOffset ("Date",testData.Date) |> ignore
set.float ("Value",testData.Value) |> ignore
set.bool ("Exists",testData.Exists) |> ignore
set.string ("Text",testData.Text)
)
do!
connectionString()
|> AzureTable.connect
|> AzureTable.table TestTable
|> AzureTable.delete ("partKey", "rowKey")
type Operator =
| LessThan
| LessThanOrEqual
| GreaterThan
| GreaterThanOrEqual
| Equal
| NotEqual
type AzureFilter =
| Flt of string * Operator * float
| Txt of string * Operator * string
| Dtm of string * Operator * DateTime
| DtmO of string * Operator * DateTimeOffset
| PaKey of Operator * string
| RoKey of Operator * string
| TStmp of Operator * DateTimeOffset
The only thing you have to do is to create a new storage account and connect it like this.
let azureCon =
(connectionString,connectionStringBackup)
|> AzureTable.connectWithBackup
All your Azure table operations will then be mirrored to the backup storage account