@@ -23,17 +23,17 @@ pub enum IsolationLevel {
2323pub struct TransactionBuilder < ' a > {
2424 client : & ' a mut Client ,
2525 isolation_level : Option < IsolationLevel > ,
26- read_only : bool ,
27- deferrable : bool ,
26+ read_only : Option < bool > ,
27+ deferrable : Option < bool > ,
2828}
2929
3030impl < ' a > TransactionBuilder < ' a > {
3131 pub ( crate ) fn new ( client : & ' a mut Client ) -> TransactionBuilder < ' a > {
3232 TransactionBuilder {
3333 client,
3434 isolation_level : None ,
35- read_only : false ,
36- deferrable : false ,
35+ read_only : None ,
36+ deferrable : None ,
3737 }
3838 }
3939
@@ -43,19 +43,19 @@ impl<'a> TransactionBuilder<'a> {
4343 self
4444 }
4545
46- /// Sets the transaction to read-only .
47- pub fn read_only ( mut self ) -> Self {
48- self . read_only = true ;
46+ /// Sets the access mode of the transaction .
47+ pub fn read_only ( mut self , read_only : bool ) -> Self {
48+ self . read_only = Some ( read_only ) ;
4949 self
5050 }
5151
52- /// Sets the transaction to be deferrable .
52+ /// Sets the deferrability of the transaction .
5353 ///
5454 /// If the transaction is also serializable and read only, creation of the transaction may block, but when it
5555 /// completes the transaction is able to run with less overhead and a guarantee that it will not be aborted due to
5656 /// serialization failure.
57- pub fn deferrable ( mut self ) -> Self {
58- self . deferrable = true ;
57+ pub fn deferrable ( mut self , deferrable : bool ) -> Self {
58+ self . deferrable = Some ( deferrable ) ;
5959 self
6060 }
6161
@@ -79,21 +79,31 @@ impl<'a> TransactionBuilder<'a> {
7979 query. push_str ( level) ;
8080 }
8181
82- if self . read_only {
82+ if let Some ( read_only ) = self . read_only {
8383 if !first {
8484 query. push ( ',' ) ;
8585 }
8686 first = false ;
8787
88- query. push_str ( " READ ONLY" ) ;
88+ let s = if read_only {
89+ " READ ONLY"
90+ } else {
91+ " READ WRITE"
92+ } ;
93+ query. push_str ( s) ;
8994 }
9095
91- if self . deferrable {
96+ if let Some ( deferrable ) = self . deferrable {
9297 if !first {
9398 query. push ( ',' ) ;
9499 }
95100
96- query. push_str ( " DEFERRABLE" ) ;
101+ let s = if deferrable {
102+ " DEFERRABLE"
103+ } else {
104+ " NOT DEFERRABLE"
105+ } ;
106+ query. push_str ( s) ;
97107 }
98108
99109 self . client . batch_execute ( & query) . await ?;
0 commit comments