11use crate :: { Connection , Result } ;
22use std:: ops:: Deref ;
33
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-
204/// Options for how a Transaction should behave when it is dropped.
215#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
226#[ non_exhaustive]
@@ -71,7 +55,7 @@ impl Transaction<'_> {
7155 /// where this is unacceptable, [`Transaction::new_unchecked`] is available.
7256 #[ inline]
7357 pub fn new ( conn : & mut Connection ) -> Result < Transaction < ' _ > > {
74- Self :: new_unchecked ( conn, TransactionBehavior :: Deferred )
58+ Self :: new_unchecked ( conn)
7559 }
7660
7761 /// Begin a new transaction, failing if a transaction is open.
@@ -80,14 +64,8 @@ impl Transaction<'_> {
8064 /// possible, [`Transaction::new`] should be preferred, as it provides a
8165 /// compile-time guarantee that transactions are not nested.
8266 #[ 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" ;
9169 conn. execute_batch ( query) . map ( move |_| Transaction {
9270 conn,
9371 drop_behavior : DropBehavior :: Rollback ,
@@ -116,8 +94,7 @@ impl Transaction<'_> {
11694
11795 #[ inline]
11896 fn commit_ ( & mut self ) -> Result < ( ) > {
119- self . conn . execute_batch ( "COMMIT" ) ?;
120- Ok ( ( ) )
97+ self . conn . execute_batch ( "COMMIT" )
12198 }
12299
123100 /// A convenience method which consumes and rolls back a transaction.
@@ -128,8 +105,7 @@ impl Transaction<'_> {
128105
129106 #[ inline]
130107 fn rollback_ ( & mut self ) -> Result < ( ) > {
131- self . conn . execute_batch ( "ROLLBACK" ) ?;
132- Ok ( ( ) )
108+ self . conn . execute_batch ( "ROLLBACK" )
133109 }
134110
135111 /// Consumes the transaction, committing or rolling back according to the
@@ -206,19 +182,6 @@ impl Connection {
206182 Transaction :: new ( self )
207183 }
208184
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-
222185 /// Begin a new transaction with the default behavior (DEFERRED).
223186 ///
224187 /// Attempt to open a nested transaction will result in a DuckDB error.
@@ -251,7 +214,7 @@ impl Connection {
251214 /// Will return `Err` if the underlying DuckDB call fails. The specific
252215 /// error returned if transactions are nested is currently unspecified.
253216 pub fn unchecked_transaction ( & self ) -> Result < Transaction < ' _ > > {
254- Transaction :: new_unchecked ( self , TransactionBehavior :: Deferred )
217+ Transaction :: new_unchecked ( self )
255218 }
256219}
257220
0 commit comments