You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-10Lines changed: 82 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,18 +8,52 @@ This project is a wrapper around the [Cosmos DB](https://docs.microsoft.com/azur
8
8
9
9
Install via NuGet:
10
10
11
-
```
11
+
```bash
12
12
dotnet add package FSharp.CosmosDb
13
13
```
14
14
15
15
Or using Paket:
16
16
17
-
```
17
+
```bash
18
18
dotnet paket add FSharp.CosmosDb
19
19
```
20
20
21
21
## Usage
22
22
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
+
23
57
### Query
24
58
25
59
```f#
@@ -32,14 +66,12 @@ let findUsers() =
32
66
|> Cosmos.host
33
67
|> Cosmos.connect key
34
68
|> Cosmos.database "UserDb"
35
-
|> Cosmos.container |> "UserContainer"
69
+
|> Cosmos.container "UserContainer"
36
70
|> Cosmos.query "SELECT u.FirstName, u.LastName FROM u WHERE u.LastName = @name"
37
71
|> Cosmos.parameters [ "name", box "Powell" ]
38
72
|> Cosmos.execAsync<User>
39
73
```
40
74
41
-
The result from a query is an `AsyncSeq` via [FSharp.Control.AsyncSeq](http://fsprojects.github.io/FSharp.Control.AsyncSeq/index.html).
@@ -71,12 +119,36 @@ Also part of this repo is a [F# Analyzer](https://github.com/ionide/FSharp.Analy
71
119
- Detection of supplied but unused parameters
72
120
- Quick fix provided with list of declared parameters
73
121
74
-
## Usage
122
+
## Analyzer Usage
123
+
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
75
129
76
-
### 1. Set two environment variables:
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
+
```
77
150
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.
80
152
81
153
### 2. Install the Analyzer from paket
82
154
@@ -97,7 +169,7 @@ Add the following settings (globally or in the workspace):
97
169
98
170
[MIT](./License.md)
99
171
100
-
# Thank Yous
172
+
# Thank You
101
173
102
174
- 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)
103
175
-[Krzysztof Cieślak](https://twitter.com/k_cieslak) for the amazing Ionide plugin
0 commit comments