Skip to content

Commit

Permalink
Feature: Enable Fable (#30)
Browse files Browse the repository at this point in the history
* refactor: remove library specific types from core

* feat: introduce extras module

* feat: enable library for fable

* feat: enable .NET specific package

* housekeeping: update samples deps

* feat: add fable related files

* housekeeping: update props

* housekeeping: update gh actions .net version

* housekeeping: add missing props from packages
  • Loading branch information
AngelMunoz committed Jul 27, 2021
1 parent 5908770 commit 94a2952
Show file tree
Hide file tree
Showing 36 changed files with 2,995 additions and 1,510 deletions.
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fantomas-tool": {
"version": "4.5.1",
"commands": [
"fantomas"
]
},
"fable": {
"version": "3.2.9",
"commands": [
"fable"
]
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.301

- name: NBGV
id: nbgv
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -440,3 +440,6 @@ $RECYCLE.BIN/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

*.fs.js
*.mjs
5 changes: 2 additions & 3 deletions Directory.build.props
@@ -1,21 +1,20 @@
<Project>
<PropertyGroup>
<Product>Mondocks</Product>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>Copyright 2020 Angel D. Munoz.</Copyright>
<Authors>Angel Munoz and contributors</Authors>

<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<PackageTags>mongodb;fsharp;nosql;library;dotnet;dotnet5;dotnet-core</PackageTags>
<PackageTags>mongodb;fsharp;nosql;library;dotnet;dotnet5;dotnet-core;fable;node</PackageTags>
<RepositoryUrl>https://github.com/AngelMunoz/Mondocks.git</RepositoryUrl>
<PackageProjectUrl>https://github.com/AngelMunoz/Mondocks</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/AngelMunoz/Mondocks</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.228" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\LICENSE" Pack="true" PackagePath="LICENSE" />
Expand Down
45 changes: 45 additions & 0 deletions Mondocks.sln
Expand Up @@ -7,6 +7,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F7F80E78-006
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Mondocks", "src\Mondocks\Mondocks.fsproj", "{A454EFD1-EB4C-49D4-BCF4-1464B1A1FFBA}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Mondocks.Fable", "src\Mondocks.Fable\Mondocks.Fable.fsproj", "{735C861D-1D1D-4CB1-B98A-5F724342BBD6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Mondocks.Net", "src\Mondocks.Net\Mondocks.Net.fsproj", "{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DB615A5F-0195-4F22-92DD-C96247F71C7E}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Commands", "samples\Commands\Commands.fsproj", "{55356649-8439-4752-AEF2-66D823C7ABBB}"
Expand All @@ -15,6 +19,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Indexes", "samples\Indexes\
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Aggregation", "samples\Aggregation\Aggregation.fsproj", "{866587A2-3C6D-4952-8186-05A13D6082C3}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Expressive", "samples\fable\Expressive.fsproj", "{2B603A9F-95FB-4EC1-B784-ACD68EC45976}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -76,11 +82,50 @@ Global
{866587A2-3C6D-4952-8186-05A13D6082C3}.Release|x64.Build.0 = Release|Any CPU
{866587A2-3C6D-4952-8186-05A13D6082C3}.Release|x86.ActiveCfg = Release|Any CPU
{866587A2-3C6D-4952-8186-05A13D6082C3}.Release|x86.Build.0 = Release|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Debug|x64.ActiveCfg = Debug|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Debug|x64.Build.0 = Debug|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Debug|x86.ActiveCfg = Debug|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Debug|x86.Build.0 = Debug|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Release|Any CPU.Build.0 = Release|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Release|x64.ActiveCfg = Release|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Release|x64.Build.0 = Release|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Release|x86.ActiveCfg = Release|Any CPU
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898}.Release|x86.Build.0 = Release|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Debug|x64.ActiveCfg = Debug|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Debug|x64.Build.0 = Debug|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Debug|x86.ActiveCfg = Debug|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Debug|x86.Build.0 = Debug|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Release|Any CPU.Build.0 = Release|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Release|x64.ActiveCfg = Release|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Release|x64.Build.0 = Release|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Release|x86.ActiveCfg = Release|Any CPU
{735C861D-1D1D-4CB1-B98A-5F724342BBD6}.Release|x86.Build.0 = Release|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Debug|x64.ActiveCfg = Debug|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Debug|x64.Build.0 = Debug|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Debug|x86.Build.0 = Debug|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Release|Any CPU.Build.0 = Release|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Release|x64.ActiveCfg = Release|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Release|x64.Build.0 = Release|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Release|x86.ActiveCfg = Release|Any CPU
{2B603A9F-95FB-4EC1-B784-ACD68EC45976}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A454EFD1-EB4C-49D4-BCF4-1464B1A1FFBA} = {F7F80E78-0062-4034-AAF0-74300988C508}
{55356649-8439-4752-AEF2-66D823C7ABBB} = {DB615A5F-0195-4F22-92DD-C96247F71C7E}
{4125A0FE-B39C-49A9-A567-5FDF41FD618B} = {DB615A5F-0195-4F22-92DD-C96247F71C7E}
{866587A2-3C6D-4952-8186-05A13D6082C3} = {DB615A5F-0195-4F22-92DD-C96247F71C7E}
{0ED6B57E-5E7B-41CA-B45A-2D4A55A79898} = {F7F80E78-0062-4034-AAF0-74300988C508}
{735C861D-1D1D-4CB1-B98A-5F724342BBD6} = {F7F80E78-0062-4034-AAF0-74300988C508}
{2B603A9F-95FB-4EC1-B784-ACD68EC45976} = {DB615A5F-0195-4F22-92DD-C96247F71C7E}
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions samples/Aggregation/Aggregation.fsproj
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.11.4" />
<ProjectReference Include="..\..\src\Mondocks\Mondocks.fsproj" />
<PackageReference Include="MongoDB.Driver" Version="2.13.0" />
<ProjectReference Include="..\..\src\Mondocks.Net\Mondocks.Net.fsproj" />
</ItemGroup>

</Project>
55 changes: 32 additions & 23 deletions samples/Aggregation/Program.fs
Expand Up @@ -5,47 +5,56 @@ open Mondocks.Queries
open Mondocks.Aggregation
open Mondocks.Types

let createUsers minAge maxAge =
let random = Random()
let createUsers minAge maxAge =
let random = Random()

insert "users" {
documents
[
// an anonymous object that does not include a null _id
{| name = "Peter"; age = random.Next(minAge, maxAge); |}
{| name = "Sandra"; age = random.Next(minAge, maxAge); |}
{| name = "Mike"; age = random.Next(minAge, maxAge); |}
{| name = "Perla"; age = random.Next(minAge, maxAge); |}
{| name = "Perla"; age = random.Next(minAge, maxAge); |}
{| name = "Updateme"; age = 1; |}
{| name = "Deleteme"; age = 50; |}
]
documents [
// an anonymous object that does not include a null _id
{| name = "Peter"
age = random.Next(minAge, maxAge) |}
{| name = "Sandra"
age = random.Next(minAge, maxAge) |}
{| name = "Mike"
age = random.Next(minAge, maxAge) |}
{| name = "Perla"
age = random.Next(minAge, maxAge) |}
{| name = "Perla"
age = random.Next(minAge, maxAge) |}
{| name = "Updateme"; age = 1 |}
{| name = "Deleteme"; age = 50 |} ]
}

let countCmd =
let countCmd =
count {
collection "users"
query {| age = 50 |}
}

let distinctCmd =
distinct "users" {
key "name"
}
let distinctCmd = distinct "users" { key "name" }



[<EntryPoint>]
let main argv =
let client = MongoClient("mongodb://localhost:27017")
let client =
MongoClient("mongodb://192.168.100.5:27017")

let db = client.GetDatabase("mondocks")

let userscmd = createUsers 15 50
let result = db.RunCommand<InsertResult>(JsonCommand userscmd)

let result =
db.RunCommand<InsertResult>(JsonCommand userscmd)

printfn $"InsertResult: %A{result}"

let countResult = db.RunCommand<CountResult>(JsonCommand countCmd)
let distinctResult = db.RunCommand<DistinctResult<string>>(JsonCommand distinctCmd)
let countResult =
db.RunCommand<CountResult>(JsonCommand countCmd)

let distinctResult =
db.RunCommand<DistinctResult<string>>(JsonCommand distinctCmd)

printfn $"%A{countResult.ToJson()}\n%A{distinctResult.ToJson()}"

0 // return an integer exit code// return an integer exit code
0 // return an integer exit code// return an integer exit code
4 changes: 2 additions & 2 deletions samples/Commands/Commands.fsproj
Expand Up @@ -11,8 +11,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.11.4" />
<ProjectReference Include="..\..\src\Mondocks\Mondocks.fsproj" />
<PackageReference Include="MongoDB.Driver" Version="2.13.0" />
<ProjectReference Include="..\..\src\Mondocks.Net\Mondocks.Net.fsproj" />
</ItemGroup>

</Project>
105 changes: 61 additions & 44 deletions samples/Commands/Program.fs
Expand Up @@ -5,82 +5,99 @@ open Mondocks.Queries
open Mondocks.Types

// a Full record here
type User = { _id: ObjectId; name: string; age: int }
type User =
{ _id: ObjectId
name: string
age: int }

let createUsers minAge maxAge =
let random = Random()

let createUsers minAge maxAge =
let random = Random()
insert "users" {
documents
[
// an anonymous object that does not include a null _id
{| name = "Peter"; age = random.Next(minAge, maxAge); |}
{| name = "Sandra"; age = random.Next(minAge, maxAge); |}
{| name = "Mike"; age = random.Next(minAge, maxAge); |}
{| name = "Perla"; age = random.Next(minAge, maxAge); |}
{| name = "Updateme"; age = 1; |}
{| name = "Deleteme"; age = 50; |}
]
documents [
// an anonymous object that does not include a null _id
{| name = "Peter"
age = random.Next(minAge, maxAge) |}
{| name = "Sandra"
age = random.Next(minAge, maxAge) |}
{| name = "Mike"
age = random.Next(minAge, maxAge) |}
{| name = "Perla"
age = random.Next(minAge, maxAge) |}
{| name = "Updateme"; age = 1 |}
{| name = "Deleteme"; age = 50 |} ]
}

let updateUser (name: string) (newName: string) =
update "users" {
updates
[
{ // you can do mongo queries like
// {| ``$or`` = [] |} -> { $or: [] }
q = {| name = name |}
u = {| name = newName; age = 5 |}
multi = Some false
upsert = Some false
collation = None
arrayFilters = None
hint = None }
]
updates [ { // you can do mongo queries like
// {| ``$or`` = [] |} -> { $or: [] }
q = {| name = name |}
u = {| name = newName; age = 5 |}
multi = Some false
upsert = Some false
collation = None
arrayFilters = None
hint = None } ]
}


let deleteUser (name: string) =
let deleteUser (name: string) =
delete "users" {
deletes [
{ q = {| name = name |}
limit = 1
collation = None
hint = None
comment = None }
]

deletes [ { q = {| name = name |}
limit = 1
collation = None
hint = None
comment = None } ]

}

// Define a function to construct a message to print
let getUsersOverAge (age: int) =
find "users" {
// equivalent to a mongo query filter
// equivalent to a mongo query filter
// { age: { $gt: 10} }
filter {| age = {| ``$gt``= age |} |}
filter {| age = {| ``$gt`` = age |} |}
limit 2
skip 1
}

[<EntryPoint>]
let main argv =
let client = MongoClient("mongodb://localhost:27017")
let client =
MongoClient("mongodb://192.168.100.5:27017")

let db = client.GetDatabase("mondocks")

let userscmd = createUsers 15 50
let result = db.RunCommand<InsertResult>(JsonCommand userscmd)

let result =
db.RunCommand<InsertResult>(JsonCommand userscmd)

printfn $"InsertResult: %A{result}"

let over20 = getUsersOverAge 20
let result = db.RunCommand<FindResult<User>>(JsonCommand over20)

let result =
db.RunCommand<FindResult<User>>(JsonCommand over20)

printfn $"FindResult Ok: %f{result.ok}"
result.cursor.firstBatch |> Seq.iter (fun value -> printfn $"%A{value}")

result.cursor.firstBatch
|> Seq.iter (fun value -> printfn $"%A{value}")

let updatecmd = updateUser "Updateme" "Updated"
let result = db.RunCommand<UpdateResult>(JsonCommand updatecmd)

let result =
db.RunCommand<UpdateResult>(JsonCommand updatecmd)

printfn $"UpdateResult: %A{result}"

let deletecmd = deleteUser "Deleteme"
let result = db.RunCommand<DeleteResult>(JsonCommand deletecmd)

let result =
db.RunCommand<DeleteResult>(JsonCommand deletecmd)

printfn $"DeleteResult: %A{result}"
0 // return an integer exit code// return an integer exit code

0 // return an integer exit code// return an integer exit code
4 changes: 2 additions & 2 deletions samples/Indexes/Indexes.fsproj
Expand Up @@ -10,8 +10,8 @@
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.11.4" />
<ProjectReference Include="..\..\src\Mondocks\Mondocks.fsproj" />
<PackageReference Include="MongoDB.Driver" Version="2.13.0" />
<ProjectReference Include="..\..\src\Mondocks.Net\Mondocks.Net.fsproj" />
</ItemGroup>

</Project>

0 comments on commit 94a2952

Please sign in to comment.