Skip to content

Commit 9fb45f2

Browse files
committed
Updating readme and tweaking method names
1 parent f0f0e05 commit 9fb45f2

3 files changed

Lines changed: 84 additions & 12 deletions

File tree

README.md

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,52 @@ This project is a wrapper around the [Cosmos DB](https://docs.microsoft.com/azur
88

99
Install via NuGet:
1010

11-
```
11+
```bash
1212
dotnet add package FSharp.CosmosDb
1313
```
1414

1515
Or using Paket:
1616

17-
```
17+
```bash
1818
dotnet paket add FSharp.CosmosDb
1919
```
2020

2121
## Usage
2222

23+
All operations will return an `AsyncSeq` via [FSharp.Control.AsyncSeq](http://fsprojects.github.io/FSharp.Control.AsyncSeq/index.html) that contains the data fetched, data inserted or data updated.
24+
25+
### Insert
26+
27+
```fsharp
28+
open FSharp.CosmosDb
29+
30+
let connStr = "..."
31+
32+
let insertUsers data =
33+
connStr
34+
|> Cosmos.fromConnectionString
35+
|> Cosmos.database "UserDb"
36+
|> Cosmos.container "UserContainer"
37+
|> Cosmos.insertMany<User> data
38+
|> Cosmos.execAsync
39+
```
40+
41+
### Update
42+
43+
```fsharp
44+
open FSharp.CosmosDb
45+
46+
let connStr = "..."
47+
48+
let updateUser id partitionKey =
49+
connStr
50+
|> Cosmos.fromConnectionString
51+
|> Cosmos.database "UserDb"
52+
|> Cosmos.container "UserContainer"
53+
|> Cosmos.update<User> id partitionKey (fun user -> { user with IsRegistered = true })
54+
|> Cosmos.execAsync
55+
```
56+
2357
### Query
2458

2559
```f#
@@ -38,8 +72,6 @@ let findUsers() =
3872
|> Cosmos.execAsync<User>
3973
```
4074

41-
The result from a query is an `AsyncSeq` via [FSharp.Control.AsyncSeq](http://fsprojects.github.io/FSharp.Control.AsyncSeq/index.html).
42-
4375
```f#
4476
[<EntryPoint>]
4577
let main argv =
@@ -52,6 +84,22 @@ let main argv =
5284
} |> Async.RunSynchronously
5385
```
5486

87+
### Delete
88+
89+
```fsharp
90+
open FSharp.CosmosDb
91+
92+
let connStr = "..."
93+
94+
let updateUser id partitionKey =
95+
connStr
96+
|> Cosmos.fromConnectionString
97+
|> Cosmos.database "UserDb"
98+
|> Cosmos.container "UserContainer"
99+
|> Cosmos.deleteItem id partitionKey
100+
|> Cosmos.execAsync
101+
```
102+
55103
# FSharp.CosmosDb.Analyzer 💡
56104

57105
[![NuGet Badge - FSharp.CosmosDb](https://buildstats.info/nuget/FSharp.CosmosDb)](https://www.nuget.org/packages/FSharp.CosmosDb)
@@ -73,10 +121,34 @@ Also part of this repo is a [F# Analyzer](https://github.com/ionide/FSharp.Analy
73121

74122
## Usage
75123

76-
### 1. Set two environment variables:
124+
### 1. Provide connection information
125+
126+
Connection information can be provided as either environment variables or using an `appsettings.json`/`appsettings.Development.json` file.
127+
128+
#### Environment Variables
129+
130+
The analyzer will look for the following environment variables:
131+
132+
- `FSHARP_COSMOS_CONNSTR` -> A full connection string to Cosmos DB
133+
- `FSHARP_COSMOS_HOST` & `FSHARP_COSMOS_KEY` -> The URI endpoint and access key
134+
135+
The `FSHARP_COSMOS_CONNSTR` will take precedence if both sets of environment variables are provided
136+
137+
#### App Settings
138+
139+
The analyzer will look for a file matching `appsettings.json` or `appsettings.Development.json` in either the workspace root of the VS Code instance or relative to the file being parsed. The file is expected to have the following JSON structure in it:
140+
141+
```json
142+
{
143+
"CosmosConnection": {
144+
"ConnectionString": "",
145+
"Host": "",
146+
"Key": ""
147+
}
148+
}
149+
```
77150

78-
- `FSHARP_COSMOS_HOST` -> The host address of your Cosmos DB
79-
- `FSHARP_COSMOS_KEY` -> The access key of your Cosmos DB
151+
If `CosmosConnection.ConnectionString` exists, it will be used, otherwise it will use the `CosmosConnection.Host` and `CosmosConnection.Key` to connect.
80152

81153
### 2. Install the Analyzer from paket
82154

@@ -97,7 +169,7 @@ Add the following settings (globally or in the workspace):
97169

98170
[MIT](./License.md)
99171

100-
# Thank Yous
172+
# Thank You
101173

102174
- Zaid Ajaj for the [Npgsql Analyzer](https://github.com/Zaid-Ajaj/Npgsql.FSharp.Analyzer). Without this I wouldn't have been able to work out how to do it (and there's some code lifted from there)
103175
- [Krzysztof Cieślak](https://twitter.com/k_cieslak) for the amazing Ionide plugin

samples/FSharp.CosmosDb.Samples/Program.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ let getFamilies conn =
7575

7676
let updateFamily conn id pk =
7777
conn
78-
|> Cosmos.updateItem<Family> id pk (fun family -> { family with IsRegistered = not family.IsRegistered })
78+
|> Cosmos.update<Family> id pk (fun family -> { family with IsRegistered = not family.IsRegistered })
7979
|> Cosmos.execAsync
8080

8181
let deleteFamily conn id pk =
8282
conn
83-
|> Cosmos.deleteItem<Family> id pk
83+
|> Cosmos.delete<Family> id pk
8484
|> Cosmos.execAsync
8585

8686
[<EntryPoint>]

src/FSharp.CosmosDb/Cosmos.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module Cosmos =
7272

7373
// --- UPDATE --- //
7474

75-
let updateItem<'T> id partitionKey (updater: 'T -> 'T) op =
75+
let update<'T> id partitionKey (updater: 'T -> 'T) op =
7676
Update
7777
{ Connection = op
7878
Id = id
@@ -81,7 +81,7 @@ module Cosmos =
8181

8282
// --- DELETE --- //
8383

84-
let deleteItem<'T> id partitionKey op =
84+
let delete<'T> id partitionKey op =
8585
Delete
8686
{ Connection = op
8787
Id = id

0 commit comments

Comments
 (0)