use async_std::sync::RwLockWriteGuard;
use tide::utils::async_trait;
use tide::Request;
use sqlx::postgres::Postgres;
use crate::{ConnectionWrap, ConnectionWrapInner, SQLxMiddleware};
#[allow(dead_code)]
pub type PostgresMiddleware = SQLxMiddleware<Postgres>;
#[cfg(feature = "postgres")]
#[cfg_attr(feature = "docs", doc(cfg(feature = "postgres")))]
#[async_trait]
pub trait PostgresRequestExt {
async fn pg_conn<'req>(&'req self) -> RwLockWriteGuard<'req, ConnectionWrapInner<Postgres>>;
}
#[async_trait]
impl<T: Send + Sync + 'static> PostgresRequestExt for Request<T> {
async fn pg_conn<'req>(&'req self) -> RwLockWriteGuard<'req, ConnectionWrapInner<Postgres>> {
let pg_conn: &ConnectionWrap<Postgres> = self
.ext()
.expect("You must install SQLx middleware providing Postgres ConnectionWrap");
pg_conn.write().await
}
}