Expand description
Diesel-async provides async variants of diesel related query functionality
diesel-async is an extension to diesel itself. It is designed to be used together with the main diesel crate. It only provides async variants of core diesel traits, that perform actual io-work. This includes async counterparts the following traits:
diesel::prelude::RunQueryDsl->diesel_async::RunQueryDsldiesel::connection::Connection->diesel_async::AsyncConnectiondiesel::query_dsl::UpdateAndFetchResults->diesel_async::UpdateAndFetchResults
These traits closely mirror their diesel counter parts while providing async functionality.
In addition to these core traits 3 fully async connection implementations are provided by diesel-async:
AsyncMysqlConnection(enabled by themysqlfeature)AsyncPgConnection(enabled by thepostgresfeature)SyncConnectionWrapper(enabled by thesync-connection-wrapper/sqlitefeature)
Ordinary usage of diesel-async assumes that you just replace the corresponding sync trait
method calls and connections with their async counterparts.
use diesel::prelude::*;
use diesel_async::{RunQueryDsl, AsyncConnection};
diesel::table! {
users(id) {
id -> Integer,
name -> Text,
}
}
use crate::users::dsl::*;
let mut connection = AsyncPgConnection::establish(std::env::var("DATABASE_URL")?).await?;
let data = users
// use ordinary diesel query dsl here
.filter(id.gt(0))
// execute the query via the provided
// async variant of `diesel_async::RunQueryDsl`
.load::<(i32, String)>(&mut connection)
.await?;
let expected_data = vec![
(1, String::from("Sean")),
(2, String::from("Tess")),
];
assert_eq!(expected_data, data);§Crate features:
postgres: Enables theAsyncPgConnectionimplementationmysql: Enables theAsyncMysqlConnectionimplementationsqlite: Enables theSyncConnectionWrapperand everything required to work with SQLitesync-connection-wrapper: Enables theSyncConnectionWrapperwhich allows to wrap sync connections fromdieselinto async connection wrapperasync-connection-wrapper: Enables theAsyncConnectionWrapperwhich allows to use connection implementations from this crate as syncdiesel::Connectionmigrations: Enables theAsyncMigrationHarnessto execute migrations viadiesel_migrationspool: Enables general support for connection poolsr2d2: Enables support for pooling via the [r2d2] cratebb8: Enables support for pooling via thebb8cratemobc: Enables support for pooling via themobccratedeadpool: Enables support for pooling via thedeadpoolcrate
Re-exports§
pub use scoped_futures;
Modules§
- async_
connection_ wrapper async-connection-wrapper - This module contains an wrapper type
that provides a
diesel::Connectionimplementation for types that implementcrate::AsyncConnection. Using this type might be useful for the following usecases: - methods
- The traits used by
QueryDsl. - pg
postgres - Provides types and functions related to working with PostgreSQL
- pooled_
connection pool - This module contains support using diesel-async with various async rust connection pooling solutions
- return_
futures - The return types produced by the various
RunQueryDslmethods - sync_
connection_ wrapper sync-connection-wrapper - This module contains a wrapper type
that provides a
crate::AsyncConnectionimplementation for types that implementdiesel::Connection. Using this type might be useful for the following usecases:
Structs§
- Ansi
Transaction Manager - An implementation of
TransactionManagerwhich can be used for backends which use ANSI standard syntax for savepoints such as SQLite and PostgreSQL. - Async
Migration Harness migrations - A diesel-migration
MigrationHarnessto run migrations via anAsyncConnection - Async
Mysql Connection mysql - A connection to a MySQL database. Connection URLs should be in the form
mysql://[user[:password]@]host/database_name - Async
PgConnection postgres - A connection to a PostgreSQL database.
- Mysql
Cancel Token mysql - The capability to request cancellation of in-progress queries on a connection.
Traits§
- Async
Connection - An async connection to a database
- Async
Connection Core - Core trait for an async database connection
- RunQuery
Dsl - Methods used to execute queries.
- Save
Changes Dsl - Sugar for types which implement both
AsChangesetandIdentifiable - Simple
Async Connection - Perform simple operations on a backend.
- Transaction
Manager - Manages the internal transaction state for a connection.
- Update
AndFetch Results - A trait defining how to update a record and fetch the updated entry on a certain backend.