This project is a wrapper around the Cosmos DB v4 .NET SDK to make it a bit more friendly to the F# language.
Install via NuGet:
dotnet add package FSharp.CosmosDb
Or using Paket:
dotnet paket add FSharp.CosmosDb
open FSharp.CosmosDb
let host = "https://..."
let key = "..."
let findUsers() =
host
|> Cosmos.host
|> Cosmos.connect key
|> Cosmos.database "UserDb"
|> Cosmos.container |> "UserContainer"
|> Cosmos.query "SELECT u.FirstName, u.LastName FROM u WHERE u.LastName = @name"
|> Cosmos.parameters [ "name", box "Powell" ]
|> Cosmos.execAsync<User>
The result from a query is an AsyncSeq
via FSharp.Control.AsyncSeq.
[<EntryPoint>]
let main argv =
async {
let users = findUsers()
do! users
|> AsyncSeq.iter (fun u -> printfn "%s %s" u.FirstName u.LastName)
return 0
} |> Async.RunSynchronously
Also part of this repo is a F# Analyzer for use from the CLI or in Ionide.
- Validation of database name against databases in Cosmos
- Quick fix provided with list of possible db names
- Validation of container name against containers in the database
- Quick fix provided with list of possible container names
- Detection of unused parameters in the query
- Quick fix provided with list of defined parameters (if any)
- Detection of supplied but unused parameters
- Quick fix provided with list of declared parameters
FSHARP_COSMOS_HOST
-> The host address of your Cosmos DBFSHARP_COSMOS_KEY
-> The access key of your Cosmos DB
paket add FSharp.Cosmos.Analyzer --group Analyzers
Add the following settings (globally or in the workspace):
{
"FSharp.enableAnalyzers": true,
"FSharp.analyzersPath": ["./packages/analyzers"]
}
- Zaid Ajaj for the Npgsql Analyzer. Without this I wouldn't have been able to work out how to do it (and there's some code lifted from there)
- Krzysztof CieΕlak for the amazing Ionide plugin