[][src]Struct gotham_middleware_diesel::Repo

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

A database "repository", for running database workloads. Manages a connection pool and running blocking tasks using tokio_threadpool::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 = repo.run(|conn| {
    use schema::users::dsl::*;
    users.load::<User>(&conn)
});

Methods

impl<T> Repo<T> where
    T: Connection + 'static, 
[src]

pub fn new(database_url: &str) -> Self[src]

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

pub fn from_pool_builder(
    database_url: &str,
    builder: Builder<ConnectionManager<T>>
) -> Self
[src]

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

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

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

pub fn with_test_transactions(database_url: &str) -> Self[src]

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

pub fn run<F, R, E>(&self, f: F) -> impl Future<Item = R, Error = E> where
    F: FnOnce(PooledConnection<ConnectionManager<T>>) -> Result<R, E> + Send + Unpin + 'static,
    T: Send + 'static, 
[src]

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

impl<T> Clone for Repo<T> where
    T: Connection + 'static, 
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T> StateData for Repo<T> where
    T: Connection + 'static, 
[src]

Auto Trait Implementations

impl<T> Sync for Repo<T>

impl<T> Send for Repo<T>

impl<T> Unpin for Repo<T>

impl<T> !RefUnwindSafe for Repo<T>

impl<T> !UnwindSafe for Repo<T>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> IntoSql for T[src]

fn into_sql<T>(self) -> Self::Expression where
    Self: AsExpression<T>, 
[src]

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

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
    &'a Self: AsExpression<T>, 
[src]

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

impl<T> FromState for T where
    T: StateData
[src]

impl<T> Erased for T