Skip to main content

SyncConnectionWrapper

Type Alias SyncConnectionWrapper 

Source
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:

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 */ }