| 1 | package rethinkdb |
| 2 | |
| 3 | import ( |
| 4 | p "gopkg.in/rethinkdb/rethinkdb-go.v6/ql2" |
| 5 | ) |
| 6 | |
| 7 | // InnerJoin returns the inner product of two sequences (e.g. a table, a filter result) |
| 8 | // filtered by the predicate. The query compares each row of the left sequence |
| 9 | // with each row of the right sequence to find all pairs of rows which satisfy |
| 10 | // the predicate. When the predicate is satisfied, each matched pair of rows |
| 11 | // of both sequences are combined into a result row. |
| 12 | func (t Term) InnerJoin(args ...interface{}) Term { |
| 13 | return constructMethodTerm(t, "InnerJoin", p.Term_INNER_JOIN, args, map[string]interface{}{}) |
| 14 | } |
| 15 | |
| 16 | // OuterJoin computes a left outer join by retaining each row in the left table even |
| 17 | // if no match was found in the right table. |
| 18 | func (t Term) OuterJoin(args ...interface{}) Term { |
| 19 | return constructMethodTerm(t, "OuterJoin", p.Term_OUTER_JOIN, args, map[string]interface{}{}) |
| 20 | } |
| 21 | |
| 22 | // EqJoinOpts contains the optional arguments for the EqJoin term. |
| 23 | type EqJoinOpts struct { |
| 24 | Index interface{} `rethinkdb:"index,omitempty"` |
| 25 | Ordered interface{} `rethinkdb:"ordered,omitempty"` |
| 26 | } |
| 27 | |
| 28 | func (o EqJoinOpts) toMap() map[string]interface{} { |
| 29 | return optArgsToMap(o) |
| 30 | } |
| 31 | |
| 32 | // EqJoin is an efficient join that looks up elements in the right table by primary key. |
| 33 | // |
| 34 | // Optional arguments: "index" (string - name of the index to use in right table instead of the primary key) |
| 35 | func (t Term) EqJoin(left, right interface{}, optArgs ...EqJoinOpts) Term { |
| 36 | opts := map[string]interface{}{} |
| 37 | if len(optArgs) >= 1 { |
| 38 | opts = optArgs[0].toMap() |
| 39 | } |
| 40 | return constructMethodTerm(t, "EqJoin", p.Term_EQ_JOIN, []interface{}{funcWrap(left), right}, opts) |
| 41 | } |
| 42 | |
| 43 | // Zip is used to 'zip' up the result of a join by merging the 'right' fields into 'left' |
| 44 | // fields of each member of the sequence. |
| 45 | func (t Term) Zip(args ...interface{}) Term { |
| 46 | return constructMethodTerm(t, "Zip", p.Term_ZIP, args, map[string]interface{}{}) |
| 47 | } |