abort()
Terminate the current transaction.
Description
The abort()
method terminates the current transaction, which includes
all expressions that are part of the query. Changes to data or schema by the
aborted transaction are ignored even if the changes occurred before the
abort()
call.
Examples
This simple example shows how to abort a transaction.
-
First, create a collection named Insect:
{ name: "Insect", coll: Collection, ts: Time("2023-06-20T20:50:45.200Z"), indexes: {}, constraints: [] }
-
Create a document in the collection and abort the transaction:
Error: abort Query aborted. error: Query aborted. at *query*:2:6 | 2 | abort(0) | ^^^ |
-
Verify that the collection doesn’t have a document:
0
This example creates an anonymous function, which aborts when called without a valid email argument:
Query aborted.
error: Query aborted.
at *query*:3:10
|
3 | abort({
| __________^
4 | | code: "invalid_email",
5 | | message: "user email must be non-empty"
6 | | })
| |______^
|
at *query*:15:11
|
15 | createUser("name", "")
| ^^^^^^^^^^^^
|
The first call to createUser()
succeeds. The second call fails because
a valid email argument isn’t included, which triggers the abort()
action.
The response message is the notification response.
Notice that the query runs all the statements included in the transaction.
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!