RethinkDb.Driver.FSharp
Configuration
Reading the Configuration
RethinkDb.Driver.FSharp provides four ways to parse connection parameters.
- The first is via a
ConfigurationSection, usually obtained from theIConfigurationcreated whenappsettings.jsonis read. - The second reads a separate JSON file and parses the configuration from it.
- The third takes a JSON string and parses the configuration from it.
- The fourth takes parameters in a URI format.
// 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:
hostname(string) - The URL or IP address of the RethinkDB serverport(int) - The port number of the RethinkDB serverdatabase(string) - The default database to use for commands that do not specify a databasetimeout(int) - The number of seconds a command may take before being terminatedusername(string) - A username with which to authenticate with RethinkDB (ignored if no password present)password(string) - The password with which to authenticate with RethinkDB (ignored if no username present)auth-key(string) - An authentication key (deprecated; v2.3 and later interpret this as the admin user password)
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.