Do

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

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

Parameter Type Definition and Requirements

expression

List of Expressions

One or more expressions to be evaluated.

Returns

The evaluation of the last expression.

Examples

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

try
{
    Value result = await client.Query(
        Do(
            Create(
                Ref(Collection("magical_creatures"), "2"),
                Obj("data", Obj("name", "Orwen"))
            ),
            Get(Ref(Collection("magical_creatures"), "2"))
        )
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "2", collection = RefV(id = "magical_creatures", collection = RefV(id = "collections"))),ts: LongV(1603756298250000),data: ObjectV(name: StringV(Orwen)))
result, err := client.Query(
	f.Do(
		f.Create(
			f.Ref(f.Collection("magical_creatures"), "2"),
			f.Obj{"data": f.Obj{"name": "Orwen"}}),
		f.Get(f.Ref(f.Collection("magical_creatures"), "2"))))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[name:Orwen] ref:{2 0xc00009a210 0xc00009a210 <nil>} ts:1603747164000000]
client.query(
  q.Do(
    q.Create(
      q.Ref(q.Collection('magical_creatures'), '2'),
      { data: { name: 'Orwen' } },
    ),
    q.Get(q.Ref(q.Collection('magical_creatures'), '2')),
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Ref(Collection("magical_creatures"), "2"),
  ts: 1592269630010000,
  data: { name: 'Orwen' }
}
result = client.query(
  q.do(
    q.create(
      q.ref(q.collection("magical_creatures"), "2"),
      {"data": {"name": "Orwen"}}
    ),
    q.get(q.ref(q.collection("magical_creatures"), "2"))
  )
)
print(result)
{'ref': Ref(id=2, collection=Ref(id=magical_creatures, collection=Ref(id=collections))), 'ts': 1592948172680000, 'data': {'name': 'Orwen'}}
Do(
  Create(
    Ref(Collection('magical_creatures'), '2'),
    { data: { name: 'Orwen' } },
  ),
  Get(Ref(Collection('magical_creatures'), '2')),
)
{
  ref: Ref(Collection("magical_creatures"), "2"),
  ts: 1624310407590000,
  data: { name: 'Orwen' }
}
Query metrics:
  •    bytesIn:  188

  •   bytesOut:  178

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:   14

  • writeBytes:  196

  •  queryTime: 39ms

  •    retries:    0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!