@@ -188,18 +188,36 @@ defmodule Ecto.Adapters.SQLite3 do
188188
189189 Here are several ways to specify a different transaction mode:
190190
191- 1. **Pass `mode: :immediate` to `Repo.transaction/2`:** Use this approach to set the transaction mode for individual transactions.
192-
193- 2. **Define custom transaction functions:** Create wrappers, such as `Repo.immediate_transaction/2` or `Repo.deferred_transaction/2`,
194- to easily apply different modes where needed.
195-
196- 3. **Set a global default:** Configure `:default_transaction_mode` to apply a preferred mode for all transactions.
197-
198- ```elixir
199- config :my_app, MyApp.Repo,
200- database: "path/to/my/database.db",
201- default_transaction_mode: :immediate
202- ```
191+ **Pass `mode: :immediate` to `Repo.transaction/2`:** Use this approach to set
192+ the transaction mode for individual transactions.
193+
194+ Multi.new()
195+ |> Multi.run(:example, fn _repo, _changes_so_far ->
196+ # ... do some work ...
197+ end)
198+ |> Repo.transaction(mode: :immediate)
199+
200+ **Define custom transaction functions:** Create wrappers, such as
201+ `Repo.immediate_transaction/2` or `Repo.deferred_transaction/2`, to easily
202+ apply different modes where needed.
203+
204+ defmodule MyApp.Repo do
205+ def immediate_transaction(fun_or_multi) do
206+ transaction(fun_or_multi, mode: :immediate)
207+ end
208+
209+ def deferred_transaction(fun_or_multi) do
210+ transaction(fun_or_multi, mode: :deferred)
211+ end
212+ end
213+
214+ **Set a global default:** Configure `:default_transaction_mode` to apply a
215+ preferred mode for all transactions, unless explicitly passed a different
216+ `:mode` to `Repo.transaction/2`.
217+
218+ config :my_app, MyApp.Repo,
219+ database: "path/to/my/database.db",
220+ default_transaction_mode: :immediate
203221
204222 [3]: https://www.sqlite.org/compile.html
205223 [4]: https://www.sqlite.org/whentouse.html
0 commit comments