Compare commits
No commits in common. "main" and "v0.9.0-b06" have entirely different histories.
main
...
v0.9.0-b06
|
@ -41,15 +41,13 @@ let fetchPost (postId : string) =
|
|||
}
|
||||
```
|
||||
|
||||
### A standard way to translate JSON or a URI into a strongly-typed configuration
|
||||
### A standard way to translate JSON into a strongly-typed configuration
|
||||
|
||||
```fsharp
|
||||
/// type: DataConfig
|
||||
let config = DataConfig.fromJsonFile "data-config.json"
|
||||
// OR
|
||||
let config = DataConfig.fromConfiguration (config.GetSection "RethinkDB")
|
||||
// OR
|
||||
let config = DataConfig.fromUri (config.GetConnectionString "RethinkDB")
|
||||
|
||||
/// type: IConnection
|
||||
let conn = config.Connect ()
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
namespace RethinkDb.Driver.FSharp
|
||||
|
||||
open System
|
||||
open Microsoft.Extensions.Configuration
|
||||
open Microsoft.Extensions.Logging
|
||||
open Newtonsoft.Json.Linq
|
||||
open RethinkDb.Driver
|
||||
open RethinkDb.Driver.Net
|
||||
|
@ -38,30 +36,17 @@ type DataConfig =
|
|||
static member empty =
|
||||
{ Parameters = [] }
|
||||
|
||||
/// Build the connection from the given parameters
|
||||
member private this.BuildConnection () =
|
||||
this.Parameters
|
||||
|> Seq.fold ConnectionBuilder.build (RethinkDB.R.Connection ())
|
||||
|
||||
/// Create a RethinkDB connection
|
||||
member this.CreateConnection () : IConnection =
|
||||
(this.BuildConnection ()).Connect ()
|
||||
|
||||
/// Create a RethinkDB connection, logging the connection settings
|
||||
member this.CreateConnection (log : ILogger) : IConnection =
|
||||
let builder = this.BuildConnection ()
|
||||
if not (isNull log) then log.LogInformation $"Connecting to {this.EffectiveUri}"
|
||||
builder.Connect ()
|
||||
this.Parameters
|
||||
|> Seq.fold ConnectionBuilder.build (RethinkDB.R.Connection ())
|
||||
|> function builder -> builder.Connect ()
|
||||
|
||||
/// Create a RethinkDB connection
|
||||
member this.CreateConnectionAsync () : Task<Connection> =
|
||||
(this.BuildConnection ()).ConnectAsync ()
|
||||
|
||||
/// Create a RethinkDB connection, logging the connection settings
|
||||
member this.CreateConnectionAsync (log : ILogger) : Task<Connection> =
|
||||
let builder = this.BuildConnection ()
|
||||
if not (isNull log) then log.LogInformation $"Connecting to {this.EffectiveUri}"
|
||||
builder.ConnectAsync ()
|
||||
this.Parameters
|
||||
|> Seq.fold ConnectionBuilder.build (RethinkDB.R.Connection ())
|
||||
|> function builder -> builder.ConnectAsync ()
|
||||
|
||||
/// The effective hostname
|
||||
member this.Hostname =
|
||||
|
@ -87,20 +72,6 @@ type DataConfig =
|
|||
| Some (Database x) -> x
|
||||
| _ -> RethinkDBConstants.DefaultDbName
|
||||
|
||||
/// The effective configuration URI (excludes password / auth key)
|
||||
member this.EffectiveUri =
|
||||
seq {
|
||||
"rethinkdb://"
|
||||
match this.Parameters |> List.tryPick (fun x -> match x with User _ -> Some x | _ -> None) with
|
||||
| Some (User (username, _)) -> $"{username}:***pw***@"
|
||||
| _ ->
|
||||
match this.Parameters |> List.tryPick (fun x -> match x with AuthKey _ -> Some x | _ -> None) with
|
||||
| Some (AuthKey _) -> "****key****@"
|
||||
| _ -> ()
|
||||
$"{this.Hostname}:{this.Port}/{this.Database}?timeout={this.Timeout}"
|
||||
}
|
||||
|> String.concat ""
|
||||
|
||||
/// Parse settings from JSON
|
||||
///
|
||||
/// A sample JSON object with all the possible properties filled in:
|
||||
|
@ -145,26 +116,3 @@ type DataConfig =
|
|||
match cfg["username"], cfg["password"] with null, _ | _, null -> () | user -> User user
|
||||
]
|
||||
}
|
||||
|
||||
/// Parse settings from a URI
|
||||
///
|
||||
/// rethinkdb://user:password@host:port/database?timeout=##
|
||||
/// OR
|
||||
/// rethinkdb://authkey@host:port/database?timeout=##
|
||||
///
|
||||
/// Scheme and host are required; all other settings optional
|
||||
static member FromUri (uri : string) =
|
||||
let it = Uri uri
|
||||
if it.Scheme <> "rethinkdb" then invalidArg "Scheme" $"""URI scheme must be "rethinkdb" (was {it.Scheme})"""
|
||||
{ Parameters =
|
||||
[ Hostname it.Host
|
||||
if it.Port <> -1 then Port it.Port
|
||||
if it.UserInfo <> "" then
|
||||
if it.UserInfo.Contains ":" then
|
||||
let parts = it.UserInfo.Split ':' |> Array.truncate 2
|
||||
User (parts[0], parts[1])
|
||||
else AuthKey it.UserInfo
|
||||
if it.Segments.Length > 1 then Database it.Segments[1]
|
||||
if it.Query.Contains "?timeout=" then Timeout (int it.Query[9..])
|
||||
]
|
||||
}
|
|
@ -10,8 +10,6 @@ open RethinkDb.Driver.FSharp
|
|||
let dataCfg = DataConfig.fromJson "rethink-config.json"
|
||||
// - or -
|
||||
let dataCfg = DataConfig.fromConfiguration [config-section]
|
||||
// - or -
|
||||
let dataCfg = DataConfig.fromUri [connection-string]
|
||||
|
||||
let conn = dataCfg.CreateConnection () // IConnection
|
||||
```
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
<Copyright>See LICENSE</Copyright>
|
||||
<PackageTags>RethinkDB document F#</PackageTags>
|
||||
<VersionPrefix>0.9.0</VersionPrefix>
|
||||
<VersionSuffix>beta-07</VersionSuffix>
|
||||
<VersionSuffix>beta-06</VersionSuffix>
|
||||
<PackageReleaseNotes>
|
||||
Add URI config option and logging CreateConnection overloads
|
||||
Add optional arguments for tableCreate
|
||||
</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user