RethinkDB.Query.ControlStructures
ReQL method for Control Structure operations.
All examples assume that use RethinkDB
has been called.
Summary↑
args(arg) | |
args(arg, opts) |
|
binary(binary) | Encapsulate binary data within a query |
binary(arg, opts) | |
branch(test, true_branch, false_branch) | If the |
coerce_to(left, right) | |
coerce_to(left, right, opts) | Convert a value of one type into another |
default(left, right) | |
default(left, right, opts) | Handle non-existence errors. Tries to evaluate and return its first argument. If an error related to the absence of a value is thrown in the process, or if its first argument returns nil, returns its second argument. (Alternatively, the second argument may be a function which will be called with either the text of the non-existence error or nil.) |
do_r(arg) | |
do_r(arg, opts) | Call an anonymous function using return values from other ReQL commands or queries as arguments |
error(arg) | |
error(arg, opts) | Throw a runtime error |
for_each(left, right) | |
for_each(left, right, opts) | Loop over a sequence, evaluating the given write query for each element |
http(url, opts \\ %{}) | Retrieve data from the specified URL over HTTP. The return type depends on the result_format option, which checks the Content-Type of the response by default |
info(arg) | |
info(arg, opts) | Get information about a ReQL value |
js(arg) | |
js(arg, opts) | Create a javascript expression |
json(arg) | |
json(arg, opts) | Parse a JSON string on the server |
type_of(arg) | |
type_of(arg, opts) | Gets the type of a value |
uuid() | Return a UUID (universally unique identifier), a string that can be used as a unique ID |
Functions
Specs:
- args(RethinkDB.Q.reql_array) :: RethinkDB.Q.t
args
is a special term that’s used to splice an array of arguments into
another term. This is useful when you want to call a variadic term such as
get_all
with a set of arguments produced at runtime.
This is analogous to Elixir’s apply
.
Specs:
- binary(RethinkDB.Q.reql_binary) :: RethinkDB.Q.t
Encapsulate binary data within a query.
Only a limited subset of ReQL commands may be chained after binary:
- coerce_to can coerce binary objects to string types
- count will return the number of bytes in the object
- slice will treat bytes like array indexes (i.e., slice(10,20) will return bytes
- 10–19)
- type_of returns PTYPE
- info will return information on a binary object.
Specs:
If the test
expression returns False or None, the false_branch will be
evaluated. Otherwise, the true_branch will be evaluated.
The branch command is effectively an if renamed due to language constraints.
Specs:
- coerce_to(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Convert a value of one type into another.
- a sequence, selection or object can be coerced to an array
- an array of key-value pairs can be coerced to an object
- a string can be coerced to a number
- any datum (single value) can be coerced to a string
- a binary object can be coerced to a string and vice-versa
Specs:
- default(RethinkDB.Q.t, RethinkDB.Q.t) :: RethinkDB.Q.t
Handle non-existence errors. Tries to evaluate and return its first argument. If an error related to the absence of a value is thrown in the process, or if its first argument returns nil, returns its second argument. (Alternatively, the second argument may be a function which will be called with either the text of the non-existence error or nil.)
Specs:
Call an anonymous function using return values from other ReQL commands or queries as arguments.
The last argument to do (or, in some forms, the only argument) is an expression or an anonymous function which receives values from either the previous arguments or from prefixed commands chained before do. The do command is essentially a single-element map, letting you map a function over just one document. This allows you to bind a query result to a local variable within the scope of do, letting you compute the result just once and reuse it in a complex expression or in a series of ReQL commands.
Arguments passed to the do function must be basic data types, and cannot be streams or selections. (Read about ReQL data types.) While the arguments will all be evaluated before the function is executed, they may be evaluated in any order, so their values should not be dependent on one another. The type of do’s result is the type of the value returned from the function or last expression.
Specs:
- error(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Throw a runtime error.
Specs:
- for_each(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Loop over a sequence, evaluating the given write query for each element.
Specs:
Retrieve data from the specified URL over HTTP. The return type depends on the result_format option, which checks the Content-Type of the response by default.
Specs:
- info(RethinkDB.Q.t) :: RethinkDB.Q.t
Get information about a ReQL value.
Specs:
Create a javascript expression.
timeout
is the number of seconds before js
times out. The default value
is 5 seconds.
Specs:
- json(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Parse a JSON string on the server.
Specs:
- type_of(RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Gets the type of a value.
Specs:
- uuid :: RethinkDB.Q.t
Return a UUID (universally unique identifier), a string that can be used as a unique ID.