Add 'Connection::into_inner()' in 'db_pools'.

Resolves #1790.
This commit is contained in:
Sergio Benitez 2021-08-30 04:02:13 -07:00
parent 9bc6c25d2d
commit 8cae077ba1
1 changed files with 31 additions and 0 deletions

View File

@ -214,6 +214,37 @@ impl<D: Database> Initializer<D> {
}
}
impl<D: Database> Connection<D> {
/// Returns the internal connection value. See the [`Connection` Deref
/// column](crate#supported-drivers) for the expected type of this value.
///
/// Note that `Connection<D>` derefs to the internal connection type, so
/// using this method is likely unnecessary. See [deref](Connection#deref)
/// for examples.
///
/// # Example
///
/// ```rust
/// # #[cfg(feature = "sqlx_sqlite")] mod _inner {
/// # use rocket::get;
/// # type Pool = rocket_db_pools::sqlx::SqlitePool;
/// use rocket_db_pools::{Database, Connection};
///
/// #[derive(Database)]
/// #[database("db")]
/// struct Db(Pool);
///
/// #[get("/")]
/// async fn db_op(db: Connection<Db>) {
/// let inner = db.into_inner();
/// }
/// # }
/// ```
pub fn into_inner(self) -> <D::Pool as Pool>::Connection {
self.0
}
}
#[rocket::async_trait]
impl<D: Database> Fairing for Initializer<D> {
fn info(&self) -> Info {