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 an instance associated with the "magical_creatures" class with an id of 1. The second expression retrieves the instance from the ref containing the class "magical_creatures" and id of 1. This was the instance 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": { "class": "magical_creatures" }, "id": 1 },
              "params": {
                "object": { "data": { "object": { "name": "Hen Wen" } } }
              }
            },
            {
              "get": { "ref": { "class": "magical_creatures" }, "id": 1 }
            }
          ]
        }'
client.Query(
  Do(
    Create(
      Ref(Class("magical_creatures"), 1),
      Obj("data", Obj("name", "Hen Wen"))),
    Get(Ref(Class("magical_creatures"), 1))));
System.out.println(
    client.query(
        Do(
           Create(
              Ref(Class(Value("magical_creatures")), Value(1)),
              Obj("data", Obj("name", Value("Hen Wen")))
           ),
          Get(Ref(Class(Value("magical_creatures")), Value(1)))
        )
    ).get());
result, _ := client.Query(
    f.Do(
        f.Create(
            f.RefClass(f.Class("magical_creatures"), 1),
            f.Obj{"data": f.Obj{"name": "Hen Wen"}},
        ),
        f.Get(f.RefClass(f.Class("magical_creatures"), 1)),
    ),
)

fmt.Println(result)
client.query(
  Do(
    Create(
      Ref(Class("magical_creatures"), 1),
      Obj("data" -> Obj("name" -> "Hen Wen"))),
    Get(Ref(Class("magical_creatures"), 1))))
client.query(
  q.do(
    q.create(
      Ref(q.class_expr("magical_creatures"), 1),
      {"data": {"name": "Hen Wen"}}
    ),
    q.get(Ref(q.class_expr("magical_creatures"), 1))
  ))
$client.query do
  do_(
    create(ref(class_('magical_creatures'), 1),
           data: { name: 'Hen Wen' }),
    get(ref(class_('magical_creatures'), 1)))
end
client.query(
    Do(
        Create(
            at: Ref(class: Class("magical_creatures"), id: 1),
            Obj("data" => Obj("name" => "Hen Wen"))
        ),
        Get(Ref(class: Class("magical_creatures"), id: 1))
    )
)
client.query(
  q.Do(
    q.Create(
      q.Ref(q.Class("magical_creatures"), 1),
      { data: { name: "Hen Wen" } }),
    q.Get(q.Ref(q.Class("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", class = ref(id = "magical_creatures", class = ref(id = "classes"))),
  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, class=Ref(id=magical_creatures, class=Ref(id=classes))),
  ts: 1526675832587944,
  data: { name: 'Hen Wen' } }