Exrethinkdb.Query.MathLogic
ReQL methods for math and logic operations.
All examples assume that use Exrethinkdb
has been called.
Summary↑
add(args) | Add multiple values |
add(left, right) | Sum two numbers, concatenate two strings, or concatenate 2 arrays |
and_r(args) | Compute the logical “and” of all values in a list |
and_r(left, right) | Compute the logical “and” of two values |
divide(args) | Divide a list of numbers. Left associative |
divide(left, right) | Divide two numbers |
eq(args) | Test if all values in a list are equal |
eq(left, right) | Test if two values are equal |
ge(args) | Test if all values in a list are greater than or equal to the next. Left associative |
ge(left, right) | Test if one value is greater than or equal to the other |
gt(args) | Test if all values in a list are greater than the next. Left associative |
gt(left, right) | Test if one value is greater than the other |
le(args) | Test if all values in a list are less than or equal to the next. Left associative |
le(left, right) | Test if one value is less than or equal to the other |
lt(args) | Test if all values in a list are less than the next. Left associative |
lt(left, right) | Test if one value is less than the other |
mod(left, right) | Find the remainder when dividing two numbers |
mul(args) | Multiply multiple values |
mul(left, right) | Multiply two numbers, or make a periodic array |
ne(args) | Test if all values in a list are not equal |
ne(left, right) | Test if two values are not equal |
not_r(arg) | Compute the logical inverse (not) of an expression |
or_r(args) | Compute the logical “or” of all values in a list |
or_r(left, right) | Compute the logical “or” of two values |
random() | Generate a random float between 0 and 1 |
random(upper) | Generate a random value in the range [0,upper). If upper is an integer then the random value will be an interger. If upper is a float it will be a float |
random(lower, upper) | 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 |
sub(args) | Subtract multiple values. Left associative |
sub(left, right) | Subtract two numbers |
Functions
Specs:
- add([Exrethinkdb.Query.reql_number | Exrethinkdb.Query.reql_string | Exrethinkdb.Query.reql_array]) :: Exrethinkdb.Query.t
Add multiple values.
iex> add([1, 2]) |> run conn
%Exrethinkdb.Record{data: 3}
iex> add(["hello", " world"]) |> run
%Exrethinkdb.Record{data: "hello world"}
Specs:
- add(Exrethinkdb.Query.reql_number | Exrethinkdb.Query.reql_string, Exrethinkdb.Query.reql_number | Exrethinkdb.Query.reql_string) :: Exrethinkdb.Query.t
Sum two numbers, concatenate two strings, or concatenate 2 arrays.
iex> add(1, 2) |> run conn
%Exrethinkdb.Record{data: 3}
iex> add("hello", " world") |> run conn
%Exrethinkdb.Record{data: "hello world"}
iex> add([1,2], [3,4]) |> run conn
%Exrethinkdb.Record{data: [1,2,3,4]}
Specs:
- and_r([Exrethinkdb.Query.reql_bool]) :: Exrethinkdb.Query.t
Compute the logical “and” of all values in a list.
iex> and_r([true, true, true]) |> run conn
%Exrethinkdb.Record{data: true}
iex> and_r([false, true, true]) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
Compute the logical “and” of two values.
iex> and(true, true) |> run conn
%Exrethinkdb.Record{data: true}
iex> and(false, true) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
- divide([Exrethinkdb.Query.reql_number]) :: Exrethinkdb.Query.t
Divide a list of numbers. Left associative.
iex> divide([12, 2, 3]) |> run conn
%Exrethinkdb.Record{data: 2}
Specs:
Divide two numbers.
iex> divide(12, 4) |> run conn
%Exrethinkdb.Record{data: 3}
Specs:
Test if all values in a list are equal.
iex> eq([2, 2, 2]) |> run conn
%Exrethinkdb.Record{data: true}
iex> eq([2, 1, 2]) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
Test if two values are equal.
iex> eq(1,1) |> run conn
%Exrethinkdb.Record{data: true}
iex> eq(1, 2) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
Test if all values in a list are greater than or equal to the next. Left associative.
iex> le([1, 4, 2]) |> run conn
%Exrethinkdb.Record{data: false}
iex> le([10, 4, 4]) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if one value is greater than or equal to the other.
iex> ge(1,1) |> run conn
%Exrethinkdb.Record{data: true}
iex> ge(2, 1) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if all values in a list are greater than the next. Left associative.
iex> gt([1, 4, 2]) |> run conn
%Exrethinkdb.Record{data: false}
iex> gt([10, 4, 2]) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if one value is greater than the other.
iex> gt(1,2) |> run conn
%Exrethinkdb.Record{data: false}
iex> gt(2,1) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if all values in a list are less than or equal to the next. Left associative.
iex> le([1, 4, 2]) |> run conn
%Exrethinkdb.Record{data: false}
iex> le([1, 4, 4]) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if one value is less than or equal to the other.
iex> le(1,1) |> run conn
%Exrethinkdb.Record{data: true}
iex> le(1, 2) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if all values in a list are less than the next. Left associative.
iex> lt([1, 4, 2]) |> run conn
%Exrethinkdb.Record{data: false}
iex> lt([1, 4, 5]) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if one value is less than the other.
iex> lt(2,1) |> run conn
%Exrethinkdb.Record{data: false}
iex> lt(1, 2) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Find the remainder when dividing two numbers.
iex> mod(23, 4) |> run conn
%Exrethinkdb.Record{data: 3}
Specs:
Multiply multiple values.
iex> mul([2,3,4]) |> run conn
%Exrethinkdb.Record{data: 24}
Specs:
- mul(Exrethinkdb.Query.reql_number | Exrethinkdb.Query.reql_array, Exrethinkdb.Query.reql_number | Exrethinkdb.Query.reql_array) :: Exrethinkdb.Query.t
Multiply two numbers, or make a periodic array.
iex> mul(2,3) |> run conn
%Exrethinkdb.Record{data: 6}
iex> mul([1,2], 2) |> run conn
%Exrethinkdb.Record{data: [1,2,1,2]}
Specs:
Test if all values in a list are not equal.
iex> ne([2, 2, 2]) |> run conn
%Exrethinkdb.Record{data: false}
iex> ne([2, 1, 2]) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Test if two values are not equal.
iex> ne(1,1) |> run conn
%Exrethinkdb.Record{data: false}
iex> ne(1, 2) |> run conn
%Exrethinkdb.Record{data: true}
Specs:
Compute the logical inverse (not) of an expression.
iex> not(true) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
- or_r([Exrethinkdb.Query.reql_bool]) :: Exrethinkdb.Query.t
Compute the logical “or” of all values in a list.
iex> or_r([true, true, true]) |> run conn
%Exrethinkdb.Record{data: true}
iex> or_r([false, true, true]) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
Compute the logical “or” of two values.
iex> or_r(true, false) |> run conn
%Exrethinkdb.Record{data: true}
iex> or_r(false, false) |> run conn
%Exrethinkdb.Record{data: false}
Specs:
- random :: Exrethinkdb.Query.t
Generate a random float between 0 and 1.
iex> random |> run conn
%Exrethinkdb.Record{data: 0.43}
Specs:
- random(Exrethinkdb.Query.reql_number) :: Exrethinkdb.Query.t
Generate a random value in the range [0,upper). If upper is an integer then the random value will be an interger. If upper is a float it will be a float.
iex> random(5) |> run conn
%Exrethinkdb.Record{data: 3}
iex> random(5.0) |> run conn
%Exrethinkdb.Record{data: 3.7}
Specs:
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
%Exrethinkdb.Record{data: 8}
iex> random(5.0, 15.0,) |> run conn
%Exrethinkdb.Record{data: 8.34}
Specs:
Subtract multiple values. Left associative.
iex> sub([9, 1, 2]) |> run conn
%Exrethinkdb.Record{data: 6}
Specs:
Subtract two numbers.
iex> sub(1, 2) |> run conn
%Exrethinkdb.Record{data: -1}