mirror of
https://github.com/ent/ent.git
synced 2026-04-28 21:50:56 +03:00
doc/website: document tweaking transaction isolation levels (#2774)
* docs: document tweaking transaction isolation levels * Update doc/md/tutorial-todo-gql-tx-mutation.md Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update doc/md/tutorial-todo-gql-tx-mutation.md * Update doc/md/tutorial-todo-gql-tx-mutation.md Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
@@ -50,6 +50,24 @@ func (mutationResolver) CreateTodo(ctx context.Context, todo TodoInput) (*ent.To
|
||||
}
|
||||
```
|
||||
|
||||
## Isolation Levels
|
||||
|
||||
If you'd like to tweak the transaction's isolation level, you can do so by implementing your own `TxOpener`. For example:
|
||||
|
||||
```go
|
||||
srv.Use(entgql.Transactioner{
|
||||
TxOpener: entgql.TxOpenerFunc(func(ctx context.Context) (context.Context, driver.Tx, error) {
|
||||
tx, err := client.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelRepeatableRead})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
ctx = NewTxContext(ctx, tx)
|
||||
ctx = NewContext(ctx, tx.Client())
|
||||
return ctx, tx, nil
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Great! With a few lines of code, our application now supports automatic transactional mutations. Please continue to the
|
||||
|
||||
Reference in New Issue
Block a user