File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ pub use self::implementation::AsyncConnectionWrapper;
101
101
102
102
mod implementation {
103
103
use diesel:: connection:: { Instrumentation , SimpleConnection } ;
104
+ use std:: ops:: { Deref , DerefMut } ;
104
105
105
106
use super :: * ;
106
107
@@ -122,6 +123,20 @@ mod implementation {
122
123
}
123
124
}
124
125
126
+ impl < C , B > Deref for AsyncConnectionWrapper < C , B > {
127
+ type Target = C ;
128
+
129
+ fn deref ( & self ) -> & Self :: Target {
130
+ & self . inner
131
+ }
132
+ }
133
+
134
+ impl < C , B > DerefMut for AsyncConnectionWrapper < C , B > {
135
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
136
+ & mut self . inner
137
+ }
138
+ }
139
+
125
140
impl < C , B > diesel:: connection:: SimpleConnection for AsyncConnectionWrapper < C , B >
126
141
where
127
142
C : crate :: SimpleAsyncConnection ,
Original file line number Diff line number Diff line change 1
1
use diesel:: migration:: Migration ;
2
- use diesel:: prelude :: * ;
2
+ use diesel:: { Connection , IntoSql } ;
3
3
use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
4
4
5
5
#[ test]
6
6
fn test_sync_wrapper ( ) {
7
+ use diesel:: RunQueryDsl ;
8
+
7
9
let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
8
10
let mut conn = AsyncConnectionWrapper :: < crate :: TestConnection > :: establish ( & db_url) . unwrap ( ) ;
9
11
@@ -12,8 +14,24 @@ fn test_sync_wrapper() {
12
14
assert_eq ! ( Ok ( 1 ) , res) ;
13
15
}
14
16
17
+ #[ tokio:: test]
18
+ async fn test_sync_wrapper_async_query ( ) {
19
+ use diesel_async:: { AsyncConnection , RunQueryDsl } ;
20
+
21
+ let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
22
+ let conn = crate :: TestConnection :: establish ( & db_url) . await . unwrap ( ) ;
23
+ let mut conn = AsyncConnectionWrapper :: < _ > :: from ( conn) ;
24
+
25
+ let res = diesel:: select ( 1 . into_sql :: < diesel:: sql_types:: Integer > ( ) )
26
+ . get_result :: < i32 > ( & mut conn)
27
+ . await ;
28
+ assert_eq ! ( Ok ( 1 ) , res) ;
29
+ }
30
+
15
31
#[ tokio:: test]
16
32
async fn test_sync_wrapper_under_runtime ( ) {
33
+ use diesel:: RunQueryDsl ;
34
+
17
35
let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
18
36
tokio:: task:: spawn_blocking ( move || {
19
37
let mut conn = AsyncConnectionWrapper :: < crate :: TestConnection > :: establish ( & db_url) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments