docbox_management/
database.rs

1/// docbox-database re-exports
2pub use docbox_database::*;
3
4/// Provider to get database access for the management tool
5///
6/// Expects that the access granted to the database is sufficient
7/// for creation and deletion of tables
8pub trait DatabaseProvider: Send + Sync + 'static {
9    /// Connect to the provided `database` providing back a [DbPool]
10    fn connect(&self, database: &str) -> impl Future<Output = DbResult<DbPool>> + Send;
11}
12
13pub struct CloseOnDrop(DbPool);
14
15pub fn close_pool_on_drop(pool: &DbPool) -> CloseOnDrop {
16    CloseOnDrop(pool.clone())
17}
18
19impl Drop for CloseOnDrop {
20    fn drop(&mut self) {
21        let pool = self.0.clone();
22
23        tokio::spawn(async move {
24            tracing::debug!("closing dropped pool");
25            pool.close().await;
26            tracing::debug!("closed dropped pool");
27        });
28    }
29}