ReQL command: connect
Command syntax
r.connect(opts={}) → connection
Description
Create a new connection to the database server. Accepts the following options:
-
host
: the host to connect to (defaultlocalhost
). -
port
: the port to connect on (default28015
). -
db
: the default database (defaulttest
). -
user
: the user account to connect as (defaultadmin
). -
password
: the password for the user account to connect as (default''
, empty). -
timeout
: timeout period in seconds for the connection to be opened (default20
). -
ssl
: a hash of options to support SSL connections (defaultnil
). Currently, there is only one option available, and if thessl
option is specified, this key is required:-
ca_certs
: a path to the SSL CA certificate.
-
If the connection cannot be established, a ReqlDriverError
exception will be thrown.
The returned connection object will have two methods on it returning the connection’s port and address:
conn.client_port
conn.client_address
Using SSL with RethinkDB requires proxy software on the server, such as Nginx, HAProxy or an SSL tunnel. RethinkDB will encrypt traffic and verify the CA certification to prevent man-in-the-middle attacks. Consult your proxy’s documentation for more details.
Alternatively, you may use RethinkDB’s built-in TLS support.
The RethinkDB Ruby driver includes support for asynchronous connections using EventMachine. Read the asynchronous connections documentation for more information.
Example: Open a connection using the default host and port, specifying the default database.
conn = r.connect(:db => 'marvel')
Example: Open a new connection to the database.
conn = r.connect(:host => 'localhost',
:port => 28015,
:db => 'heroes')
Example: Open a new connection to the database, specifying a user/password combination for authentication.
conn = r.connect(:host => 'localhost',
:port => 28015,
:db => 'heroes',
:user => 'herofinder',
:password => 'metropolis')
Example: Open a new connection to the database using an SSL proxy.
conn = r.connect(:host => 'localhost',
:port => 28015,
:ssl => {
:ca_certs => '/path/to/ca.crt'
})
Example: Open a connection and immediately pass it to a Ruby block. Using this style, the connection will be automatically closed when execution reaches the end of the block.
r.connect(:db => 'marvel') { |conn|
r.table('superheroes').run(conn)
}
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/ruby/connect/