use crate::{DbError, PoolStatus};
#[async_trait::async_trait]
pub trait Backend: Send + Sync {
fn backend_name(&self) -> &'static str;
fn pool_status(&self) -> PoolStatus;
async fn health_check(&self) -> Result<bool, DbError>;
async fn close(&self);
}
#[cfg(feature = "redis")]
#[async_trait::async_trait]
impl Backend for crate::RedisClient {
fn backend_name(&self) -> &'static str {
"redis"
}
fn pool_status(&self) -> PoolStatus {
crate::RedisClient::pool_status(self)
}
async fn health_check(&self) -> Result<bool, DbError> {
crate::RedisClient::health_check(self).await
}
async fn close(&self) {
crate::RedisClient::close(self).await;
}
}
#[cfg(feature = "mysql")]
#[async_trait::async_trait]
impl Backend for crate::mysql::Database {
fn backend_name(&self) -> &'static str {
"mysql"
}
fn pool_status(&self) -> PoolStatus {
crate::mysql::Database::pool_status(self)
}
async fn health_check(&self) -> Result<bool, DbError> {
crate::mysql::Database::health_check(self).await
}
async fn close(&self) {
crate::mysql::Database::close(self).await;
}
}
#[cfg(feature = "postgres")]
#[async_trait::async_trait]
impl Backend for crate::postgres::Database {
fn backend_name(&self) -> &'static str {
"postgres"
}
fn pool_status(&self) -> PoolStatus {
crate::postgres::Database::pool_status(self)
}
async fn health_check(&self) -> Result<bool, DbError> {
crate::postgres::Database::health_check(self).await
}
async fn close(&self) {
crate::postgres::Database::close(self).await;
}
}