Struct diesel::Connection [] [src]

pub struct Connection {
    // some fields omitted
}

Methods

impl Connection
[src]

fn establish(database_url: &str) -> ConnectionResult<Connection>

Establishes a new connection to the database at the given URL. The URL should be a PostgreSQL connection string, as documented at http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNSTRING

fn transaction<T, E, F>(&self, f: F) -> TransactionResult<T, E> where F: FnOnce() -> Result<T, E>

Executes the given function inside of a database transaction. When a transaction is already occurring, savepoints will be used to emulate a nested transaction.

If the function returns an Ok, that value will be returned. If the function returns an Err, TransactionError::UserReturnedError will be returned wrapping that value.

fn begin_test_transaction(&self) -> QueryResult<usize>

Creates a transaction that will never be committed. This is useful for tests. Panics if called while inside of a transaction.

fn test_transaction<T, E, F>(&self, f: F) -> T where F: FnOnce() -> Result<T, E>

Executes the given function inside a transaction, but does not commit it. Panics if the given function returns an Err.

fn find<T, U, PK>(&self, source: T, id: PK) -> QueryResult<U> where T: Table + FilterDsl<FindPredicate<T, PK>>, FindBy<T, T::PrimaryKey, PK>: LimitDsl, U: Queriable<Limit<FindBy<T, T::PrimaryKey, PK>>::SqlType>, PK: AsExpression<PkType<T>>, AsExpr<PK, T::PrimaryKey>: NonAggregate

Attempts to find a single record from the given table by primary key.

Example

let sean = (1, "Sean".to_string());
let tess = (2, "Tess".to_string());
assert_eq!(Ok(sean), connection.find(users, 1));
assert_eq!(Ok(tess), connection.find(users, 2));
assert_eq!(Err::<(i32, String), _>(NotFound), connection.find(users, 3));

Trait Implementations

impl Send for Connection
[src]

impl Drop for Connection
[src]

fn drop(&mut self)

A method called when the value goes out of scope. Read more