[][src]Struct sudoku_backend::ops::setup::DatabaseConnection

pub struct DatabaseConnection(_);

Connection request guard type: a wrapper around an r2d2 pooled connection.

Use this as an argument to a Rocket request handler after having it manage()d to gain access to the database.

Examples

#[get("/databased")]
fn databased(db: DatabaseConnection) -> String {
    // Do some database ops, which are outside the scope of this document
    funxion_result
}

fn main() {
    let database_file: (String, PathBuf) = /* obtained elsewhere */;
    rocket::ignite()
        .manage(DatabaseConnection::initialise(&database_file))
        .mount("/", routes![databased])
        .launch();
}

Methods

impl DatabaseConnection
[src]

Set up a connection to the main database located in the specified file and initialise it with util::INITIALISE_DATABASE.

Methods from Deref<Target = SqliteConnection>

Run a transaction with BEGIN IMMEDIATE

This method will return an error if a transaction is already open.

Example

conn.immediate_transaction(|| {
    // Do stuff in a transaction
    Ok(())
})

Run a transaction with BEGIN EXCLUSIVE

This method will return an error if a transaction is already open.

Example

conn.exclusive_transaction(|| {
    // Do stuff in a transaction
    Ok(())
})

Trait Implementations

impl Deref for DatabaseConnection
[src]

The resulting type after dereferencing.

impl<'a, 'r> FromRequest<'a, 'r> for DatabaseConnection
[src]

Attempts to retrieve a single connection from the managed database pool.

If no pool is currently managed, fails with an InternalServerError status. If no connections are available, fails with a ServiceUnavailable status.

The associated error to be returned if derivation fails.

Auto Trait Implementations

impl Send for DatabaseConnection

impl !Sync for DatabaseConnection

Blanket Implementations

impl<T> From for T
[src]

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

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

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

The type returned in the event of a conversion error.

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

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

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

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

The type returned in the event of a conversion error.

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

impl<T> Typeable for T where
    T: Any
[src]

Get the TypeId of this object.

impl<T> IntoSql for T
[src]

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

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