[−][src]Struct sudoku_backend::ops::setup::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]
impl DatabaseConnectionpub fn initialise(
db_file: &(String, PathBuf)
) -> Pool<ConnectionManager<SqliteConnection>>[src]
pub fn initialise(
db_file: &(String, PathBuf)
) -> Pool<ConnectionManager<SqliteConnection>>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>
pub fn immediate_transaction<T, E, F>(&self, f: F) -> Result<T, E> where
E: From<Error>,
F: FnOnce() -> Result<T, E>, [src]
pub fn immediate_transaction<T, E, F>(&self, f: F) -> Result<T, E> where
E: From<Error>,
F: FnOnce() -> Result<T, E>, 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(()) })
pub fn exclusive_transaction<T, E, F>(&self, f: F) -> Result<T, E> where
E: From<Error>,
F: FnOnce() -> Result<T, E>, [src]
pub fn exclusive_transaction<T, E, F>(&self, f: F) -> Result<T, E> where
E: From<Error>,
F: FnOnce() -> Result<T, E>, 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]
impl Deref for DatabaseConnectiontype Target = SqliteConnection
The resulting type after dereferencing.
fn deref(&self) -> &SqliteConnection[src]
fn deref(&self) -> &SqliteConnectionimpl<'a, 'r> FromRequest<'a, 'r> for DatabaseConnection[src]
impl<'a, 'r> FromRequest<'a, 'r> for DatabaseConnectionAttempts 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.
type Error = ()
The associated error to be returned if derivation fails.
fn from_request(
request: &'a Request<'r>
) -> RequestOutcome<DatabaseConnection, ()>[src]
fn from_request(
request: &'a Request<'r>
) -> RequestOutcome<DatabaseConnection, ()>Auto Trait Implementations
impl Send for DatabaseConnection
impl Send for DatabaseConnectionimpl !Sync for DatabaseConnection
impl !Sync for DatabaseConnectionBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeIdimpl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut Timpl<T> Typeable for T where
T: Any, [src]
impl<T> Typeable for T where
T: Any, impl<T> IntoSql for T[src]
impl<T> IntoSql for Tfn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>, [src]
fn into_sql<T>(self) -> Self::Expression where
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]
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>, Convert &self to an expression for Diesel's query builder. Read more