Skip to content

Commit 09c91a7

Browse files
authored
Merge pull request #247 from imintz/imintz/async_connection_wrapper_unwrap
Add AsyncConnectionWrapper::into_inner
2 parents cbcf68f + 0bfd612 commit 09c91a7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/async_connection_wrapper.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ mod implementation {
123123
}
124124
}
125125

126+
impl<C, B> AsyncConnectionWrapper<C, B>
127+
where
128+
C: crate::AsyncConnection,
129+
{
130+
/// Consumes the [`AsyncConnectionWrapper`] returning the wrapped inner
131+
/// [`AsyncConnection`].
132+
pub fn into_inner(self) -> C {
133+
self.inner
134+
}
135+
}
136+
126137
impl<C, B> Deref for AsyncConnectionWrapper<C, B> {
127138
type Target = C;
128139

tests/sync_wrapper.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,30 @@ fn check_run_migration() {
6666
// just use `run_migrations` here because that's the easiest one without additional setup
6767
conn.run_migrations(&migrations).unwrap();
6868
}
69+
70+
#[tokio::test]
71+
async fn test_sync_wrapper_unwrap() {
72+
let db_url = std::env::var("DATABASE_URL").unwrap();
73+
74+
let conn = tokio::task::spawn_blocking(move || {
75+
use diesel::RunQueryDsl;
76+
77+
let mut conn = AsyncConnectionWrapper::<crate::TestConnection>::establish(&db_url).unwrap();
78+
let res =
79+
diesel::select(1.into_sql::<diesel::sql_types::Integer>()).get_result::<i32>(&mut conn);
80+
assert_eq!(Ok(1), res);
81+
conn
82+
})
83+
.await
84+
.unwrap();
85+
86+
{
87+
use diesel_async::RunQueryDsl;
88+
89+
let mut conn = conn.into_inner();
90+
let res = diesel::select(1.into_sql::<diesel::sql_types::Integer>())
91+
.get_result::<i32>(&mut conn)
92+
.await;
93+
assert_eq!(Ok(1), res);
94+
}
95+
}

0 commit comments

Comments
 (0)