Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
warmwaffles authored Nov 4, 2024
1 parent 7984992 commit 9c9a80b
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions lib/ecto/adapters/sqlite3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,36 @@ defmodule Ecto.Adapters.SQLite3 do
Here are several ways to specify a different transaction mode:
1. **Pass `mode: :immediate` to `Repo.transaction/2`:** Use this approach to set the transaction mode for individual transactions.
2. **Define custom transaction functions:** Create wrappers, such as `Repo.immediate_transaction/2` or `Repo.deferred_transaction/2`,
to easily apply different modes where needed.
3. **Set a global default:** Configure `:default_transaction_mode` to apply a preferred mode for all transactions.
```elixir
config :my_app, MyApp.Repo,
database: "path/to/my/database.db",
default_transaction_mode: :immediate
```
**Pass `mode: :immediate` to `Repo.transaction/2`:** Use this approach to set
the transaction mode for individual transactions.
Multi.new()
|> Multi.run(:example, fn _repo, _changes_so_far ->
# ... do some work ...
end)
|> Repo.transaction(mode: :immediate)
**Define custom transaction functions:** Create wrappers, such as
`Repo.immediate_transaction/2` or `Repo.deferred_transaction/2`, to easily
apply different modes where needed.
defmodule MyApp.Repo do
def immediate_transaction(fun_or_multi) do
transaction(fun_or_multi, mode: :immediate)
end
def deferred_transaction(fun_or_multi) do
transaction(fun_or_multi, mode: :deferred)
end
end
**Set a global default:** Configure `:default_transaction_mode` to apply a
preferred mode for all transactions, unless explicitly passed a different
`:mode` to `Repo.transaction/2`.
config :my_app, MyApp.Repo,
database: "path/to/my/database.db",
default_transaction_mode: :immediate
[3]: https://www.sqlite.org/compile.html
[4]: https://www.sqlite.org/whentouse.html
Expand Down

0 comments on commit 9c9a80b

Please sign in to comment.