@@ -13,6 +13,9 @@ defmodule Ecto.Adapters.SQLite3 do
13
13
14
14
* `:database` - The path to the database. In memory is allowed. You can use
15
15
`:memory` or `":memory:"` to designate that.
16
+ * `:default_transaction_mode` - one of `deferred` (default), `immediate`,
17
+ or `exclusive`. If a mode is not specified in a call to `Repo.transaction/2`,
18
+ this will be the default transaction mode.
16
19
* `:journal_mode` - Sets the journal mode for the sqlite connection. Can be
17
20
one of the following `:delete`, `:truncate`, `:persist`, `:memory`,
18
21
`:wal`, or `:off`. Defaults to `:wal`.
@@ -51,8 +54,8 @@ defmodule Ecto.Adapters.SQLite3 do
51
54
* `:datetime_type` - Defaults to `:iso8601`. Determines how datetime fields are stored in the database.
52
55
The allowed values are `:iso8601` and `:text_datetime`. `:iso8601` corresponds to a string of the form
53
56
`YYYY-MM-DDThh:mm:ss` and `:text_datetime` corresponds to a string of the form `YYYY-MM-DD hh:mm:ss`
54
- * `:load_extensions` - list of paths identifying extensions to load. Defaults to []. The provided list will
55
- be merged with the global extensions list, set on :exqlite, :load_extensions. Be aware that the path should
57
+ * `:load_extensions` - list of paths identifying extensions to load. Defaults to []. The provided list will
58
+ be merged with the global extensions list, set on :exqlite, :load_extensions. Be aware that the path should
56
59
handle pointing to a library compiled for the current architecture. See `Exqlite.Connection.connect/1` for more.
57
60
58
61
For more information about the options above, see [sqlite documentation][1]
@@ -177,11 +180,34 @@ defmodule Ecto.Adapters.SQLite3 do
177
180
types, despite the fact SQLite only has [five storage classes][5]. The query will still
178
181
work and return data, but you will need to do this mapping on your own.
179
182
183
+ ### Transaction mode
184
+
185
+ By default, [SQLite transactions][8] run in `DEFERRED` mode. However, in typical web applications with a balanced load
186
+ of reads and writes, using `IMMEDIATE` mode can yield better performance.
187
+
188
+ Here are several ways to specify a different transaction mode:
189
+
190
+ 1. **Pass `mode: :immediate` to `Repo.transaction/2`:** Use this approach to set the transaction mode for individual transactions.
191
+
192
+ 2. **Define custom transaction functions:** Create wrappers, such as `Repo.immediate_transaction/2` or `Repo.deferred_transaction/2`,
193
+ to easily apply different modes where needed.
194
+
195
+ 3. **Set a global default:** Configure `:default_transaction_mode` to apply a preferred mode for all transactions.
196
+
197
+ ```elixir
198
+ config :my_app, MyApp.Repo,
199
+ database: "path/to/my/database.db",
200
+ default_transaction_mode: :immediate
201
+ ```
202
+
203
+ See [this GitHub issue](https://github.com/elixir-sqlite/ecto_sqlite3/issues/153) for more details.
204
+
180
205
[3]: https://www.sqlite.org/compile.html
181
206
[4]: https://www.sqlite.org/whentouse.html
182
207
[5]: https://www.sqlite.org/datatype3.html
183
208
[6]: https://www.sqlite.org/datatype3.html#collating_sequences
184
209
[7]: https://hexdocs.pm/ecto/schemaless-queries.html
210
+ [8]: https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions
185
211
"""
186
212
187
213
use Ecto.Adapters.SQL ,
0 commit comments