[−][src]Struct gotham_middleware_diesel::Repo
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]
T: Connection + 'static,
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]
database_url: &str,
builder: Builder<ConnectionManager<T>>
) -> Self
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]
F: FnOnce(PooledConnection<ConnectionManager<T>>) -> Result<R, E> + Send + Unpin + 'static,
T: Send + 'static,
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]
T: Connection + 'static,
fn clone(&self) -> Repo<T>
[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]
T: Connection + 'static,
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]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> IntoSql for T
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
Self: AsExpression<T>,
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]
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more
impl<T> FromState for T where
T: StateData,
[src]
T: StateData,