Crate reql[−][src]
ReQL is the RethinkDB query language. It offers a very powerful and convenient way to manipulate JSON documents.
Start the server
Linux and OS X
Start the server from a terminal window.
$ rethinkdb
Windows
Start the server from the Windows command prompt.
C:\Path\To\RethinkDB\>rethinkdb.exe
Import the driver
First, make sure you have protoc
installed and in your PATH
. See
prost-build
documentation
for more details if it fails to compile.
Add this crate (reql
) and the futures
crate to your dependencies in Cargo.toml
.
You may also need to depend on a crate that provides an async implementation of a
TcpStream
, like async-std
, for example. You can use this crate
with any TcpStream
that implements AsyncRead
and AsyncWrite
from
the futures crate. The implementation also needs to implement the same
traits for &TcpStream
because we use unmutable references of the
connection to take advantage of RethinkDB’s connection pipelining abilities.
Now import the RethinkDB driver:
use reql::r;
You can now access RethinkDB commands through the r
struct.
Open a connection
When you first start RethinkDB, the server opens a port for the client
drivers (28015
by default). Let’s open a connection:
use async_std::net::TcpStream; use reql::{r, DEFAULT_ADDR}; let stream = TcpStream::connect(DEFAULT_ADDR).await?; let connection = r.connection(stream).await?;
The variable connection
is now initialized and we can run queries.
Send a query to the database
use async_std::net::TcpStream; use futures::TryStreamExt; use reql::{r, DEFAULT_ADDR}; let stream = TcpStream::connect(DEFAULT_ADDR).await?; let conn = r.connection(stream).await?; let mut query = r.expr("Hello world!").run(&conn);
Modules
cmd |
Structs
Connection | The connection object returned by |
Query | The query that will be sent to RethinkDB |
r | The top-level ReQL namespace |
Enums
Availability | A server in the cluster is unavailable |
Client | An error has occurred within the driver |
Error | The most generic error message in ReQL |
Runtime | The parent class of all runtime errors |
Constants
DEFAULT_ADDR | Default address of the RethinkDB server |
Traits
TcpStream | A generic, runtime independent, TcpStream |
Type Definitions
Result | Custom result returned by various ReQL commands |