@@ -35,12 +35,14 @@ pub use postgres_shared::{params, Column, RowIndex};
35
35
use error:: { ConnectError , Error , DbError , SqlState } ;
36
36
use params:: { ConnectParams , IntoConnectParams } ;
37
37
use stream:: PostgresStream ;
38
- use types:: { Oid , Type , ToSql , SessionInfo , IsNull , FromSql , WrongType , Other , Kind , Field } ;
39
38
use tls:: Handshake ;
39
+ use transaction:: Transaction ;
40
+ use types:: { Oid , Type , ToSql , SessionInfo , IsNull , FromSql , WrongType , Other , Kind , Field } ;
40
41
41
42
pub mod error;
42
43
mod stream;
43
44
pub mod tls;
45
+ pub mod transaction;
44
46
#[ macro_use]
45
47
pub mod types;
46
48
@@ -905,7 +907,7 @@ impl Connection {
905
907
906
908
pub fn transaction ( self ) -> BoxFuture < Transaction , Error > {
907
909
self . simple_query ( "BEGIN" )
908
- . map ( |( _, c) | Transaction ( c) )
910
+ . map ( |( _, c) | Transaction :: new ( c) )
909
911
. boxed ( )
910
912
}
911
913
@@ -991,59 +993,6 @@ impl Row {
991
993
}
992
994
}
993
995
994
- #[ derive( Debug ) ]
995
- pub struct Transaction ( Connection ) ;
996
-
997
- impl Transaction {
998
- pub fn batch_execute ( self , query : & str ) -> BoxFuture < Transaction , Error < Transaction > > {
999
- self . 0 . batch_execute ( query)
1000
- . map ( Transaction )
1001
- . map_err ( transaction_err)
1002
- . boxed ( )
1003
- }
1004
-
1005
- pub fn prepare ( self , query : & str ) -> BoxFuture < ( Statement , Transaction ) , Error < Transaction > > {
1006
- self . 0 . prepare ( query)
1007
- . map ( |( s, c) | ( s, Transaction ( c) ) )
1008
- . map_err ( transaction_err)
1009
- . boxed ( )
1010
- }
1011
-
1012
- pub fn execute ( self ,
1013
- statement : & Statement ,
1014
- params : & [ & ToSql ] )
1015
- -> BoxFuture < ( u64 , Transaction ) , Error < Transaction > > {
1016
- self . 0 . execute ( statement, params)
1017
- . map ( |( n, c) | ( n, Transaction ( c) ) )
1018
- . map_err ( transaction_err)
1019
- . boxed ( )
1020
- }
1021
-
1022
- pub fn query ( self ,
1023
- statement : & Statement ,
1024
- params : & [ & ToSql ] )
1025
- -> BoxStateStream < Row , Transaction , Error < Transaction > > {
1026
- self . 0 . query ( statement, params)
1027
- . map_state ( Transaction )
1028
- . map_err ( transaction_err)
1029
- . boxed ( )
1030
- }
1031
-
1032
- pub fn commit ( self ) -> BoxFuture < Connection , Error > {
1033
- self . finish ( "COMMIT" )
1034
- }
1035
-
1036
- pub fn rollback ( self ) -> BoxFuture < Connection , Error > {
1037
- self . finish ( "ROLLBACK" )
1038
- }
1039
-
1040
- fn finish ( self , query : & str ) -> BoxFuture < Connection , Error > {
1041
- self . 0 . simple_query ( query)
1042
- . map ( |( _, c) | c)
1043
- . boxed ( )
1044
- }
1045
- }
1046
-
1047
996
fn connect_err ( fields : & mut ErrorFields ) -> ConnectError {
1048
997
match DbError :: new ( fields) {
1049
998
Ok ( err) => ConnectError :: Db ( Box :: new ( err) ) ,
@@ -1057,10 +1006,6 @@ fn bad_message<T>() -> T
1057
1006
io:: Error :: new ( io:: ErrorKind :: InvalidInput , "unexpected message" ) . into ( )
1058
1007
}
1059
1008
1060
- fn transaction_err ( e : Error ) -> Error < Transaction > {
1061
- match e {
1062
- Error :: Io ( e) => Error :: Io ( e) ,
1063
- Error :: Db ( e, c) => Error :: Db ( e, Transaction ( c) ) ,
1064
- Error :: Conversion ( e, c) => Error :: Conversion ( e, Transaction ( c) )
1065
- }
1009
+ trait TransactionNew {
1010
+ fn new ( c : Connection ) -> Transaction ;
1066
1011
}
0 commit comments