Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit b36c3ea

Browse files
Parse data config with Chiron in Quatro
1 parent a04f146 commit b36c3ea

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/4-Freya-FSharp/Data.fs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open Chiron
44
open RethinkDb.Driver
55
open RethinkDb.Driver.Ast
66
open RethinkDb.Driver.Net
7+
open System
78

89
type ConfigParameter =
910
| Hostname of string
@@ -27,7 +28,23 @@ with
2728
|> Seq.fold folder (RethinkDB.R.Connection())
2829
upcast bldr.Connect()
2930
static member FromJson json =
30-
Json.parse json
31+
match Json.parse json with
32+
| Object config ->
33+
let options =
34+
config
35+
|> Map.toList
36+
|> List.map (fun item ->
37+
match item with
38+
| "Hostname", String x -> Hostname x
39+
| "Port", Number x -> Port <| int x
40+
| "AuthKey", String x -> AuthKey x
41+
| "Timeout", Number x -> Timeout <| int x
42+
| "Database", String x -> Database x
43+
| key, value ->
44+
raise <| InvalidOperationException
45+
(sprintf "Unrecognized RethinkDB configuration parameter %s (value %A)" key value))
46+
{ Parameters = options }
47+
| _ -> { Parameters = [] }
3148

3249

3350
[<RequireQualifiedAccess>]

0 commit comments

Comments
 (0)