pub struct Repo<T> where
    T: Connection + 'static, 
{ /* private fields */ }
Expand description

A database “repository”, for running database workloads. Manages a connection pool and running blocking tasks using tokio::task::spawn_blocking which does not block the tokio event loop.




#[derive(Queryable, Debug)]
pub struct User {
    pub id: i32,
    pub name: String,
}

type Repo = gotham_middleware_diesel::Repo<SqliteConnection>;
let repo = Repo::new(database_url);
let result = runtime
    .block_on(repo.run(|conn| {
        use schema::users::dsl::*;
        users.load::<User>(&conn)
    }))
    .unwrap();

Implementations

Creates a repo with default connection pool settings. The default connection pool is r2d2::Builder::default()


type Repo = gotham_middleware_diesel::Repo<SqliteConnection>;
// Accepts a database URL, e.g. "postgres://username:password@host/database"
// for a postgres connection. Here we use an Sqlite in memory connection.
let repo = Repo::new(":memory:");

Creates a repo with a pool builder, allowing you to customize any connection pool configuration.

use core::time::Duration;
use r2d2::Pool;

type Repo = gotham_middleware_diesel::Repo<SqliteConnection>;
let database_url = ":memory:";
let repo = Repo::from_pool_builder(
    database_url,
    Pool::builder()
        .connection_timeout(Duration::from_secs(120))
        .max_size(100),
);

Creates a repo for use in tests, where queries are executed with an isolated test transaction and rolled back when the connection is dropped. This allows tests to run in parallel without impacting each other.


type Repo = gotham_middleware_diesel::Repo<SqliteConnection>;
let repo = Repo::with_test_transactions(":memory:");

Runs the given closure in a way that is safe for blocking IO to the database without blocking the tokio reactor. The closure will be passed a Connection from the pool to use.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Tries to borrow a value from the State storage. Read more

Borrows a value from the State storage. Read more

Tries to mutably borrow a value from the State storage. Read more

Mutably borrows a value from the State storage. Read more

Tries to move a value out of the State storage and return ownership. Read more

Moves a value out of the State storage and returns ownership. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert self to an expression for Diesel’s query builder. Read more

Convert &self to an expression for Diesel’s query builder. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more