Do

Do( expression, ... )
Do( expression, ... )
Do( expression, ... )
Do( expression, ... )
do( expression, ... )
do_( expression, ... )
Do( expression, ... )
Do( expression, ... )

Description

The Do function evaluates a list of expressions which are provided as arguments. This evaluation occurs sequentially, from left to right, ensuring that modifications made by earlier expressions are seen by later expressions. If one of the expressions evaluated by Do returns an error, the current transaction is terminated and none of the expressions' effects are persisted in the database. If all of the expressions executed by Do succeed, only the results of the last statements executed are returned. If no expressions are provided, Do returns an error.

Parameters

Argument Type Definition and Requirements

expression

List of Expressions

One or more expressions to be evaluated.

Returns

The evaluation of the last expression.

Examples

The query below has a Do statement with two expressions. The first expression creates a document associated with the "magical_creatures" collection, with an id of 1. The second expression retrieves the document from the ref containing the collection "magical_creatures" and id of 1. This was the document just created in the previous statement. Only the results from the second retrieving expression are returned.

curl https://db.fauna.com/ \
    -d '{
          "do": [
            {
              "create": { "ref": { "collection": "magical_creatures" }, "id": 1 },
              "params": {
                "object": { "data": { "object": { "name": "Hen Wen" } } }
              }
            },
            {
              "get": { "ref": { "collection": "magical_creatures" }, "id": 1 }
            }
          ]
        }'
client.Query(
  Do(
    Create(
      Ref(Collection("magical_creatures"), 1),
      Obj("data", Obj("name", "Hen Wen"))),
    Get(Ref(Collection("magical_creatures"), 1))));
System.out.println(
    client.query(
        Do(
           Create(
              Ref(Collection(Value("magical_creatures")), Value(1)),
              Obj("data", Obj("name", Value("Hen Wen")))
           ),
          Get(Ref(Collection(Value("magical_creatures")), Value(1)))
        )
    ).get());
result, _ := client.Query(
    f.Do(
        f.Create(
            f.RefCollection(f.Collection("magical_creatures"), 1),
            f.Obj{"data": f.Obj{"name": "Hen Wen"}},
        ),
        f.Get(f.RefCollection(f.Collection("magical_creatures"), 1)),
    ),
)

fmt.Println(result)
client.query(
  Do(
    Create(
      Ref(Collection("magical_creatures"), 1),
      Obj("data" -> Obj("name" -> "Hen Wen"))),
    Get(Ref(Collection("magical_creatures"), 1))))
client.query(
  q.do(
    q.create(
      Ref(q.collection("magical_creatures"), 1),
      {"data": {"name": "Hen Wen"}}
    ),
    q.get(Ref(q.collection("magical_creatures"), 1))
  ))
$client.query do
  do_(
    create(ref(collection_('magical_creatures'), 1),
           data: { name: 'Hen Wen' }),
    get(ref(collection_('magical_creatures'), 1)))
end
client.query(
    Do(
        Create(
            at: Ref(collection: Collection("magical_creatures"), id: 1),
            Obj("data" => Obj("name" => "Hen Wen"))
        ),
        Get(Ref(collection: Collection("magical_creatures"), id: 1))
    )
)
client.query(
  q.Do(
    q.Create(
      q.Ref(q.Collection("magical_creatures"), 1),
      { data: { name: "Hen Wen" } }),
    q.Get(q.Ref(q.Collection("magical_creatures"), 1))))
.then((ret) => console.log(ret));
HTTP/1.1 401 Unauthorized
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}
{
  ref: ref(id = "1", collection = ref(id = "magical_creatures", collection = ref(id = "collections"))),
  ts: 1536603599790006,
  data: {name: "Hen Wen"}
}
map[ref:{1 0xc4201a85e0 <nil>} ts:1526946657492696 data:map[name:Hen Wen]]
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}
{
  "errors": [ { "code": "unauthorized", "description": "Unauthorized" } ]
}
{ ref: Ref(id=1, collection=Ref(id=magical_creatures, collection=Ref(id=collections))),
  ts: 1526675832587944,
  data: { name: 'Hen Wen' } }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!