pub use docbox_database::*;
pub trait DatabaseProvider: Send + Sync + 'static {
fn connect(&self, database: &str) -> impl Future<Output = DbResult<DbPool>> + Send;
}
pub struct CloseOnDrop(DbPool);
pub fn close_pool_on_drop(pool: &DbPool) -> CloseOnDrop {
CloseOnDrop(pool.clone())
}
impl Drop for CloseOnDrop {
fn drop(&mut self) {
let pool = self.0.clone();
tokio::spawn(async move {
tracing::debug!("closing dropped pool");
pool.close().await;
tracing::debug!("closed dropped pool");
});
}
}