pub type SyncConnectionWrapper<C, B = Tokio> = SyncConnectionWrapper<C, B>;Expand description
A wrapper of a diesel::connection::Connection usable in async context.
It implements AsyncConnection if diesel::connection::Connection fulfils requirements:
- it’s a
diesel::connection::LoadConnection - its
diesel::connection::Connection::Backendhas adiesel::query_builder::BindCollectorimplementingdiesel::query_builder::MoveableBindCollector - its
diesel::connection::LoadConnection::Rowimplementsdiesel::row::IntoOwnedRow
Internally this wrapper type will use spawn_blocking on tokio
to execute the request on the inner connection. This implies a
dependency on tokio and that the runtime is running.
Note that only SQLite is supported at the moment.
§Examples
use diesel_async::RunQueryDsl;
use schema::users;
async fn some_async_fn() {
use diesel_async::AsyncConnection;
use diesel::sqlite::SqliteConnection;
let mut conn =
SyncConnectionWrapper::<SqliteConnection>::establish(&database_url).await.unwrap();
let all_users = users::table.load::<(i32, String)>(&mut conn).await.unwrap();
}
Aliased Type§
pub struct SyncConnectionWrapper<C, B = Tokio> { /* private fields */ }