Light
Dark
System
v4latest
v5dev
v4latest
v3
v2
v1

Transactions

Transactions are a robust concept to ensure your queries are executed, even if network errors occur. To do this, simply use the transaction method on EdgeDBClient.

Copy
client.transaction(tx ->
    tx.execute("INSERT Person { name := $name, age := $age}", new HashMap<>(){{
        put("name", "Example Name");
        put("age", 1234);
    }}).thenCompose(v ->
        tx.querySingle(Long.class, "SELECT count((SELECT Person))");
    );
).thenAccept(count -> {
    System.out.println(String.format("There are %d people in the database", count));
})

It is important to note that you must use the tx parameter of the transaction to preform queries, otherwise you won’t get the benefits of transactions.

Light
Dark
System

We use ChatGPT with additional context from our documentation to answer your questions. Not all answers will be accurate. Please join our Discord if you need more help.