7
7
use pg:: GenericConnection ;
8
8
use r2d2;
9
9
use r2d2_postgres;
10
+ use r2d2_postgres:: postgres;
10
11
use r2d2_postgres:: PostgresConnectionManager as PCM ;
11
- use r2d2_postgres:: SslMode ;
12
+ use r2d2_postgres:: TlsMode ;
12
13
use conduit:: { Request , Response } ;
13
14
use conduit_middleware:: Middleware ;
14
15
@@ -19,8 +20,8 @@ pub type Pool = r2d2::Pool<PCM>;
19
20
pub type Config = r2d2:: Config < pg:: Connection , r2d2_postgres:: Error > ;
20
21
type PooledConnnection = r2d2:: PooledConnection < PCM > ;
21
22
22
- pub fn pool ( url : & str , config : r2d2:: Config < pg :: Connection , r2d2_postgres:: Error > ) -> Pool {
23
- let mgr = PCM :: new ( url, SslMode :: None ) . unwrap ( ) ;
23
+ pub fn pool ( url : & str , config : r2d2:: Config < postgres :: Connection , r2d2_postgres:: Error > ) -> Pool {
24
+ let mgr = PCM :: new ( url, TlsMode :: None ) . unwrap ( ) ;
24
25
r2d2:: Pool :: new ( config, mgr) . unwrap ( )
25
26
}
26
27
@@ -35,7 +36,7 @@ pub struct Transaction {
35
36
// into `PooledConnnection`, but this `Transaction` can be moved around in
36
37
// memory, so we need the borrow to be from a stable address. The `Box` will
37
38
// provide this stable address.
38
- tx : LazyCell < pg:: Transaction < ' static > > ,
39
+ tx : LazyCell < pg:: transaction :: Transaction < ' static > > ,
39
40
slot : LazyCell < Box < PooledConnnection > > ,
40
41
commit : Cell < Option < bool > > ,
41
42
@@ -55,14 +56,14 @@ impl Transaction {
55
56
}
56
57
}
57
58
58
- pub fn conn ( & self ) -> CargoResult < & pg :: Connection > {
59
+ pub fn conn ( & self ) -> CargoResult < & r2d2 :: PooledConnection < r2d2_postgres :: PostgresConnectionManager > > {
59
60
if !self . slot . filled ( ) {
60
61
let conn = try!( self . app . database . get ( ) . map_err ( |e| {
61
62
internal ( format ! ( "failed to get a database connection: {}" , e) )
62
63
} ) ) ;
63
64
self . slot . fill ( Box :: new ( conn) ) ;
64
65
}
65
- Ok ( & * * * self . slot . borrow ( ) . unwrap ( ) )
66
+ Ok ( & * * self . slot . borrow ( ) . unwrap ( ) )
66
67
}
67
68
68
69
fn tx < ' a > ( & ' a self ) -> CargoResult < & ' a ( GenericConnection + ' a ) > {
@@ -74,12 +75,12 @@ impl Transaction {
74
75
if !self . tx . filled ( ) {
75
76
let conn = try!( self . conn ( ) ) ;
76
77
let t = try!( conn. transaction ( ) ) ;
77
- let t = mem:: transmute :: < _ , pg:: Transaction < ' static > > ( t) ;
78
+ let t = mem:: transmute :: < _ , pg:: transaction :: Transaction < ' static > > ( t) ;
78
79
self . tx . fill ( t) ;
79
80
}
80
81
}
81
82
let tx = self . tx . borrow ( ) ;
82
- let tx: & ' a pg:: Transaction < ' static > = tx. unwrap ( ) ;
83
+ let tx: & ' a pg:: transaction :: Transaction < ' static > = tx. unwrap ( ) ;
83
84
Ok ( tx)
84
85
}
85
86
@@ -121,7 +122,7 @@ pub trait RequestTransaction {
121
122
/// Return the lazily initialized postgres connection for this request.
122
123
///
123
124
/// The connection will live for the lifetime of the request.
124
- fn db_conn ( & self ) -> CargoResult < & pg :: Connection > ;
125
+ fn db_conn ( & self ) -> CargoResult < & r2d2 :: PooledConnection < r2d2_postgres :: PostgresConnectionManager > > ;
125
126
126
127
/// Return the lazily initialized postgres transaction for this request.
127
128
///
@@ -136,7 +137,7 @@ pub trait RequestTransaction {
136
137
}
137
138
138
139
impl < ' a > RequestTransaction for Request + ' a {
139
- fn db_conn ( & self ) -> CargoResult < & pg :: Connection > {
140
+ fn db_conn ( & self ) -> CargoResult < & r2d2 :: PooledConnection < r2d2_postgres :: PostgresConnectionManager > > {
140
141
self . extensions ( ) . find :: < Transaction > ( )
141
142
. expect ( "Transaction not present in request" )
142
143
. conn ( )
0 commit comments