RethinkDB.Connection
A module for managing connections.
A Connection
object is a process that can be started in various ways.
It is recommended to start it as part of a supervision tree with a name:
worker(RethinkDB.Connection, [[port: 28015, host: 'localhost', name: :rethinkdb_connection]])
Connections will by default connect asynchronously. If a connection fails, we retry with
an exponential backoff. All queries will return %RethinkDB.Exception.ConnectionClosed{}
until the connection is established.
If :sync_connect
is set to true
then the process will crash if we fail to connect. It’s
recommended to only use this if the database is on the same host or if a rethinkdb proxy
is running on the same host. If there’s any chance of a network partition, it’s recommended
to stick with the default behavior.
Summary
Functions
Closes a feed
Fetch the next dataset for a feed
noreply_wait
ensures that previous queries with the noreply flag have been processed by the server. Note that this guarantee only applies to queries run on the given connection
Run a query on a connection
Start connection as a linked process
Stop the connection
Macros
A convenience macro for naming connections
Functions
Closes a feed.
Since a feed is tied to a particular connection, no connection is needed when calling
close
.
Fetch the next dataset for a feed.
Since a feed is tied to a particular connection, no connection is needed when calling
next
.
noreply_wait
ensures that previous queries with the noreply flag have been processed by the server. Note that this guarantee only applies to queries run on the given connection.
Run a query on a connection.
Supports the following options:
timeout
- How long to wait for a responsedb
- Default database to use for query. Can also be specified as part of the query.
Start connection as a linked process
Accepts a Dict
of options. Supported options:
:host
- hostname to use to connect to database. Defaults to'localhost'
.:port
- port on which to connect to database. Defaults to28015
.:auth_key
- authorization key to use with database. Defaults tonil
.:db
- default database to use with queries. Defaults tonil
.:sync_connect
- whether to haveinit
block until a connection succeeds. Defaults tofalse
.:max_pending
- Hard cap on number of concurrent requests. Defaults to10000
:ssl
- a dict of options. Support SSL options::ca_certs
- a list of file paths to cacerts.
Macros
A convenience macro for naming connections.
For convenience we provide the use RethinkDB.Connection
macro, which automatically registers
itself under the module name:
defmodule FooDatabase, do: use RethinkDB.Connection
Then in the supervision tree:
worker(FooDatabase, [[port: 28015, host: 'localhost']])
When use RethinkDB.Connection
is called, it will define:
start_link
stop
run
All of these only differ from the normal RethinkDB.Connection
functions in that they don’t
accept a connection. They will use the current module as the process name. start_link
will
start the connection under the module name.
If you attempt to provide a name to start_link
, it will raise an ArgumentError
.