@@ -726,9 +726,44 @@ impl Row {
726726 }
727727}
728728
729+ #[ derive( Debug ) ]
729730pub struct Transaction ( Connection ) ;
730731
731732impl Transaction {
733+ pub fn batch_execute ( self , query : & str ) -> BoxFuture < Transaction , Error < Transaction > > {
734+ self . 0 . batch_execute ( query)
735+ . map ( Transaction )
736+ . map_err ( transaction_err)
737+ . boxed ( )
738+ }
739+
740+ pub fn prepare ( self , query : & str ) -> BoxFuture < ( Statement , Transaction ) , Error < Transaction > > {
741+ self . 0 . prepare ( query)
742+ . map ( |( s, c) | ( s, Transaction ( c) ) )
743+ . map_err ( transaction_err)
744+ . boxed ( )
745+ }
746+
747+ pub fn execute ( self ,
748+ statement : & Statement ,
749+ params : & [ & ToSql ] )
750+ -> BoxFuture < ( u64 , Transaction ) , Error < Transaction > > {
751+ self . 0 . execute ( statement, params)
752+ . map ( |( n, c) | ( n, Transaction ( c) ) )
753+ . map_err ( transaction_err)
754+ . boxed ( )
755+ }
756+
757+ pub fn query ( self ,
758+ statement : & Statement ,
759+ params : & [ & ToSql ] )
760+ -> BoxStateStream < Row , Transaction , Error < Transaction > > {
761+ self . 0 . query ( statement, params)
762+ . map_state ( Transaction )
763+ . map_err ( transaction_err)
764+ . boxed ( )
765+ }
766+
732767 pub fn commit ( self ) -> BoxFuture < Connection , Error > {
733768 self . finish ( "COMMIT" )
734769 }
@@ -756,3 +791,11 @@ fn bad_message<T>() -> T
756791{
757792 io:: Error :: new ( io:: ErrorKind :: InvalidInput , "unexpected message" ) . into ( )
758793}
794+
795+ fn transaction_err ( e : Error ) -> Error < Transaction > {
796+ match e {
797+ Error :: Io ( e) => Error :: Io ( e) ,
798+ Error :: Db ( e, c) => Error :: Db ( e, Transaction ( c) ) ,
799+ Error :: Conversion ( e, c) => Error :: Conversion ( e, Transaction ( c) )
800+ }
801+ }
0 commit comments