Join

Join( source, detail )
Join( source, detail )
Join( source, detail )
Join( source, detail )
join( source, detail )
join( source, detail )
Join( source, detail )
Join( source, detail )

Description

The Join function finds all index tuples from the source SetRef and uses the source's values to be retrieved from the detail index terms.

Parameters

Argument Type Definition and Requirements

source

SetRef

The source SetRef for the join operation.

detail

IndexRef or Lambda function

The IndexRef to join with the source SetRef, or the Lambda function which determines how to complete the join operation.

Returns

The SetRef for the join operation.

Examples

The index form is useful when the instances in the source_set match the terms in an index. Join returns instances from an Index (specified by detail) that match the terms from source.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/181388642114077184" }
            },
            "with": { "index": "spells_by_spellbook" }
          }
        }'
client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Index("spells_by_spellbook"))));
client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/181388642114077184")),
        Index(Value("spells_by_spellbook")))));
result, _ := client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.RefClass(f.Class("characters"), "181388642114077184"),
            ),
            f.Index("spells_by_spellbook"),
        ),
    ),
)

fmt.Println(result)
client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Index("spells_by_spellbook"))))
client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")
      ),
      q.index("spells_by_spellbook")
    )
  ))
$client.query do
  paginate join match(index('spellbooks_by_owner'),
                 ref('classes/characters/181388642114077184')) index('spells_by_spellbook')
end
client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/181388642114077184")
            ),
            with: Index("spells_by_spellbook")
        )
    )
)
client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        q.Ref(q.Class("characters"), "181388642114077184")),
      q.Index("spells_by_spellbook"))))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  data: [
    ref(id = "181388642046968320", class = ref(id="spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id="spells", class = ref(id = "classes")))
  ]
}
map[data:[{181388642046968320 0xc4202478a0 <nil>} {181388642071085568 0xc420247ac0 <nil>}]]
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{ data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

The Lambda form requires the Lambda function to be pure. i.e. it may not make any reads or writes.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/181388642114077184" }
            },
            "with": {
              "lambda": "spellbook",
              "expr": {
                "match": { "index": "spells_by_spellbook" },
                "terms": { "var": "spellbook" }
              }
            }
          }
        }'
client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda(
        "spellbook",
        Match(Index("spells_by_spellbook"), Var("spellbook"))))));
client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/181388642114077184")),
        Lambda(
          Value("spellbook"),
          Match(
            Index(Value("spells_by_spellbook")),
            Var("spellbook"))))));
result, _ := client.Query(
    f.Paginate(
        f.Join(
            f.MatchTerm(
                f.Index("spellbooks_by_owner"),
                f.RefClass(f.Class("characters"), "181388642114077184"),
            ),
            f.Lambda(
                "spellbook",
                f.MatchTerm(
                    f.Index("spells_by_spellbook"),
                    f.Var("spellbook"),
                ),
            ),
        ),
    ),
)

fmt.Println(result)
client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda { spellbook =>
        Match(Index("spells_by_spellbook"), spellbook)
      })))
client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")
      ),
      q.lambda_expr(
        "spellbook",
        q.match(
          q.index("spells_by_spellbook"),
          q.var("spellbook")
        )
      )
    )
  ))
$client.query do
  paginate join(match(index('spellbooks_by_owner'),
                      ref('classes/characters/181388642114077184')),
                lambda_expr('spellbook',
                            match(index('spells_by_spellbook'), var('spellbook'))))
end
client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/181388642114077184")
            ),
            with: Lambda(
                vars: "spellbook"
                in: Match(
                    index: Index("spells_by_spellbook"),
                    terms: Var("spellbook")
                )
            )
        )
    )
)
client.query(
  q.Paginate(
    q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        q.Ref(q.Class("characters"), "181388642114077184")),
      q.Lambda("spellbook", q.Match(q.Index("spells_by_spellbook"), q.Var("spellbook"))))))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      { "@ref": "classes/spells/181388642046968320" },
      { "@ref": "classes/spells/181388642071085568" }
    ]
  }
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    ref(id = "181388642046968320", class = ref(id="spells", class = ref(id = "classes"))),
    ref(id = "181388642071085568", class = ref(id="spells", class = ref(id = "classes")))
  ]
}
map[data:[{181388642046968320 0xc42029a8e0 <nil>} {181388642071085568 0xc42029ab00 <nil>}]]
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{
  "data": [
    { "@ref": "classes/spells/181388642046968320" },
    { "@ref": "classes/spells/181388642071085568" }
  ]
}
{ data:
   [ Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))),
     Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) ] }

The events view of Join contains events for joined sets as the join filtered by when the join instance was live in the source set.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{
          "paginate": {
            "join": {
              "match": { "index": "spellbooks_by_owner" },
              "terms": { "@ref": "classes/characters/181388642114077184" }
            },
            "with": {
              "lambda": "spellbook",
              "expr": {
                "match": { "index": "spells_by_spellbook" },
                "terms": { "var": "spellbook" }
              }
            }
          },
          "events": true
        }'
client.Query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda(
        "spellbook",
        Match(Index("spells_by_spellbook"), Var("spellbook")))),
    events: true));
client.query(
  Paginate(
      Join(
        Match(
          Index(Value("spellbooks_by_owner")),
          Ref("classes/characters/181388642114077184")),
        Lambda(
          Value("spellbook"),
          Match(
            Index(Value("spells_by_spellbook")),
            Var("spellbook")))))
    .events(Value(true)));
result, _ := client.Query(
    f.Paginate(
        f.Events(
            f.Join(
                f.MatchTerm(
                    f.Index("spellbooks_by_owner"),
                    f.RefClass(f.Class("characters"), "181388642114077184"),
                ),
                f.Lambda(
                    "spellbook",
                    f.MatchTerm(
                        f.Index("spells_by_spellbook"),
                        f.Var("spellbook"),
                    ),
                ),
            ),
        ),
    ),
)

fmt.Println(result)
client.query(
  Paginate(
    Join(
      Match(
        Index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")),
      Lambda { spellbook =>
        Match(Index("spells_by_spellbook"), spellbook)
      }),
    events = true))
client.query(
  q.paginate(
    q.join(
      q.match(
        q.index("spellbooks_by_owner"),
        Ref("classes/characters/181388642114077184")
      ),
      q.lambda_expr(
        "spellbook",
        q.match(
          q.index("spells_by_spellbook"),
          q.var("spellbook")
        )
      )
    ),
    events=True
  ))
$client.query do
  paginate join(match(index('spellbooks_by_owner'),
                      ref('classes/characters/181388642114077184')),
                lambda_expr('spellbook',
                            match(index('spells_by_spellbook'), var('spellbook')))),
           events: true
end
client.query(
    Paginate(
        Join(
            Match(
                index: Index("spellbooks_by_owner"),
                terms: Ref("classes/characters/181388642114077184")
            ),
            with: Lambda(
                vars: "spellbook"
                in: Match(
                    index: Index("spells_by_spellbook"),
                    terms: Var("spellbook")
                )
            )
        ),
        events: true
    )
)
client.query(
  q.Paginate(
    q.Events(q.Join(
      q.Match(
        q.Index("spellbooks_by_owner"),
        q.Ref(q.Class("characters"), "181388642114077184")),
      q.Index("spells_by_spellbook")))))
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{
  "resource": {
    "data": [
      {
        "ts": 1509244539547758,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642046968320" }
      },
      {
        "ts": 1509244539547758,
        "action": "create",
        "resource": { "@ref": "classes/spells/181388642071085568" }
      }
    ]
  }
}
{
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      ts: 1509244539547758,
      action: "create",
      resource: ref(id = "181388642046968320", class = ref(id="spells", class = ref(id = "classes")))
    },
    {
      ts: 1509244539547758,
      action: "create",
      resource: ref(id = "181388642071085568", class = ref(id="spells", class = ref(id = "classes")))
    }
  ]
}
map[data:[
  map[ts:1509244539547758 action:add instance:{181388642046968320 0xc420285c60 <nil>}]
  map[ts:1509244539547758 action:add instance:{181388642071085568 0xc420285f20 <nil>}]
]]
{
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{
  "data": [
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642046968320" }
    },
    {
      "ts": 1509244539547758,
      "action": "create",
      "resource": { "@ref": "classes/spells/181388642071085568" }
    }
  ]
}
{ data:
  [  { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642046968320, class=Ref(id=spells, class=Ref(id=classes))) },
     { ts: 1527095186458101,
       action: 'add',
       instance:
        Ref(id=181388642071085568, class=Ref(id=spells, class=Ref(id=classes))) } ] }