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,13 +64,7 @@ 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- // };
67+ fn new_unchecked ( conn : & Connection ) -> Result < Transaction < ' _ > > {
9068 let query = "BEGIN Transaction" ;
9169 conn. execute_batch ( query) . map ( move |_| Transaction {
9270 conn,
@@ -206,19 +184,6 @@ impl Connection {
206184 Transaction :: new ( self )
207185 }
208186
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-
222187 /// Begin a new transaction with the default behavior (DEFERRED).
223188 ///
224189 /// Attempt to open a nested transaction will result in a DuckDB error.
@@ -251,7 +216,7 @@ impl Connection {
251216 /// Will return `Err` if the underlying DuckDB call fails. The specific
252217 /// error returned if transactions are nested is currently unspecified.
253218 pub fn unchecked_transaction ( & self ) -> Result < Transaction < ' _ > > {
254- Transaction :: new_unchecked ( self , TransactionBehavior :: Deferred )
219+ Transaction :: new_unchecked ( self )
255220 }
256221}
257222
0 commit comments