File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-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 ;
78 // The runtime is required for the `sqlite` implementation to be able to use
89 // `spawn_blocking()`. This is not required for `postgres` or `mysql`.
910 #[ cfg( feature = "sqlite" ) ]
@@ -23,8 +24,24 @@ fn test_sync_wrapper() {
2324 assert_eq ! ( Ok ( 1 ) , res) ;
2425}
2526
27+ #[ tokio:: test]
28+ async fn test_sync_wrapper_async_query ( ) {
29+ use diesel_async:: { AsyncConnection , RunQueryDsl } ;
30+
31+ let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
32+ let conn = crate :: TestConnection :: establish ( & db_url) . await . unwrap ( ) ;
33+ let mut conn = AsyncConnectionWrapper :: < _ > :: from ( conn) ;
34+
35+ let res = diesel:: select ( 1 . into_sql :: < diesel:: sql_types:: Integer > ( ) )
36+ . get_result :: < i32 > ( & mut conn)
37+ . await ;
38+ assert_eq ! ( Ok ( 1 ) , res) ;
39+ }
40+
2641#[ tokio:: test]
2742async fn test_sync_wrapper_under_runtime ( ) {
43+ use diesel:: RunQueryDsl ;
44+
2845 let db_url = std:: env:: var ( "DATABASE_URL" ) . unwrap ( ) ;
2946 tokio:: task:: spawn_blocking ( move || {
3047 let mut conn = AsyncConnectionWrapper :: < crate :: TestConnection > :: establish ( & db_url) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments