File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 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;
101101
102102mod implementation {
103103 use diesel:: connection:: { Instrumentation , SimpleConnection } ;
104+ use std:: ops:: { Deref , DerefMut } ;
104105
105106 use super :: * ;
106107
@@ -122,6 +123,20 @@ mod implementation {
122123 }
123124 }
124125
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+
125140 impl < C , B > diesel:: connection:: SimpleConnection for AsyncConnectionWrapper < C , B >
126141 where
127142 C : crate :: SimpleAsyncConnection ,
Original file line number Diff line number Diff line change 11use diesel:: migration:: Migration ;
2- use diesel:: prelude :: * ;
2+ use diesel:: { Connection , IntoSql } ;
33use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
44
55#[ test]
66fn test_sync_wrapper ( ) {
7+ use diesel:: RunQueryDsl ;
8+
79 let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
810 let mut conn = AsyncConnectionWrapper :: < crate :: TestConnection > :: establish ( & db_url) . unwrap ( ) ;
911
@@ -12,8 +14,24 @@ fn test_sync_wrapper() {
1214 assert_eq ! ( Ok ( 1 ) , res) ;
1315}
1416
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+
1531#[ tokio:: test]
1632async fn test_sync_wrapper_under_runtime ( ) {
33+ use diesel:: RunQueryDsl ;
34+
1735 let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
1836 tokio:: task:: spawn_blocking ( move || {
1937 let mut conn = AsyncConnectionWrapper :: < crate :: TestConnection > :: establish ( & db_url) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments