1use sea_orm::DatabaseConnection;
2use std::future::Future;
3use std::ops::Deref;
4use std::pin::Pin;
5
6#[derive(Debug, Clone)]
14pub struct DbPool(pub(crate) DatabaseConnection);
15
16impl DbPool {
17 pub fn connection(&self) -> &DatabaseConnection {
19 &self.0
20 }
21}
22
23impl Deref for DbPool {
24 type Target = DatabaseConnection;
25
26 fn deref(&self) -> &Self::Target {
27 &self.0
28 }
29}
30
31impl modo::GracefulShutdown for DbPool {
32 fn graceful_shutdown(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> {
33 Box::pin(async {
34 if let Err(e) = self.0.close_by_ref().await {
35 tracing::warn!("Error closing database pool: {e}");
36 }
37 })
38 }
39}