Files
osirose-new/database-service/src/db.rs
2024-11-26 02:01:27 -05:00

25 lines
605 B
Rust

use crate::redis_cache::RedisCache;
use crate::users::UsersService;
use sqlx::PgPool;
use std::sync::Arc;
pub struct Database {
pub users_service: UsersService, // User-specific functionality
}
impl Database {
pub async fn new(pool: PgPool, cache: Arc<RedisCache>) -> Self {
let users_service = UsersService { pool, cache };
Self { users_service }
}
pub async fn health_check(&self) -> bool {
// Simple query to check database health
sqlx::query("SELECT 1")
.execute(&self.users_service.pool)
.await
.is_ok()
}
}