Exrethinkdb.Query.Joins

ReQL methods for join operations.

All examples assume that use Exrethinkdb has been called.

Summary

eq_join(left, field, right, opts \\ %{})

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

inner_join(left, right, f)

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

outer_join(left, right, f)

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

zip(arg)

Used to ‘zip’ up the result of a join by merging the ‘right’ fields into ‘left’ fields of each member of the sequence

Functions

eq_join(left, field, right, opts \\ %{})

Specs:

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: , right:

}`, 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
inner_join(left, right, f)

Specs:

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
outer_join(left, right, f)

Specs:

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
zip(arg)

Specs:

Used to ‘zip’ up the result of a join by merging the ‘right’ fields into ‘left’ fields of each member of the sequence.

iex> table("people") |> eq_join(
    "id", table("phone_numbers"), %{index: "person_id"}
  ) |> zip |> run