Skip to content

Commit aafd1a4

Browse files
authored
Merge pull request #25 from aaronpowell/0.2.0
Version 0.2.0
2 parents 1cbd57d + 8182cc9 commit aafd1a4

37 files changed

Lines changed: 1101 additions & 297 deletions

.gitattributes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

.github/workflows/build-prs.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build previews
2+
3+
env:
4+
OUTPUT_PATH: ${{ github.workspace }}/.nupkg
5+
DOTNET_VERSION: "3.1.100"
6+
7+
on:
8+
push:
9+
branches-ignore:
10+
- master
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@master
18+
19+
- name: Setup Dotnet ${{ env.DOTNET_VERSION }}
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: ${{ env.DOTNET_VERSION }}
23+
24+
- name: Restore dotnet tools
25+
run: dotnet tool restore
26+
27+
- name: Generate packages
28+
run: dotnet fake run ./build.fsx --target Release
29+
30+
- name: Set Version
31+
run: dotnet fake run ./build.fsx --target SetVersionForCI
32+
33+
- name: Create version file
34+
run: echo ${{ env.package_version }} >> ${{ env.OUTPUT_PATH }}/version.txt
35+
36+
- name: Publish release packages
37+
uses: actions/upload-artifact@v1
38+
with:
39+
name: packages
40+
path: ${{ env.OUTPUT_PATH }}

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "coreclr",
1616
"request": "launch",
1717
"preLaunchTask": "build",
18-
"program": "${workspaceFolder}/tests/FSharp.CosmosDb.Analyzer.Tests/bin/Debug/netcoreapp2.0/FSharp.CosmosDb.Analyzer.Tests.dll",
18+
"program": "${workspaceFolder}/tests/FSharp.CosmosDb.Analyzer.Tests/bin/Debug/netcoreapp3.1/FSharp.CosmosDb.Analyzer.Tests.dll",
1919
"args": [],
2020
"cwd": "${workspaceFolder}",
2121
"stopAtEntry": false,

.vscode/tasks.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"type": "shell",
1010
"args": [
1111
"build",
12-
// Ask dotnet build to generate full paths for file names.
1312
"/property:GenerateFullPaths=true",
14-
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
1513
"/consoleloggerparameters:NoSummary"
1614
],
1715
"group": {
@@ -35,7 +33,18 @@
3533
"presentation": {
3634
"reveal": "always"
3735
},
38-
"problemMatcher": "$msCompile"
36+
"problemMatcher": "$msCompile",
37+
"dependsOn": ["build"]
38+
},
39+
{
40+
"label": "run analyzers",
41+
"type": "shell",
42+
"command": "dotnet",
43+
"args": ["fake", "run", "./build.fsx", "--target", "RunAnalyzer"],
44+
"problemMatcher": ["$msCompile"],
45+
"presentation": {
46+
"reveal": "always"
47+
}
3948
}
4049
]
4150
}

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog for `FSharp.CosmosDb`
22

3+
## [0.2.0]
4+
5+
### Added
6+
7+
- Ability to create a connection from a connection string with `Cosmos.fromConnectionString`
8+
- Insert API
9+
- Update API
10+
- Delete API
11+
12+
### Changed
13+
14+
- Introduced a `maybe` computational expression to simplify option types
15+
- Major refactor of the internals
16+
- Change analyzer to support using appsettings not just environment variables to find connection info
17+
- Bumped dependency for FSAC to 35.0.0
18+
319
## [0.1.1] - 2020-03-13
420

521
### Changed

README.md

Lines changed: 82 additions & 10 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#
@@ -32,14 +66,12 @@ let findUsers() =
3266
|> Cosmos.host
3367
|> Cosmos.connect key
3468
|> Cosmos.database "UserDb"
35-
|> Cosmos.container |> "UserContainer"
69+
|> Cosmos.container "UserContainer"
3670
|> Cosmos.query "SELECT u.FirstName, u.LastName FROM u WHERE u.LastName = @name"
3771
|> Cosmos.parameters [ "name", box "Powell" ]
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)
@@ -71,12 +119,36 @@ Also part of this repo is a [F# Analyzer](https://github.com/ionide/FSharp.Analy
71119
- Detection of supplied but unused parameters
72120
- Quick fix provided with list of declared parameters
73121

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
75129

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+
```
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

build.fsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Fake.DotNet
55
open Fake.IO
66
open Fake.IO.Globbing.Operators
77
open Fake.Core.TargetOperators
8+
open Fake.DotNet.Testing
89

910
Target.initEnvironment()
1011

@@ -81,10 +82,32 @@ Target.create "SetVersionForCI" (fun _ ->
8182
let changelog = getChangelog()
8283
printfn "::set-env name=package_version::%s" changelog.NuGetVersion)
8384

84-
Target.create "All" ignore
85+
Target.create "Test" (fun _ -> DotNet.test id sln)
86+
87+
Target.create "RunAnalyzer" (fun ctx ->
88+
let args =
89+
sprintf
90+
"--project samples/FSharp.CosmosDb.Samples/FSharp.CosmosDb.Samples.fsproj --analyzers-path src/FSharp.CosmosDb.Analyzer/bin/%A/netcoreapp2.0/publish"
91+
(configuration (ctx.Context.AllExecutingTargets))
92+
DotNet.exec id "fsharp-analyzers" args |> ignore)
93+
94+
Target.create "Default" ignore
8595
Target.create "Release" ignore
8696

87-
"Clean" ==> "Restore" ==> "Build" ==> "All"
88-
"Clean" ==> "Restore" ==> "Build" ==> "Publish" ==> "Package" ==> "Changelog" ==> "Release"
97+
"Clean"
98+
==> "Restore"
99+
==> "Build"
100+
==> "Default"
101+
102+
"Default"
103+
==> "Publish"
104+
==> "Test"
105+
==> "Package"
106+
==> "Changelog"
107+
==> "Release"
108+
109+
"Default"
110+
==> "Publish"
111+
==> "RunAnalyzer"
89112

90-
Target.runOrDefault "All"
113+
Target.runOrDefault "Default"

paket.dependencies

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ source https://api.nuget.org/v3/index.json
33

44
storage: none
55

6-
nuget Expecto
76
nuget FSharp.Analyzers.SDK
8-
nuget FSharp.Compiler.Service 34.1.1
7+
nuget FSharp.Compiler.Service 35.0.0
98
nuget Azure.Cosmos 4.0.0-preview3 preview
109
nuget FSharp.Control.AsyncSeq
1110
nuget System.Json
1211
nuget Microsoft.Extensions.Configuration
1312
nuget Microsoft.Extensions.Configuration.Json
14-
nuget Microsoft.NET.Test.Sdk
15-
nuget YoloDev.Expecto.TestSdk
13+
nuget Expecto 8.13.1
14+
nuget YoloDev.Expecto.TestSdk 0.8.0
15+
nuget Microsoft.NET.Test.Sdk 16.5.0
1616
nuget Microsoft.SourceLink.GitHub prerelease copy_local: true
17+
nuget Microsoft.NETFramework.ReferenceAssemblies copy_local: true
1718

19+
nuget FSharp.SystemTextJson 0.10.25
1820
// [ FAKE GROUP ]
1921
group Build
2022
storage none
2123
source https://api.nuget.org/v3/index.json
2224
nuget Fake.DotNet.Cli
2325
nuget Fake.IO.FileSystem
2426
nuget Fake.Core.Target
25-
nuget Fake.Core.ReleaseNotes
27+
nuget Fake.Core.ReleaseNotes
28+
nuget Fake.DotNet.Testing.Expecto

0 commit comments

Comments
 (0)