Crate diesel_async

source ·
Expand description

Diesel-async provides async variants of diesel releated query functionality

diesel-async is an extension to diesel itself. It is designed to be used togehter 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:

These traits closely mirror their diesel counter parts while providing async functionality.

In addition to these core traits 2 fully async connection implementations are provided by diesel-async:

  • [AsyncMysqlConnection] (enabled by the mysql feature)
  • AsyncPgConnection (enabled by the postgres feature)

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);

Re-exports

Modules

  • The traits used by QueryDsl.
  • Provides types and functions related to working with PostgreSQL
  • This module contains support using diesel-async with various async rust connection pooling solutions
  • The return types produces by the various RunQueryDsl methods

Structs

  • An implementation of TransactionManager which can be used for backends which use ANSI standard syntax for savepoints such as SQLite and PostgreSQL.
  • A connection to a PostgreSQL database.

Enums

Traits