Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dotnet-websharper/mongolab
MongoLab for WebSharper
https://github.com/dotnet-websharper/mongolab
Last synced: 8 days ago
JSON representation
MongoLab for WebSharper
- Host: GitHub
- URL: https://github.com/dotnet-websharper/mongolab
- Owner: dotnet-websharper
- License: apache-2.0
- Created: 2018-08-13T14:58:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-23T21:05:39.000Z (over 3 years ago)
- Last Synced: 2024-08-02T05:09:49.802Z (3 months ago)
- Language: F#
- Homepage: https://websharper.com
- Size: 589 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-websharper - PouchDb - CouchDB-inspired in-browser database. (Libraries / JavaScript library bindings)
README
# WebSharper.MongoLab
WebSharper abstractions for MongoLab REST API.
## Hello World
```
#!fsharpasync {
let! users =
Database "websharper" >- Collection "Users"
|> Fetchusers
|> Array.iter (fun user ->
JavaScript.Log (user?Name + " (" + user?Location + ")")
)
}
|> Async.Start
```##The ``Key`` reference cell
In order to be able to use the API, you have to set ``Key`` to your API key before any API call.
```
#!fsharpKey := "Your API key."
```## Constraints
You can restrict queries as in any other query language with ``Constraint``s and ``Condition``s. Let's count the Hungarian users.
```
#!fsharpasync {
let! n =
Database "websharper" >- Collection "Users"
|> Where (fun _ ->
Constraint ("Location", EqualsTo "Hungary")
)
|> CountJavaScript.Log ("Number of hungarian users: " + string n)
}
|> Async.Start
```## Insert
Inserting a document is just as easy as fetching one, and can be done in a type-safe way.
```
#!fsharptype User =
{
Name : string
Location : string
}Database "websharper" >- Collection "Users"
|> Push {
Name = "Sandor Rakonczai"
Location = "Hungary"
}
|> Async.Ignore
|> Async.Start
```## Optional "type-safety"
You can explicitly set the collection-type. After ``Collection<'a>``, ``Push`` will look like ``'a -> Async`` rather than ``obj -> ...``, which is much better.