@@ -68,28 +68,18 @@ impl DbConnectionV3 {
68
68
69
69
{
70
70
let mut handle = self . write ( ) . await ;
71
- TxManager :: begin_transaction (
72
- handle. deref_mut ( ) ,
73
- )
74
- . await ?;
71
+ TxManager :: begin_transaction ( handle. deref_mut ( ) ) . await ?;
75
72
}
76
73
77
74
match callback ( self . clone ( ) ) . await {
78
75
Ok ( result) => {
79
76
let mut handle = self . write ( ) . await ;
80
- TxManager :: commit_transaction (
81
- handle. deref_mut ( ) ,
82
- )
83
- . await ?;
77
+ TxManager :: commit_transaction ( handle. deref_mut ( ) ) . await ?;
84
78
Ok ( result)
85
79
}
86
80
Err ( callback_error) => {
87
81
let mut handle = self . write ( ) . await ;
88
- match TxManager :: rollback_transaction (
89
- handle. deref_mut ( ) ,
90
- )
91
- . await
92
- {
82
+ match TxManager :: rollback_transaction ( handle. deref_mut ( ) ) . await {
93
83
Ok ( ( ) ) | Err ( diesel:: result:: Error :: BrokenTransactionManager ) => {
94
84
Err ( callback_error)
95
85
}
@@ -174,7 +164,7 @@ impl DbConnectionPoolV2 {
174
164
}
175
165
176
166
#[ cfg( feature = "testing" ) ]
177
- async fn get_connection ( & self ) -> Result < DbConnectionV2 , DatabasePoolError > {
167
+ async fn get_connection_v1 ( & self ) -> Result < DbConnectionV2 , DatabasePoolError > {
178
168
let Some ( test_connection) = & self . test_connection else {
179
169
panic ! (
180
170
"Test connection not initialized in test DatabasePool -- was `for_tests` called?"
@@ -185,7 +175,7 @@ impl DbConnectionPoolV2 {
185
175
}
186
176
187
177
#[ cfg( feature = "testing" ) ]
188
- async fn get_connection_v3 ( & self ) -> Result < DbConnectionV3 , DatabasePoolError > {
178
+ async fn get_connection ( & self ) -> Result < DbConnectionV3 , DatabasePoolError > {
189
179
Ok ( self
190
180
. test_connection_v3
191
181
. as_ref ( )
@@ -194,13 +184,13 @@ impl DbConnectionPoolV2 {
194
184
}
195
185
196
186
#[ cfg( not( feature = "testing" ) ) ]
197
- async fn get_connection ( & self ) -> Result < DbConnectionV2 , DatabasePoolError > {
187
+ async fn get_connection_v1 ( & self ) -> Result < DbConnectionV2 , DatabasePoolError > {
198
188
let connection = self . pool . get ( ) . await ?;
199
189
Ok ( connection)
200
190
}
201
191
202
192
#[ cfg( not( feature = "testing" ) ) ]
203
- async fn get_connection_v3 ( & self ) -> Result < DbConnectionV3 , DatabasePoolError > {
193
+ async fn get_connection ( & self ) -> Result < DbConnectionV3 , DatabasePoolError > {
204
194
let connection = self . pool . get ( ) . await ?;
205
195
Ok ( DbConnectionV3 :: new ( Arc :: new ( RwLock :: new ( connection) ) ) )
206
196
}
@@ -334,17 +324,17 @@ impl DbConnectionPoolV2 {
334
324
/// # Ok(())
335
325
/// # }
336
326
/// ```
337
- pub async fn get ( & self ) -> Result < DbConnectionV2 , DatabasePoolError > {
338
- self . get_connection ( ) . await
327
+ pub async fn get_v1 ( & self ) -> Result < DbConnectionV2 , DatabasePoolError > {
328
+ self . get_connection_v1 ( ) . await
339
329
}
340
330
341
- pub async fn get_v3 ( & self ) -> Result < DbConnectionV3 , DatabasePoolError > {
342
- self . get_connection_v3 ( ) . await
331
+ pub async fn get ( & self ) -> Result < DbConnectionV3 , DatabasePoolError > {
332
+ self . get_connection ( ) . await
343
333
}
344
334
345
335
#[ cfg( feature = "testing" ) ]
346
- pub fn get_ok_v3 ( & self ) -> DbConnectionV3 {
347
- futures:: executor:: block_on ( self . get_v3 ( ) ) . expect ( "Failed to get test connection" )
336
+ pub fn get_ok ( & self ) -> DbConnectionV3 {
337
+ futures:: executor:: block_on ( self . get ( ) ) . expect ( "Failed to get test connection" )
348
338
}
349
339
350
340
/// Gets a test connection from the pool synchronously, failing if the connection is not available
@@ -354,8 +344,8 @@ impl DbConnectionPoolV2 {
354
344
/// See [DbConnectionPoolV2::get] for more information on how connections should be used
355
345
/// in tests.
356
346
#[ cfg( feature = "testing" ) ]
357
- pub fn get_ok ( & self ) -> DbConnectionV2 {
358
- futures:: executor:: block_on ( self . get ( ) ) . expect ( "Failed to get test connection" )
347
+ pub fn get_ok_v1 ( & self ) -> DbConnectionV2 {
348
+ futures:: executor:: block_on ( self . get_v1 ( ) ) . expect ( "Failed to get test connection" )
359
349
}
360
350
361
351
/// Returns an infinite iterator of futures resolving to connections acquired from the pool
@@ -390,7 +380,7 @@ impl DbConnectionPoolV2 {
390
380
/// ```
391
381
pub fn iter_conn (
392
382
& self ,
393
- ) -> impl Iterator < Item = impl Future < Output = Result < DbConnectionV2 , DatabasePoolError > > + ' _ >
383
+ ) -> impl Iterator < Item = impl Future < Output = Result < DbConnection , DatabasePoolError > > + ' _ >
394
384
{
395
385
std:: iter:: repeat_with ( || self . get ( ) )
396
386
}
@@ -472,7 +462,9 @@ impl DbConnectionPoolV2 {
472
462
pub struct PingError ( #[ from] diesel:: result:: Error ) ;
473
463
474
464
pub async fn ping_database ( conn : & mut DbConnection ) -> Result < ( ) , PingError > {
475
- sql_query ( "SELECT 1" ) . execute ( conn) . await ?;
465
+ sql_query ( "SELECT 1" )
466
+ . execute ( conn. write ( ) . await . deref_mut ( ) )
467
+ . await ?;
476
468
Ok ( ( ) )
477
469
}
478
470
0 commit comments