docbox_management/
database.rs1use docbox_database::{DbPool, DbResult};
2
3pub trait DatabaseProvider: Send + Sync + 'static {
8 fn connect(&self, database: &str) -> impl Future<Output = DbResult<DbPool>> + Send;
10}
11
12pub struct CloseOnDrop(DbPool);
13
14pub fn close_pool_on_drop(pool: &DbPool) -> CloseOnDrop {
15 CloseOnDrop(pool.clone())
16}
17
18impl Drop for CloseOnDrop {
19 fn drop(&mut self) {
20 let pool = self.0.clone();
21
22 tokio::spawn(async move {
23 tracing::debug!("closing dropped pool");
24 pool.close().await;
25 tracing::debug!("closed dropped pool");
26 });
27 }
28}