Skip to content

Commit

Permalink
Add transaction page to docs (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs authored Oct 2, 2023
1 parent 392e69f commit 4a40547
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
datatypes
exceptions
api
transactions

EdgeDB.Net is the official EdgeDB .NET client, compatable with C#, F# and
VB.NET.
Expand Down
61 changes: 61 additions & 0 deletions docs/transactions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. _edgedb-dotnet-transactions:

============
Transactions
============

Transactions allow you to execute transactional code via the ``TransactionAsync`` API, retrying your
queries if a retryable error (e.g. a network failure) occurs. If an non-retryable error happens,
the queries performed within the transactions are automatically rolled back:

.. tabs::

.. code-tab:: cs
:caption: C#

var client = new EdgeDBClient();

await client.TransactionAsync(async tx =>
await tx.ExecuteAsync("INSERT User { name := 'John Smith' }");
);

.. code-tab:: fsharp
:caption: F#

let client = new EdgeDBClient()

client.TransactionAsync(
fun tx -> tx.ExecuteAsync("INSERT User { name := 'John Smith' }")
) |> Async.AwaitTask |> Async.Ignore |> ignore
.. note::
Code blocks in transactions may run multiple times. It’s good practice to only perform safe to re-run operations in transaction blocks.

The ``TransactionAsync`` method proxies the result of the transaction, allowing you to
get the result of a query executed in a transaction:

.. tabs::

.. code-tab:: cs
:caption: C#

var client = new EdgeDBClient();

var transactionResult = await client.TransactionAsync(async tx =>
await tx.QueryRequiredSingleAsync<string>("SELECT 'Hello from Transaction!'");
);

Console.WriteLine(transactionResult);

.. code-tab:: fsharp
:caption: F#

let client = new EdgeDBClient()

client.TransactionAsync(
fun tx -> tx.QueryRequiredSingleAsync<string>("SELECT 'Hello from Transaction!'")
)
|> Async.AwaitTask
|> Async.RunSynchronously
|> fun r -> printfn "Transaction result: %s" r

0 comments on commit 4a40547

Please sign in to comment.