Loading…

RethinkDb.Driver.FSharp
Configuration

Reading the Configuration

RethinkDb.Driver.FSharp provides four ways to parse connection parameters.

// 1. Reads the "RethinkDB" section in appsettings.json
let fromAppCfg = DataConfig.FromConfiguration (config.GetSection "RethinkDB")
// 2. Reads a file
let fromFileCfg = DataConfig.FromJsonFile "data-config.json"
// 3. Reads a string
let fromJsonCfg = DataConfig.FromJson """{ "hostname": "localhost", "database": "a_database" }"""
// 4. Reads a URI
let fromUri = DataConfig.FromUri "rethinkdb://localhost/a_database"

All versions return a DataConfig object which has CreateConnection and CreateConnectionAsync methods. In a dependency injection environment, the IConnection from these methods should be added as a singleton. In a self-managed environment, this is what should be managed. DataConfig also has properties that will return the effective settings for host, port, database, and timeout.

CreateConnection and CreateConnectionAsync also have overloads that take an ILogger instance; if one is provided, an information-level message will be logged with the connection's URI-formatted effective settings.

Specifying the Configuration

There are seven configuration options. In JSON format, these are:

For a URI, these 7 options are expressed as either rethinkdb://username:password@hostname:port/database?timeout=timeout (for username / password authentication) or rethinkdb://auth-key@hostname:port/database?timeout=timeout (for auth key / admin password authentication). In the URI format, only hostname is required; all other settings will use the driver defaults.