File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -638,6 +638,12 @@ impl Connection {
638
638
. boxed ( )
639
639
}
640
640
641
+ pub fn transaction ( self ) -> BoxFuture < Transaction , Error > {
642
+ self . simple_query ( "BEGIN" )
643
+ . map ( |( _, c) | Transaction ( c) )
644
+ . boxed ( )
645
+ }
646
+
641
647
pub fn close ( self ) -> BoxFuture < ( ) , Error > {
642
648
let mut terminate = vec ! [ ] ;
643
649
frontend:: terminate ( & mut terminate) ;
@@ -720,6 +726,24 @@ impl Row {
720
726
}
721
727
}
722
728
729
+ pub struct Transaction ( Connection ) ;
730
+
731
+ impl Transaction {
732
+ pub fn commit ( self ) -> BoxFuture < Connection , Error > {
733
+ self . finish ( "COMMIT" )
734
+ }
735
+
736
+ pub fn rollback ( self ) -> BoxFuture < Connection , Error > {
737
+ self . finish ( "ROLLBACK" )
738
+ }
739
+
740
+ fn finish ( self , query : & str ) -> BoxFuture < Connection , Error > {
741
+ self . 0 . simple_query ( query)
742
+ . map ( |( _, c) | c)
743
+ . boxed ( )
744
+ }
745
+ }
746
+
723
747
fn connect_err ( fields : & mut ErrorFields ) -> ConnectError {
724
748
match DbError :: new ( fields) {
725
749
Ok ( err) => ConnectError :: Db ( Box :: new ( err) ) ,
You can’t perform that action at this time.
0 commit comments