@@ -32,6 +32,7 @@ defmodule Exqlite.Connection do
32
32
33
33
defstruct [
34
34
:db ,
35
+ :default_transaction_mode ,
35
36
:directory ,
36
37
:path ,
37
38
:transaction_status ,
@@ -55,9 +56,11 @@ defmodule Exqlite.Connection do
55
56
@ type synchronous ( ) :: :extra | :full | :normal | :off
56
57
@ type auto_vacuum ( ) :: :none | :full | :incremental
57
58
@ type locking_mode ( ) :: :normal | :exclusive
59
+ @ type transaction_mode ( ) :: :deferred | :immediate | :exclusive
58
60
59
61
@ type connection_opt ( ) ::
60
62
{ :database , String . t ( ) }
63
+ | { :default_transaction_mode , transaction_mode ( ) }
61
64
| { :mode , Sqlite3 . open_opt ( ) }
62
65
| { :journal_mode , journal_mode ( ) }
63
66
| { :temp_store , temp_store ( ) }
@@ -91,6 +94,9 @@ defmodule Exqlite.Connection do
91
94
92
95
* `:database` - The path to the database. In memory is allowed. You can use
93
96
`:memory` or `":memory:"` to designate that.
97
+ * `:default_transaction_mode` - one of `deferred` (default), `immediate`,
98
+ or `exclusive`. If a mode is not specified in a call to `Repo.transaction/2`,
99
+ this will be the default transaction mode.
94
100
* `:mode` - use `:readwrite` to open the database for reading and writing
95
101
, `:readonly` to open it in read-only mode or `[:readonly | :readwrite, :nomutex]`
96
102
to open it with no mutex mode. `:readwrite` will also create
@@ -260,7 +266,10 @@ defmodule Exqlite.Connection do
260
266
# append level on the savepoint. Instead the rollbacks would just completely
261
267
# revert the issues when it may be desirable to fix something while in the
262
268
# transaction and then commit.
263
- case Keyword . get ( options , :mode , :deferred ) do
269
+
270
+ mode = Keyword . get ( options , :mode , state . default_transaction_mode )
271
+
272
+ case mode do
264
273
:deferred when transaction_status == :idle ->
265
274
handle_transaction ( :begin , "BEGIN TRANSACTION" , state )
266
275
@@ -549,6 +558,8 @@ defmodule Exqlite.Connection do
549
558
:ok <- load_extensions ( db , options ) do
550
559
state = % __MODULE__ {
551
560
db: db ,
561
+ default_transaction_mode:
562
+ Keyword . get ( options , :default_transaction_mode , :deferred ) ,
552
563
directory: directory ,
553
564
path: database ,
554
565
transaction_status: :idle ,
0 commit comments