RethinkDB.Query
Querying API for RethinkDB
Summary
Functions
Add multiple values
Sum two numbers, concatenate two strings, or concatenate 2 arrays
Compute the logical “and” of all values in a list
Compute the logical “and” of two values
Append a value to an array
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
Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error
Get all documents between two keys. Accepts three optional arguments: index, left_bound, and right_bound. If index is set to the name of a secondary index, between will return all documents where that index’s value is in the specified range (it uses the primary key by default). left_bound or right_bound may be set to open or closed to indicate whether or not to include that endpoint of the range (by default, left_bound is closed and right_bound is open)
Encapsulate binary data within a query
If the test
expression returns False or None, the false_branch will be
evaluated. Otherwise, the true_branch will be evaluated
Rounds the given value up, returning the smallest integer value greater than or equal to the given value (the value’s ceiling)
Change a value in an array at a given index. Returns the modified array
Construct a circular line or polygon. A circle in RethinkDB is a polygon or line approximating a circle of a given radius around a given center, consisting of a specified number of vertices (default 32)
Convert a value of one type into another
When called with values, returns true
if a sequence contains all the specified
values. When called with predicate functions, returns true
if for each
predicate there exists at least one element of the stream where that predicate
returns true
Counts the number of elements in a sequence. If called with a value, counts
the number of times that value occurs in the sequence. If called with a
predicate function, counts the number of elements in the sequence where that
function returns true
Return a new time object only based on the day, month and year (ie. the same day at 00:00)
Return the day of a time object as a number between 1 and 31
Return the day of week of a time object as a number between 1 and 7 (following ISO 8601 standard)
Return the day of the year of a time object as a number between 1 and 366 (following ISO 8601 standard)
Reference a database
Create a database. A RethinkDB database is a collection of tables, similar to relational databases
Drop a database. The database, all its tables, and corresponding data will be deleted
List all database names in the system. The result is a list of strings
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.)
Delete one or more documents from a table
Remove one or more elements from an array at a given index. Returns the modified array
Remove the elements of one array from another array
Compute the distance between a point and another geometry object. At least one of the geometry objects specified must be a point
Removes duplicates from elements in a sequence
Divide a list of numbers. Left associative
Divide two numbers
Call an anonymous function using return values from other ReQL commands or queries as arguments
Convert a string to all down case
Return if a time is between two other times (by default, inclusive for the start, exclusive for the end)
Create a time object based on seconds since epoch. The first argument is a double and will be rounded to three decimal places (millisecond-precision)
Test if all values in a list are equal
Test if two values are equal
Join tables using a field on the left-hand sequence matching primary keys or
secondary indexes on the right-hand table. eq_join
is more efficient than other
ReQL join types, and operates much faster. Documents in the result set consist
of pairs of left-hand and right-hand documents, matched when the field on the
left-hand side exists and is non-null and an entry with that field’s value
exists in the specified index on the right-hand side
Throw a runtime error
Convert a Line object into a Polygon object. If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them
Get all the documents for which the given predicate is true
Concatenate one or more elements into a single sequence using a mapping function
Rounds the given value down, returning the largest integer value less than or equal to the given value (the value’s floor)
Loop over a sequence, evaluating the given write query for each element
Test if all values in a list are greater than or equal to the next. Left associative
Test if one value is greater than or equal to the other
Convert a GeoJSON object to a ReQL geometry object
Get a document by primary key
Get all documents where the given value matches the value of the requested index
Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it
Get all documents where the given geometry object intersects the geometry object of the requested geospatial index
Get all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers)
Takes a stream and partitions it into multiple groups based on the fields or functions provided
Test if all values in a list are greater than the next. Left associative
Test if one value is greater than the other
Test if an object has one or more fields. An object has a field if it has that key and the key has a non-null value. For instance, the object {‘a’: 1,’b’: 2,’c’: null} has the fields a and b
Return the hour in a time object as a number between 0 and 23
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
Return a new time object with a different timezone. While the time stays the same, the results returned by methods such as hours() will change since they take the timezone into account. The timezone argument has to be of the ISO 8601 format
Tests whether a geometry object is completely contained within another. When applied to a sequence of geometry objects, includes acts as a filter, returning a sequence of objects from the sequence that include the argument
Create a new secondary index on a table. Secondary indexes improve the speed of many read queries at the slight cost of increased storage space and decreased write performance. For more information about secondary indexes, read the article “Using secondary indexes in RethinkDB.”
Delete a previously created secondary index of this table
List all the secondary indexes of this table
Rename an existing secondary index on a table. If the optional argument overwrite is specified as true, a previously existing index with the new name will be deleted and the index will be renamed. If overwrite is false (the default) an error will be raised if the new index name already exists
Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified
Wait for the specified indexes on this table to be ready, or for all indexes on this table to be ready if no indexes are specified
Get information about a ReQL value
Returns an inner join of two sequences. The returned sequence represents an
intersection of the left-hand sequence and the right-hand sequence: each row of
the left-hand sequence will be compared with each row of the right-hand
sequence to find all pairs of rows which satisfy the predicate. Each matched
pair of rows of both sequences are combined into a result row. In most cases,
you will want to follow the join with zip
to combine the left and right results
Insert documents into a table. Accepts a single document or an array of documents
Insert a value in to an array at a given index. Returns the modified array
Tests whether two geometry objects intersect with one another. When applied to a sequence of geometry objects, intersects acts as a filter, returning a sequence of objects from the sequence that intersect with the argument
Test if a sequence is empty
Create a time object based on an ISO 8601 date-time string (e.g. ‘2013-01-01T01:01:01+00:00’). We support all valid ISO 8601 formats except for week dates. If you pass an ISO 8601 date-time without a time zone, you must specify the time zone with the default_timezone argument
Create a javascript expression
Parse a JSON string on the server
Return an array containing all of the object’s keys
Test if all values in a list are less than or equal to the next. Left associative
Test if one value is less than or equal to the other
End the sequence after the given number of elements
Construct a geometry object of type Line. The line can be specified in one of two ways:
Replace an object in a field instead of merging it with an existing object in a merge or update operation
Test if all values in a list are less than the next. Left associative
Test if one value is less than the other
Transform each element of one or more sequences by applying a mapping function to them. If map is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence
Checks a string for matches
Finds the maximum element of a sequence. The max command can be called with:
Merge two or more objects together to construct a new object with properties from all. When there is a conflict between field names, preference is given to fields in the rightmost object in the argument list
Finds the minimum element of a sequence. The min command can be called with:
Return the minute in a time object as a number between 0 and 59
Find the remainder when dividing two numbers
Return the month of a time object as a number between 1 and 12
Multiply multiple values
Multiply two numbers, or make a periodic array
Test if all values in a list are not equal
Test if two values are not equal
Compute the logical inverse (not) of an expression
Return a time object representing the current time in UTC. The command now() is computed once when the server receives the query, so multiple instances of r.now() will always return the same time inside a query
Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element
Creates an object from a list of key-value pairs, where the keys must be strings. r.object(A, B, C, D) is equivalent to r.expr([[A, B], [C, D]]).coerce_to(‘OBJECT’)
Get the indexes of an element in a sequence. If the argument is a predicate, get the indexes of all elements matching it
Compute the logical “or” of all values in a list
Compute the logical “or” of two values
Sort the sequence by document values of the given key(s). To specify the ordering, wrap the attribute with either r.asc or r.desc (defaults to ascending)
Returns a left outer join of two sequences. The returned sequence represents
a union of the left-hand sequence and the right-hand sequence: all documents in
the left-hand sequence will be returned, each matched with a document in the
right-hand sequence if one satisfies the predicate condition. In most cases,
you will want to follow the join with zip
to combine the left and right results
Plucks out one or more attributes from either an object or a sequence of objects (projection)
Construct a geometry object of type Point. The point is specified by two floating point numbers, the longitude (−180 to 180) and latitude (−90 to 90) of the point on a perfect sphere
Construct a geometry object of type Polygon. The Polygon can be specified in one of two ways:
Use polygon2 to “punch out” a hole in polygon1. polygon2 must be completely contained within polygon1 and must have no holes itself (it must not be the output of polygon_sub itself)
Prepend a value to an array
Generate a random float between 0 and 1
Generate a random value in the range [0,upper). If upper is an integer then the random value will be an integer. If upper is a float it will be a float
Generate a random value in the range [lower,upper). If either arg is an integer then the random value will be an interger. If one of them is a float it will be a float
Generate a stream of sequential integers in a specified range
Produce a single value from a sequence through repeated application of a reduction function
Replace documents in a table. Accepts a JSON document or a ReQL expression, and replaces the original document with the new one. The new document must have the same primary key as the original document
Rounds the given value to the nearest whole integer
Select a given number of elements from a sequence with uniform random distribution. Selection is done without replacement
Return the seconds in a time object as a number between 0 and 59.999 (double precision)
Remove the elements of one array from another and return them as a set (an array with distinct values)
Add a value to an array and return it as a set (an array with distinct values)
Intersect two arrays returning values that occur in both of them as a set (an array with distinct values)
Add a several values to an array and return it as a set (an array with distinct values)
Skip a number of elements from the head of the sequence
Return the elements of a sequence within the specified range
Insert several values in to an array at a given index. Returns the modified array
Split a string
on whitespace
Split a string
on separator
Split a string
with a given separator
into max_result
segments
Subtract multiple values. Left associative
Subtract two numbers
Sums all the elements of a sequence. If called with a field name, sums all
the values of that field in the sequence, skipping elements of the sequence
that lack that field. If called with a function, calls that function on every
element of the sequence and sums the results, skipping elements of the sequence
where that function returns nil
or a non-existence error
sync ensures that writes on a given table are written to permanent storage. Queries that specify soft durability (durability=’soft’) do not give such guarantees, so sync can be used to ensure the state of these queries. A call to sync does not return until all previous writes to the table are persisted
Return all documents in a table. Other commands may be chained after table to return a subset of documents (such as get and filter) or perform further processing
Create a table. A RethinkDB table is a collection of JSON documents
Drop a table. The table and all its data will be deleted
List all table names in a database. The result is a list of strings
Create a time object for a specific time
Return the number of seconds elapsed since the beginning of the day stored in the time object
Return the timezone of the time object
Convert a time object to its epoch time
Convert a ReQL geometry object to a GeoJSON object
Convert a time object to a string in ISO 8601 format
Serialize to JSON string on the server
Gets the type of a value
Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after ungroup will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction
Concatenate two or more sequences
Convert a string to all upper case
Update JSON documents in a table. Accepts a JSON document, a ReQL expression, or a combination of the two
Return a UUID (universally unique identifier), a string that can be used as a unique ID
Return an array containing all of the object’s values
Plucks one or more attributes from a sequence of objects, filtering out any objects in the sequence that do not have the specified fields. Functionally, this is identical to has_fields followed by pluck on a sequence
The opposite of pluck; takes an object or a sequence of objects, and returns them with the specified paths removed
Return the year of a time object
Used to ‘zip’ up the result of a join by merging the ‘right’ fields into ‘left’ fields of each member of the sequence
Types
reql_array :: [term] | t
reql_binary ::
%RethinkDB.Pseudotypes.Binary{data: term} |
binary |
t
reql_datum :: term
reql_func0 :: (() -> term) | t
reql_func1 :: (term -> term) | t
reql_func2 :: (term, term -> term) | t
reql_geo_line ::
%RethinkDB.Pseudotypes.Geometry.Line{coordinates: term} |
t
reql_geo_point ::
%RethinkDB.Pseudotypes.Geometry.Point{coordinates: term} |
{reql_number, reql_number} |
t
reql_geo_polygon ::
%RethinkDB.Pseudotypes.Geometry.Polygon{inner_coordinates: term, outer_coordinates: term} |
t
reql_number :: integer | float | t
reql_opts :: %{}
reql_string :: String.t | t
t :: %RethinkDB.Q{query: term}
Functions
Specs
add([RethinkDB.Q.reql_number | RethinkDB.Q.reql_string | RethinkDB.Q.reql_array]) :: RethinkDB.Q.t
Add multiple values.
iex> add([1, 2]) |> run conn
%RethinkDB.Record{data: 3}
iex> add(["hello", " world"]) |> run
%RethinkDB.Record{data: "hello world"}
Specs
add(RethinkDB.Q.reql_number | RethinkDB.Q.reql_string, RethinkDB.Q.reql_number | RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Sum two numbers, concatenate two strings, or concatenate 2 arrays.
iex> add(1, 2) |> run conn
%RethinkDB.Record{data: 3}
iex> add("hello", " world") |> run conn
%RethinkDB.Record{data: "hello world"}
iex> add([1,2], [3,4]) |> run conn
%RethinkDB.Record{data: [1,2,3,4]}
Specs
and_r([RethinkDB.Q.reql_bool]) :: RethinkDB.Q.t
Compute the logical “and” of all values in a list.
iex> and_r([true, true, true]) |> run conn
%RethinkDB.Record{data: true}
iex> and_r([false, true, true]) |> run conn
%RethinkDB.Record{data: false}
Specs
and_r(RethinkDB.Q.reql_bool, RethinkDB.Q.reql_bool) :: RethinkDB.Q.t
Compute the logical “and” of two values.
iex> and(true, true) |> run conn
%RethinkDB.Record{data: true}
iex> and(false, true) |> run conn
%RethinkDB.Record{data: false}
Specs
append(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Append a value to an array.
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
avg(RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error.
Produces a non-existence error when called on an empty sequence. You can
handle this case with default
.
Specs
avg(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Specs
between(RethinkDB.Q.reql_array, RethinkDB.Q.t, RethinkDB.Q.t) :: RethinkDB.Q.t
Get all documents between two keys. Accepts three optional arguments: index, left_bound, and right_bound. If index is set to the name of a secondary index, between will return all documents where that index’s value is in the specified range (it uses the primary key by default). left_bound or right_bound may be set to open or closed to indicate whether or not to include that endpoint of the range (by default, left_bound is closed and right_bound is open).
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
branch(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
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
ceil(RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Rounds the given value up, returning the smallest integer value greater than or equal to the given value (the value’s ceiling).
Specs
change_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Change a value in an array at a given index. Returns the modified array.
Construct a circular line or polygon. A circle in RethinkDB is a polygon or line approximating a circle of a given radius around a given center, consisting of a specified number of vertices (default 32).
The center may be specified either by two floating point numbers, the latitude (−90 to 90) and longitude (−180 to 180) of the point on a perfect sphere (see Geospatial support for more information on ReQL’s coordinate system), or by a point object. The radius is a floating point number whose units are meters by default, although that may be changed with the unit argument.
Optional arguments available with circle are:
- num_vertices: the number of vertices in the polygon or line. Defaults to 32.
- geo_system: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.
- unit: Unit for the radius distance. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).
- fill: if
true
(the default) the circle is filled, creating a polygon; iffalse
the circle is unfilled (creating a line).
Specs
circle(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_number, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
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
contains(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_func1 | RethinkDB.Q.t) :: RethinkDB.Q.t
When called with values, returns true
if a sequence contains all the specified
values. When called with predicate functions, returns true
if for each
predicate there exists at least one element of the stream where that predicate
returns true
.
Specs
count(RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Counts the number of elements in a sequence. If called with a value, counts
the number of times that value occurs in the sequence. If called with a
predicate function, counts the number of elements in the sequence where that
function returns true
.
If count is called on a binary object, it will return the size of the object in bytes.
Specs
count(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Specs
date(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return a new time object only based on the day, month and year (ie. the same day at 00:00).
Specs
day(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the day of a time object as a number between 1 and 31.
Specs
day_of_week(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the day of week of a time object as a number between 1 and 7 (following ISO 8601 standard).
Specs
day_of_year(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the day of the year of a time object as a number between 1 and 366 (following ISO 8601 standard).
Specs
db_create(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Create a database. A RethinkDB database is a collection of tables, similar to relational databases.
If successful, the command returns an object with two fields:
- dbs_created: always 1.
- config_changes: a list containing one object with two fields, old_val and new_val:
- old_val: always null.
- new_val: the database’s new config value.
If a database with the same name already exists, the command throws RqlRuntimeError.
Note: Only alphanumeric characters and underscores are valid for the database name.
Specs
db_drop(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Drop a database. The database, all its tables, and corresponding data will be deleted.
If successful, the command returns an object with two fields:
- dbs_dropped: always 1.
- tables_dropped: the number of tables in the dropped database.
- config_changes: a list containing one two-field object, old_val and new_val:
- old_val: the database’s original config value.
- new_val: always None.
If the given database does not exist, the command throws RqlRuntimeError.
Specs
db_list :: RethinkDB.Q.t
List all database names in the system. The result is a list of strings.
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
delete(RethinkDB.Q.t) :: RethinkDB.Q.t
Delete one or more documents from a table.
The optional arguments are:
- durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
- return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
Delete returns an object that contains the following attributes:
- deleted: the number of documents that were deleted.
- skipped: the number of documents that were skipped. For example, if you attempt to delete a batch of documents, and another concurrent query deletes some of those documents first, they will be counted as skipped.
- errors: the number of errors encountered while performing the delete.
- first_error: If errors were encountered, contains the text of the first error. inserted, replaced, and unchanged: all 0 for a delete operation.
- changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the delete operation. Each object will have
- two keys: {“new_val”: None, “old_val”:
}.
Remove one or more elements from an array at a given index. Returns the modified array.
Specs
delete_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Specs
difference(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Remove the elements of one array from another array.
Compute the distance between a point and another geometry object. At least one of the geometry objects specified must be a point.
Optional arguments available with distance are:
- geo_system: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.
- unit: Unit to return the distance in. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).
If one of the objects is a polygon or a line, the point will be projected onto the line or polygon assuming a perfect sphere model before the distance is computed (using the model specified with geo_system). As a consequence, if the polygon or line is extremely large compared to Earth’s radius and the distance is being computed with the default WGS84 model, the results of distance should be considered approximate due to the deviation between the ellipsoid and spherical models.
Specs
distance(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Removes duplicates from elements in a sequence.
The distinct command can be called on any sequence, a table, or called on a table with an index.
Specs
divide([RethinkDB.Q.reql_number]) :: RethinkDB.Q.t
Divide a list of numbers. Left associative.
iex> divide([12, 2, 3]) |> run conn
%RethinkDB.Record{data: 2}
Specs
divide(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Divide two numbers.
iex> divide(12, 4) |> run conn
%RethinkDB.Record{data: 3}
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
do_r(RethinkDB.Q.reql_datum | RethinkDB.Q.reql_func0, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Specs
downcase(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Convert a string to all down case.
iex> "Hi" |> downcase |> run conn
%RethinkDB.Record{data: "hi"}
Specs
during(RethinkDB.Q.reql_time, RethinkDB.Q.reql_time, RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return if a time is between two other times (by default, inclusive for the start, exclusive for the end).
Specs
epoch_time(reql_number) :: RethinkDB.Q.t
Create a time object based on seconds since epoch. The first argument is a double and will be rounded to three decimal places (millisecond-precision).
Specs
eq([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t
Test if all values in a list are equal.
iex> eq([2, 2, 2]) |> run conn
%RethinkDB.Record{data: true}
iex> eq([2, 1, 2]) |> run conn
%RethinkDB.Record{data: false}
Specs
eq(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Test if two values are equal.
iex> eq(1,1) |> run conn
%RethinkDB.Record{data: true}
iex> eq(1, 2) |> run conn
%RethinkDB.Record{data: false}
Join tables using a field on the left-hand sequence matching primary keys or
secondary indexes on the right-hand table. eq_join
is more efficient than other
ReQL join types, and operates much faster. Documents in the result set consist
of pairs of left-hand and right-hand documents, matched when the field on the
left-hand side exists and is non-null and an entry with that field’s value
exists in the specified index on the right-hand side.
The result set of eq_join
is a stream or array of objects. Each object in the
returned set will be an object of the form `{ left: <left-document>, right:
<right-document> }`, where the values of left and right will be the joined
documents. Use the zip command to merge the left and right fields together.
iex> table("people") |> eq_join(
"id", table("phone_numbers"), %{index: "person_id"}
) |> run
Specs
eq_join(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string, RethinkDB.Q.reql_array, %{}) :: RethinkDB.Q.t
Specs
fill(RethinkDB.Q.reql_line) :: RethinkDB.Q.t
Convert a Line object into a Polygon object. If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them.
Specs
filter(RethinkDB.Q.reql_array, RethinkDB.Q.t) :: RethinkDB.Q.t
Get all the documents for which the given predicate is true.
filter can be called on a sequence, selection, or a field containing an array of elements. The return type is the same as the type on which the function was called on.
The body of every filter is wrapped in an implicit .default(False), which means that if a non-existence errors is thrown (when you try to access a field that does not exist in a document), RethinkDB will just ignore the document. The default value can be changed by passing the named argument default. Setting this optional argument to r.error() will cause any non-existence errors to return a RqlRuntimeError.
Specs
flat_map(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Concatenate one or more elements into a single sequence using a mapping function.
Specs
floor(RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Rounds the given value down, returning the largest integer value less than or equal to the given value (the value’s floor).
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
ge([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t
Test if all values in a list are greater than or equal to the next. Left associative.
iex> le([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}
iex> le([10, 4, 4]) |> run conn
%RethinkDB.Record{data: true}
Specs
ge(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Test if one value is greater than or equal to the other.
iex> ge(1,1) |> run conn
%RethinkDB.Record{data: true}
iex> ge(2, 1) |> run conn
%RethinkDB.Record{data: true}
Specs
geojson(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t
Convert a GeoJSON object to a ReQL geometry object.
RethinkDB only allows conversion of GeoJSON objects which have ReQL equivalents: Point, LineString, and Polygon. MultiPoint, MultiLineString, and MultiPolygon are not supported. (You could, however, store multiple points, lines and polygons in an array and use a geospatial multi index with them.)
Only longitude/latitude coordinates are supported. GeoJSON objects that use Cartesian coordinates, specify an altitude, or specify their own coordinate reference system will be rejected.
Specs
get(RethinkDB.Q.t, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Get a document by primary key.
If no document exists with that primary key, get will return nil.
Specs
get_all(RethinkDB.Q.t, RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Get all documents where the given value matches the value of the requested index.
Specs
get_field(RethinkDB.Q.reql_obj | RethinkDB.Q.reql_array, RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.
Get all documents where the given geometry object intersects the geometry object of the requested geospatial index.
The index argument is mandatory. This command returns the same results as
filter(r.row('index')) |> intersects(geometry)
. The total number of results
is limited to the array size limit which defaults to 100,000, but can be
changed with the array_limit
option to run.
Specs
get_intersecting(RethinkDB.Q.reql_array, RethinkDB.Q.reql_geo, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Get all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers).
The index argument is mandatory. Optional arguments are:
- max_results: the maximum number of results to return (default 100).
- unit: Unit for the distance. Possible values are m (meter, the default), km (kilometer), mi (international mile), nm (nautical mile), ft (international foot).
- max_dist: the maximum distance from an object to the specified point (default 100 km).
- geo_system: the reference ellipsoid to use for geographic coordinates. Possible values are WGS84 (the default), a common standard for Earth’s geometry, or unit_sphere, a perfect sphere of 1 meter radius.
The return value will be an array of two-item objects with the keys dist and doc, set to the distance between the specified point and the document (in the units specified with unit, defaulting to meters) and the document itself, respectively.
Specs
get_nearest(RethinkDB.Q.reql_array, RethinkDB.Q.reql_geo, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Specs
group(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1 | RethinkDB.Q.reql_string | [RethinkDB.Q.reql_func1 | RethinkDB.Q.reql_string]) :: RethinkDB.Q.t
Takes a stream and partitions it into multiple groups based on the fields or functions provided.
With the multi flag single documents can be assigned to multiple groups, similar to the behavior of multi-indexes. When multi is True and the grouping value is an array, documents will be placed in each group that corresponds to the elements of the array. If the array is empty the row will be ignored.
Specs
gt([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t
Test if all values in a list are greater than the next. Left associative.
iex> gt([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}
iex> gt([10, 4, 2]) |> run conn
%RethinkDB.Record{data: true}
Specs
gt(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Test if one value is greater than the other.
iex> gt(1,2) |> run conn
%RethinkDB.Record{data: false}
iex> gt(2,1) |> run conn
%RethinkDB.Record{data: true}
Specs
has_fields(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Test if an object has one or more fields. An object has a field if it has that key and the key has a non-null value. For instance, the object {‘a’: 1,’b’: 2,’c’: null} has the fields a and b.
Specs
hours(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the hour in a time object as a number between 0 and 23.
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
in_timezone(RethinkDB.Q.reql_time, RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Return a new time object with a different timezone. While the time stays the same, the results returned by methods such as hours() will change since they take the timezone into account. The timezone argument has to be of the ISO 8601 format.
Specs
includes(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo) :: RethinkDB.Q.t
Tests whether a geometry object is completely contained within another. When applied to a sequence of geometry objects, includes acts as a filter, returning a sequence of objects from the sequence that include the argument.
Create a new secondary index on a table. Secondary indexes improve the speed of many read queries at the slight cost of increased storage space and decreased write performance. For more information about secondary indexes, read the article “Using secondary indexes in RethinkDB.”
RethinkDB supports different types of secondary indexes:
- Simple indexes based on the value of a single field.
- Compound indexes based on multiple fields.
- Multi indexes based on arrays of values.
- Geospatial indexes based on indexes of geometry objects, created when the geo optional argument is true.
- Indexes based on arbitrary expressions.
The index_function can be an anonymous function or a binary representation obtained from the function field of index_status.
If successful, create_index will return an object of the form {:created => 1}. If an index by that name already exists on the table, a RqlRuntimeError will be thrown.
Specs
index_create(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_func1, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Specs
index_drop(RethinkDB.Q.t, RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Delete a previously created secondary index of this table.
Specs
index_list(RethinkDB.Q.t) :: RethinkDB.Q.t
List all the secondary indexes of this table.
Rename an existing secondary index on a table. If the optional argument overwrite is specified as true, a previously existing index with the new name will be deleted and the index will be renamed. If overwrite is false (the default) an error will be raised if the new index name already exists.
The return value on success will be an object of the format {:renamed => 1}, or {:renamed => 0} if the old and new names are the same.
An error will be raised if the old index name does not exist, if the new index name is already in use and overwrite is false, or if either the old or new index name are the same as the primary key field name.
Specs
index_rename(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified.
Specs
index_status(RethinkDB.Q.t, RethinkDB.Q.reql_string | RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Wait for the specified indexes on this table to be ready, or for all indexes on this table to be ready if no indexes are specified.
Specs
index_wait(RethinkDB.Q.t, RethinkDB.Q.reql_string | RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Specs
inner_join(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array, RethinkDB.Q.reql_func2) :: RethinkDB.Q.t
Returns an inner join of two sequences. The returned sequence represents an
intersection of the left-hand sequence and the right-hand sequence: each row of
the left-hand sequence will be compared with each row of the right-hand
sequence to find all pairs of rows which satisfy the predicate. Each matched
pair of rows of both sequences are combined into a result row. In most cases,
you will want to follow the join with zip
to combine the left and right results.
Note that inner_join
is slower and much less efficient than using eqJoin
or
flat_map
with get_all
. You should avoid using inner_join
in commands when
possible.
iex> table("people") |> inner_join(
table("phone_numbers"), &(eq(&1["id"], &2["person_id"])
) |> run
Insert documents into a table. Accepts a single document or an array of documents.
The optional arguments are:
- durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode Rethink_dB will acknowledge the write immediately after receiving and caching it, but before the write has been committed to disk.
- return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
- conflict: Determine handling of inserting documents with the same primary key as existing entries. Possible values are “error”, “replace” or “update”.
- “error”: Do not insert the new document and record the conflict as an error. This is the default.
- “replace”: Replace the old document in its entirety with the new one.
- “update”: Update fields of the old document with fields from the new one.
Insert returns an object that contains the following attributes:
- inserted: the number of documents successfully inserted.
- replaced: the number of documents updated when conflict is set to “replace” or “update”.
- unchanged: the number of documents whose fields are identical to existing documents with the same primary key when conflict is set to “replace” or “update”.
- errors: the number of errors encountered while performing the insert.
- first_error: If errors were encountered, contains the text of the first error.
- deleted and skipped: 0 for an insert operation.
- generated_keys: a list of generated primary keys for inserted documents whose primary keys were not specified (capped to 100,000).
- warnings: if the field generated_keys is truncated, you will get the warning
“Too many generated keys (
), array truncated to 100000.”. - changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the insert operation. Each object will have
- two keys: {“new_val”:
, “old_val”: None}.
Specs
insert(RethinkDB.Q.t, RethinkDB.Q.reql_obj | RethinkDB.Q.reql_array, %{}) :: RethinkDB.Q.t
Specs
insert_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Insert a value in to an array at a given index. Returns the modified array.
Specs
intersects(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo) :: RethinkDB.Q.t
Tests whether two geometry objects intersect with one another. When applied to a sequence of geometry objects, intersects acts as a filter, returning a sequence of objects from the sequence that intersect with the argument.
Specs
iso8601(reql_string) :: RethinkDB.Q.t
Create a time object based on an ISO 8601 date-time string (e.g. ‘2013-01-01T01:01:01+00:00’). We support all valid ISO 8601 formats except for week dates. If you pass an ISO 8601 date-time without a time zone, you must specify the time zone with the default_timezone argument.
Create a javascript expression.
The only opt allowed is timeout
.
timeout
is the number of seconds before js
times out. The default value
is 5 seconds.
Specs
keys(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t
Return an array containing all of the object’s keys.
Specs
le([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t
Test if all values in a list are less than or equal to the next. Left associative.
iex> le([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}
iex> le([1, 4, 4]) |> run conn
%RethinkDB.Record{data: true}
Specs
le(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Test if one value is less than or equal to the other.
iex> le(1,1) |> run conn
%RethinkDB.Record{data: true}
iex> le(1, 2) |> run conn
%RethinkDB.Record{data: true}
Specs
limit(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
End the sequence after the given number of elements.
Specs
line([RethinkDB.Q.reql_geo]) :: RethinkDB.Q.t
Construct a geometry object of type Line. The line can be specified in one of two ways:
- Two or more two-item arrays, specifying latitude and longitude numbers of the line’s vertices;
- Two or more Point objects specifying the line’s vertices.
Specs
literal(RethinkDB.Q.reql_object) :: RethinkDB.Q.t
Replace an object in a field instead of merging it with an existing object in a merge or update operation.
Specs
lt([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t
Test if all values in a list are less than the next. Left associative.
iex> lt([1, 4, 2]) |> run conn
%RethinkDB.Record{data: false}
iex> lt([1, 4, 5]) |> run conn
%RethinkDB.Record{data: true}
Specs
lt(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Test if one value is less than the other.
iex> lt(2,1) |> run conn
%RethinkDB.Record{data: false}
iex> lt(1, 2) |> run conn
%RethinkDB.Record{data: true}
Specs
map(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Transform each element of one or more sequences by applying a mapping function to them. If map is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence.
Note that map can only be applied to sequences, not single values. If you wish to apply a function to a single value/selection (including an array), use the do command.
Specs
match(RethinkDB.Q.reql_string, Regex.t | RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Checks a string for matches.
Example:
iex> "hello world" |> match("hello") |> run conn
iex> "hello world" |> match(~r(hello)) |> run conn
Finds the maximum element of a sequence. The max command can be called with:
- a field name, to return the element of the sequence with the smallest value in that field;
- an index, to return the element of the sequence with the smallest value in that index;
- a function, to apply the function to every element within the sequence and return the element which returns the smallest value from the function, ignoring any elements where the function returns None or produces a non-existence error.
Calling max on an empty sequence will throw a non-existence error; this can be
handled using the default
command.
Specs
max(RethinkDB.Q.reql_array, RethinkDB.Q.reql_opts | RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Specs
merge(RethinkDB.Q.reql_array, RethinkDB.Q.reql_object | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Merge two or more objects together to construct a new object with properties from all. When there is a conflict between field names, preference is given to fields in the rightmost object in the argument list.
Finds the minimum element of a sequence. The min command can be called with:
- a field name, to return the element of the sequence with the smallest value in that field;
- an index option, to return the element of the sequence with the smallest value in that index;
- a function, to apply the function to every element within the sequence and return the element which returns the smallest value from the function, ignoring any elements where the function returns None or produces a non-existence error.
Calling min on an empty sequence will throw a non-existence error; this can be
handled using the default
command.
Specs
min(RethinkDB.Q.reql_array, RethinkDB.Q.reql_opts | RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Specs
minutes(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the minute in a time object as a number between 0 and 59.
Specs
mod(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Find the remainder when dividing two numbers.
iex> mod(23, 4) |> run conn
%RethinkDB.Record{data: 3}
Specs
month(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the month of a time object as a number between 1 and 12.
Specs
mul([RethinkDB.Q.reql_number | RethinkDB.Q.reql_array]) :: RethinkDB.Q.t
Multiply multiple values.
iex> mul([2,3,4]) |> run conn
%RethinkDB.Record{data: 24}
Specs
mul(RethinkDB.Q.reql_number | RethinkDB.Q.reql_array, RethinkDB.Q.reql_number | RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Multiply two numbers, or make a periodic array.
iex> mul(2,3) |> run conn
%RethinkDB.Record{data: 6}
iex> mul([1,2], 2) |> run conn
%RethinkDB.Record{data: [1,2,1,2]}
Specs
ne([RethinkDB.Q.reql_datum]) :: RethinkDB.Q.t
Test if all values in a list are not equal.
iex> ne([2, 2, 2]) |> run conn
%RethinkDB.Record{data: false}
iex> ne([2, 1, 2]) |> run conn
%RethinkDB.Record{data: true}
Specs
ne(RethinkDB.Q.reql_datum, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Test if two values are not equal.
iex> ne(1,1) |> run conn
%RethinkDB.Record{data: false}
iex> ne(1, 2) |> run conn
%RethinkDB.Record{data: true}
Specs
not_r(RethinkDB.Q.reql_bool) :: RethinkDB.Q.t
Compute the logical inverse (not) of an expression.
iex> not(true) |> run conn
%RethinkDB.Record{data: false}
Specs
now :: RethinkDB.Q.t
Return a time object representing the current time in UTC. The command now() is computed once when the server receives the query, so multiple instances of r.now() will always return the same time inside a query.
Specs
nth(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element.
Specs
object(RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Creates an object from a list of key-value pairs, where the keys must be strings. r.object(A, B, C, D) is equivalent to r.expr([[A, B], [C, D]]).coerce_to(‘OBJECT’).
Specs
offsets_of(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Get the indexes of an element in a sequence. If the argument is a predicate, get the indexes of all elements matching it.
Specs
or_r([RethinkDB.Q.reql_bool]) :: RethinkDB.Q.t
Compute the logical “or” of all values in a list.
iex> or_r([true, true, true]) |> run conn
%RethinkDB.Record{data: true}
iex> or_r([false, true, true]) |> run conn
%RethinkDB.Record{data: false}
Specs
or_r(RethinkDB.Q.reql_bool, RethinkDB.Q.reql_bool) :: RethinkDB.Q.t
Compute the logical “or” of two values.
iex> or_r(true, false) |> run conn
%RethinkDB.Record{data: true}
iex> or_r(false, false) |> run conn
%RethinkDB.Record{data: false}
Sort the sequence by document values of the given key(s). To specify the ordering, wrap the attribute with either r.asc or r.desc (defaults to ascending).
Sorting without an index requires the server to hold the sequence in memory, and is limited to 100,000 documents (or the setting of the array_limit option for run). Sorting with an index can be done on arbitrarily large tables, or after a between command using the same index.
Specs
order_by(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Specs
outer_join(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array, RethinkDB.Q.reql_func2) :: RethinkDB.Q.t
Returns a left outer join of two sequences. The returned sequence represents
a union of the left-hand sequence and the right-hand sequence: all documents in
the left-hand sequence will be returned, each matched with a document in the
right-hand sequence if one satisfies the predicate condition. In most cases,
you will want to follow the join with zip
to combine the left and right results.
Note that outer_join
is slower and much less efficient than using flat_map
with get_all
. You should avoid using outer_join
in commands when possible.
iex> table("people") |> outer_join(
table("phone_numbers"), &(eq(&1["id"], &2["person_id"])
) |> run
Specs
pluck(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Plucks out one or more attributes from either an object or a sequence of objects (projection).
Specs
point(RethinkDB.Q.reql_geo) :: RethinkDB.Q.t
Construct a geometry object of type Point. The point is specified by two floating point numbers, the longitude (−180 to 180) and latitude (−90 to 90) of the point on a perfect sphere.
Specs
polygon([RethinkDB.Q.reql_geo]) :: RethinkDB.Q.t
Construct a geometry object of type Polygon. The Polygon can be specified in one of two ways:
Three or more two-item arrays, specifying latitude and longitude numbers of the polygon’s vertices;
- Three or more Point objects specifying the polygon’s vertices.
- Longitude (−180 to 180) and latitude (−90 to 90) of vertices are plotted on a perfect sphere. See Geospatial support for more information on ReQL’s coordinate system.
If the last point does not specify the same coordinates as the first point, polygon will close the polygon by connecting them. You cannot directly construct a polygon with holes in it using polygon, but you can use polygon_sub to use a second polygon within the interior of the first to define a hole.
Specs
polygon_sub(RethinkDB.Q.reql_geo, RethinkDB.Q.reql_geo) :: RethinkDB.Q.t
Use polygon2 to “punch out” a hole in polygon1. polygon2 must be completely contained within polygon1 and must have no holes itself (it must not be the output of polygon_sub itself).
Specs
prepend(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Prepend a value to an array.
Specs
random :: RethinkDB.Q.t
Generate a random float between 0 and 1.
iex> random |> run conn
%RethinkDB.Record{data: 0.43}
Specs
random(RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Generate a random value in the range [0,upper). If upper is an integer then the random value will be an integer. If upper is a float it will be a float.
iex> random(5) |> run conn
%RethinkDB.Record{data: 3}
iex> random(5.0) |> run conn
%RethinkDB.Record{data: 3.7}
Specs
random(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Generate a random value in the range [lower,upper). If either arg is an integer then the random value will be an interger. If one of them is a float it will be a float.
iex> random(5, 10) |> run conn
%RethinkDB.Record{data: 8}
iex> random(5.0, 15.0,) |> run conn
%RethinkDB.Record{data: 8.34}
Generate a stream of sequential integers in a specified range.
range
takes 0, 1 or 2 arguments:
- With no arguments, range returns an “infinite” stream from 0 up to and including the maximum integer value;
- With one argument, range returns a stream from 0 up to but not including the end value;
- With two arguments, range returns a stream from the start value up to but not including the end value.
Specs
reconfigure(RethinkDB.Q.reql_term, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Specs
reduce(RethinkDB.Q.reql_array, RethinkDB.Q.reql_func2) :: RethinkDB.Q.t
Produce a single value from a sequence through repeated application of a reduction function.
The reduction function can be called on:
- two elements of the sequence
- one element of the sequence and one result of a previous reduction
- two results of previous reductions
The reduction function can be called on the results of two previous reductions because the reduce command is distributed and parallelized across shards and CPU cores. A common mistaken when using the reduce command is to suppose that the reduction is executed from left to right.
Replace documents in a table. Accepts a JSON document or a ReQL expression, and replaces the original document with the new one. The new document must have the same primary key as the original document.
The optional arguments are:
- durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
- return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
- non_atomic: if set to True, executes the replacement and distributes the result to replicas in a non-atomic fashion. This flag is required to perform non-deterministic updates, such as those that require reading data from another table.
Replace returns an object that contains the following attributes:
- replaced: the number of documents that were replaced
- unchanged: the number of documents that would have been modified, except that the new value was the same as the old value
- inserted: the number of new documents added. You can have new documents inserted if you do a point-replace on a key that isn’t in the table or you do a replace on a selection and one of the documents you are replacing has been deleted
- deleted: the number of deleted documents when doing a replace with None
- errors: the number of errors encountered while performing the replace.
- first_error: If errors were encountered, contains the text of the first error.
- skipped: 0 for a replace operation
- changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the replace operation. Each object will have
- two keys: {“new_val”:
, “old_val”: }.
Specs
round_r(RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Rounds the given value to the nearest whole integer.
For example, values of 1.0 up to but not including 1.5 will return 1.0, similar to floor; values of 1.5 up to 2.0 will return 2.0, similar to ceil.
Specs
sample(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Select a given number of elements from a sequence with uniform random distribution. Selection is done without replacement.
If the sequence has less than the requested number of elements (i.e., calling sample(10) on a sequence with only five elements), sample will return the entire sequence in a random order.
Specs
seconds(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the seconds in a time object as a number between 0 and 59.999 (double precision).
Specs
set_difference(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Remove the elements of one array from another and return them as a set (an array with distinct values).
Specs
set_insert(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Add a value to an array and return it as a set (an array with distinct values).
Specs
set_intersection(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Intersect two arrays returning values that occur in both of them as a set (an array with distinct values).
Specs
set_union(RethinkDB.Q.reql_array, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Add a several values to an array and return it as a set (an array with distinct values).
Specs
skip(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Skip a number of elements from the head of the sequence.
Specs
slice(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Return the elements of a sequence within the specified range.
Specs
splice_at(RethinkDB.Q.reql_array, RethinkDB.Q.reql_number, RethinkDB.Q.reql_datum) :: RethinkDB.Q.t
Insert several values in to an array at a given index. Returns the modified array.
Specs
split(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Split a string
on whitespace.
iex> "abracadabra" |> split |> run conn
%RethinkDB.Record{data: ["abracadabra"]}
Specs
split(RethinkDB.Q.reql_string, RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Split a string
on separator
.
iex> "abra-cadabra" |> split("-") |> run conn
%RethinkDB.Record{data: ["abra", "cadabra"]}
Specs
split(RethinkDB.Q.reql_string, RethinkDB.Q.reql_string | nil, integer) :: RethinkDB.Q.t
Split a string
with a given separator
into max_result
segments.
iex> "a-bra-ca-da-bra" |> split("-", 2) |> run conn
%RethinkDB.Record{data: ["a", "bra", "ca-da-bra"]}
Specs
sub([RethinkDB.Q.reql_number]) :: RethinkDB.Q.t
Subtract multiple values. Left associative.
iex> sub([9, 1, 2]) |> run conn
%RethinkDB.Record{data: 6}
Specs
sub(RethinkDB.Q.reql_number, RethinkDB.Q.reql_number) :: RethinkDB.Q.t
Subtract two numbers.
iex> sub(1, 2) |> run conn
%RethinkDB.Record{data: -1}
Specs
sum(RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Sums all the elements of a sequence. If called with a field name, sums all
the values of that field in the sequence, skipping elements of the sequence
that lack that field. If called with a function, calls that function on every
element of the sequence and sums the results, skipping elements of the sequence
where that function returns nil
or a non-existence error.
Returns 0 when called on an empty sequence.
Specs
sum(RethinkDB.Q.reql_array, RethinkDB.Q.reql_string | RethinkDB.Q.reql_func1) :: RethinkDB.Q.t
Specs
sync(RethinkDB.Q.t) :: RethinkDB.Q.t
sync ensures that writes on a given table are written to permanent storage. Queries that specify soft durability (durability=’soft’) do not give such guarantees, so sync can be used to ensure the state of these queries. A call to sync does not return until all previous writes to the table are persisted.
If successful, the operation returns an object: {“synced”: 1}.
Return all documents in a table. Other commands may be chained after table to return a subset of documents (such as get and filter) or perform further processing.
There are two optional arguments.
- useOutdated: if true, this allows potentially out-of-date data to be returned, with potentially faster reads. It also allows you to perform reads from a secondary replica if a primary has failed. Default false.
- identifierFormat: possible values are name and uuid, with a default of name. If set to uuid, then system tables will refer to servers, databases and tables by UUID rather than name. (This only has an effect when used with system tables.)
Specs
table(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Create a table. A RethinkDB table is a collection of JSON documents.
If successful, the command returns an object with two fields:
- tables_created: always 1.
- config_changes: a list containing one two-field object, old_val and new_val:
- old_val: always nil.
- new_val: the table’s new config value.
If a table with the same name already exists, the command throws RqlRuntimeError.
Note: Only alphanumeric characters and underscores are valid for the table name.
When creating a table you can specify the following options:
- primary_key: the name of the primary key. The default primary key is id.
- durability: if set to soft, writes will be acknowledged by the server immediately and flushed to disk in the background. The default is hard: acknowledgment of writes happens after data has been written to disk.
- shards: the number of shards, an integer from 1-32. Defaults to 1.
- replicas: either an integer or a mapping object. Defaults to 1. If replicas is an integer, it specifies the number of replicas per shard. Specifying more replicas than there are servers will return an error. If replicas is an object, it specifies key-value pairs of server tags and the number of replicas to assign to those servers: {:tag1 => 2, :tag2 => 4, :tag3 => 2, …}.
- primary_replica_tag: the primary server specified by its server tag. Required if replicas is an object; the tag must be in the object. This must not be specified if replicas is an integer. The data type of a primary key is usually a string (like a UUID) or a number, but it can also be a time, binary object, boolean or an array. It cannot be an object.
Specs
table_create(RethinkDB.Q.t, RethinkDB.Q.reql_string, RethinkDB.Q.reql_opts) :: RethinkDB.Q.t
Drop a table. The table and all its data will be deleted.
If successful, the command returns an object with two fields:
- tables_dropped: always 1.
- config_changes: a list containing one two-field object, old_val and new_val:
- old_val: the dropped table’s config value.
- new_val: always nil.
If the given table does not exist in the database, the command throws RqlRuntimeError.
Specs
time(reql_number, reql_number, reql_number, reql_string) :: RethinkDB.Q.t
Create a time object for a specific time.
A few restrictions exist on the arguments:
- year is an integer between 1400 and 9,999.
- month is an integer between 1 and 12.
- day is an integer between 1 and 31.
- hour is an integer.
- minutes is an integer.
- seconds is a double. Its value will be rounded to three decimal places (millisecond-precision).
- timezone can be ‘Z’ (for UTC) or a string with the format ±[hh]:[mm].
Specs
time(reql_number, reql_number, reql_number, reql_number, reql_number, reql_number, reql_string) :: RethinkDB.Q.t
Specs
time_of_day(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the number of seconds elapsed since the beginning of the day stored in the time object.
Specs
timezone(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Return the timezone of the time object.
Specs
to_epoch_time(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Convert a time object to its epoch time.
Specs
to_geojson(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t
Convert a ReQL geometry object to a GeoJSON object.
Specs
to_iso8601(RethinkDB.Q.reql_time) :: RethinkDB.Q.t
Convert a time object to a string in ISO 8601 format.
Specs
to_json(RethinkDB.Q.reql_term) :: RethinkDB.Q.t
Serialize to JSON string on the server.
Specs
ungroup(RethinkDB.Q.t) :: RethinkDB.Q.t
Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after ungroup will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction.
The format of the array returned by ungroup is the same as the default native format of grouped data in the JavaScript driver and data explorer. end
Specs
union(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Concatenate two or more sequences.
Specs
upcase(RethinkDB.Q.reql_string) :: RethinkDB.Q.t
Convert a string to all upper case.
iex> "hi" |> upcase |> run conn
%RethinkDB.Record{data: "HI"}
Update JSON documents in a table. Accepts a JSON document, a ReQL expression, or a combination of the two.
The optional arguments are:
- durability: possible values are hard and soft. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving it, but before the write has been committed to disk.
- return_changes: if set to True, return a changes array consisting of old_val/new_val objects describing the changes made.
- non_atomic: if set to True, executes the update and distributes the result to replicas in a non-atomic fashion. This flag is required to perform non-deterministic updates, such as those that require reading data from another table.
Update returns an object that contains the following attributes:
- replaced: the number of documents that were updated.
- unchanged: the number of documents that would have been modified except the new value was the same as the old value.
- skipped: the number of documents that were skipped because the document didn’t exist.
- errors: the number of errors encountered while performing the update.
- first_error: If errors were encountered, contains the text of the first error.
- deleted and inserted: 0 for an update operation.
- changes: if return_changes is set to True, this will be an array of objects, one for each objected affected by the update operation. Each object will have
- two keys: {“new_val”:
, “old_val”: }.
Return a UUID (universally unique identifier), a string that can be used as a unique ID.
Accepts optionally a string. If given, UUID will be derived from the strings SHA-1 hash.
Specs
values(RethinkDB.Q.reql_obj) :: RethinkDB.Q.t
Return an array containing all of the object’s values.
Specs
with_fields(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array) :: RethinkDB.Q.t
Plucks one or more attributes from a sequence of objects, filtering out any objects in the sequence that do not have the specified fields. Functionally, this is identical to has_fields followed by pluck on a sequence.
Specs
without(RethinkDB.Q.reql_array, RethinkDB.Q.reql_array | RethinkDB.Q.reql_string) :: RethinkDB.Q.t
The opposite of pluck; takes an object or a sequence of objects, and returns them with the specified paths removed.