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,14 +64,8 @@ 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
- // };
90
- let query = "BEGIN Transaction" ;
67
+ fn new_unchecked ( conn : & Connection ) -> Result < Transaction < ' _ > > {
68
+ let query = "BEGIN TRANSACTION" ;
91
69
conn. execute_batch ( query) . map ( move |_| Transaction {
92
70
conn,
93
71
drop_behavior : DropBehavior :: Rollback ,
@@ -116,8 +94,7 @@ impl Transaction<'_> {
116
94
117
95
#[ inline]
118
96
fn commit_ ( & mut self ) -> Result < ( ) > {
119
- self . conn . execute_batch ( "COMMIT" ) ?;
120
- Ok ( ( ) )
97
+ self . conn . execute_batch ( "COMMIT" )
121
98
}
122
99
123
100
/// A convenience method which consumes and rolls back a transaction.
@@ -128,8 +105,7 @@ impl Transaction<'_> {
128
105
129
106
#[ inline]
130
107
fn rollback_ ( & mut self ) -> Result < ( ) > {
131
- self . conn . execute_batch ( "ROLLBACK" ) ?;
132
- Ok ( ( ) )
108
+ self . conn . execute_batch ( "ROLLBACK" )
133
109
}
134
110
135
111
/// Consumes the transaction, committing or rolling back according to the
@@ -206,19 +182,6 @@ impl Connection {
206
182
Transaction :: new ( self )
207
183
}
208
184
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
185
/// Begin a new transaction with the default behavior (DEFERRED).
223
186
///
224
187
/// Attempt to open a nested transaction will result in a DuckDB error.
@@ -251,7 +214,7 @@ impl Connection {
251
214
/// Will return `Err` if the underlying DuckDB call fails. The specific
252
215
/// error returned if transactions are nested is currently unspecified.
253
216
pub fn unchecked_transaction ( & self ) -> Result < Transaction < ' _ > > {
254
- Transaction :: new_unchecked ( self , TransactionBehavior :: Deferred )
217
+ Transaction :: new_unchecked ( self )
255
218
}
256
219
}
257
220
0 commit comments