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

add(args)

Specs:

Add multiple values.

iex> add([1, 2]) |> run conn
%Exrethinkdb.Record{data: 3}

iex> add(["hello", " world"]) |> run
%Exrethinkdb.Record{data: "hello world"}
add(left, right)

Specs:

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]}
and_r(args)

Specs:

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}
and_r(left, right)

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}
divide(args)

Specs:

Divide a list of numbers. Left associative.

iex> divide([12, 2, 3]) |> run conn
%Exrethinkdb.Record{data: 2}
divide(left, right)

Specs:

Divide two numbers.

iex> divide(12, 4) |> run conn
%Exrethinkdb.Record{data: 3}
eq(args)

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}
eq(left, right)

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}
ge(args)

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}
ge(left, right)

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}
gt(args)

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}
gt(left, right)

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}
le(args)

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}
le(left, right)

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}
lt(args)

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}
lt(left, right)

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}
mod(left, right)

Specs:

Find the remainder when dividing two numbers.

iex> mod(23, 4) |> run conn
%Exrethinkdb.Record{data: 3}
mul(args)

Specs:

Multiply multiple values.

iex> mul([2,3,4]) |> run conn
%Exrethinkdb.Record{data: 24}
mul(left, right)

Specs:

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]}
ne(args)

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}
ne(left, right)

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}
not_r(arg)

Specs:

Compute the logical inverse (not) of an expression.

iex> not(true) |> run conn
%Exrethinkdb.Record{data: false}
or_r(args)

Specs:

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}
or_r(left, right)

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}
random()

Specs:

Generate a random float between 0 and 1.

iex> random |> run conn
%Exrethinkdb.Record{data: 0.43}
random(upper)

Specs:

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}
random(lower, upper)

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}
sub(args)

Specs:

Subtract multiple values. Left associative.

iex> sub([9, 1, 2]) |> run conn
%Exrethinkdb.Record{data: 6}
sub(left, right)

Specs:

Subtract two numbers.

iex> sub(1, 2) |> run conn
%Exrethinkdb.Record{data: -1}