db_manager_connection - OmniCloudOrg/OmniOrchestrator GitHub Wiki
Path: src/db_manager/connection.rs
- struct ConnectionManager
- async fn new
- async fn ensure_database_exists
- fn main_pool
- async fn platform_pool
pub struct ConnectionManager {
/// Base URL for database connections
base_url: String,
/// Main application database pool
main_pool: Pool<MySql>,
/// Platform-specific database pools
platform_pools: Arc<RwLock<HashMap<i64, Pool<MySql>>>>,
}
Manages database connections across the application
pub async fn new(base_url: &str) -> Result<Self, DatabaseError> {
// Connect to the MySQL server without specifying a database
info!("Connecting to MySQL server at {}", base_url);
Creates a new connection manager
pub async fn ensure_database_exists(pool: &Pool<MySql>, db_name: &str) -> Result<(), DatabaseError> {
info!("Ensuring database exists: {}", db_name);
Ensures a database exists, creating it if necessary
pub fn main_pool(&self) -> &Pool<MySql> {
&self.main_pool
}
/// Gets or creates a platform-specific database pool
pub async fn platform_pool(&self, platform_id: i64, platform_name: &str) -> Result<Pool<MySql>, DatabaseError> {
// ... function body
}
Gets the main database pool
pub async fn platform_pool(&self, platform_id: i64, platform_name: &str) -> Result<Pool<MySql>, DatabaseError> {
// Check if we already have this pool
{
// ... function body
}
Gets or creates a platform-specific database pool