1
1
use crate :: { Connection , Result } ;
2
2
use std:: ops:: Deref ;
3
3
4
- /// Options for transaction behavior. See [BEGIN
5
- /// TRANSACTION](http://www.sqlite.org/lang_transaction.html) for details.
6
- #[ derive( Copy , Clone ) ]
7
- #[ non_exhaustive]
8
- pub enum TransactionBehavior {
9
- /// DEFERRED means that the transaction does not actually start until the
10
- /// database is first accessed.
11
- Deferred ,
12
- /// IMMEDIATE cause the database connection to start a new write
13
- /// immediately, without waiting for a writes statement.
14
- Immediate ,
15
- /// EXCLUSIVE prevents other database connections from reading the database
16
- /// while the transaction is underway.
17
- Exclusive ,
18
- }
19
-
20
4
/// Options for how a Transaction should behave when it is dropped.
21
5
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
22
6
#[ non_exhaustive]
@@ -71,7 +55,7 @@ impl Transaction<'_> {
71
55
/// where this is unacceptable, [`Transaction::new_unchecked`] is available.
72
56
#[ inline]
73
57
pub fn new ( conn : & mut Connection ) -> Result < Transaction < ' _ > > {
74
- Self :: new_unchecked ( conn, TransactionBehavior :: Deferred )
58
+ Self :: new_unchecked ( conn)
75
59
}
76
60
77
61
/// Begin a new transaction, failing if a transaction is open.
@@ -80,13 +64,7 @@ impl Transaction<'_> {
80
64
/// possible, [`Transaction::new`] should be preferred, as it provides a
81
65
/// compile-time guarantee that transactions are not nested.
82
66
#[ inline]
83
- fn new_unchecked ( conn : & Connection , _: TransactionBehavior ) -> Result < Transaction < ' _ > > {
84
- // TODO(wangfenjin): not supported
85
- // let query = match behavior {
86
- // TransactionBehavior::Deferred => "BEGIN DEFERRED",
87
- // TransactionBehavior::Immediate => "BEGIN IMMEDIATE",
88
- // TransactionBehavior::Exclusive => "BEGIN EXCLUSIVE",
89
- // };
67
+ fn new_unchecked ( conn : & Connection ) -> Result < Transaction < ' _ > > {
90
68
let query = "BEGIN Transaction" ;
91
69
conn. execute_batch ( query) . map ( move |_| Transaction {
92
70
conn,
@@ -206,19 +184,6 @@ impl Connection {
206
184
Transaction :: new ( self )
207
185
}
208
186
209
- /// Begin a new transaction with a specified behavior.
210
- ///
211
- /// See [`transaction`](Connection::transaction).
212
- ///
213
- /// # Failure
214
- ///
215
- /// Will return `Err` if the underlying DuckDB call fails.
216
- #[ inline]
217
- #[ allow( dead_code) ]
218
- fn transaction_with_behavior ( & mut self , behavior : TransactionBehavior ) -> Result < Transaction < ' _ > > {
219
- Transaction :: new_unchecked ( self , behavior)
220
- }
221
-
222
187
/// Begin a new transaction with the default behavior (DEFERRED).
223
188
///
224
189
/// Attempt to open a nested transaction will result in a DuckDB error.
@@ -251,7 +216,7 @@ impl Connection {
251
216
/// Will return `Err` if the underlying DuckDB call fails. The specific
252
217
/// error returned if transactions are nested is currently unspecified.
253
218
pub fn unchecked_transaction ( & self ) -> Result < Transaction < ' _ > > {
254
- Transaction :: new_unchecked ( self , TransactionBehavior :: Deferred )
219
+ Transaction :: new_unchecked ( self )
255
220
}
256
221
}
257
222
0 commit comments