burncloud-database-client 0.1.1

High-level database client with migrations, pooling, and AI model management for BurnCloud
Documentation
# burncloud-database-client


High-level database client with migrations, connection pooling, and specialized AI model management repositories for BurnCloud.

## Overview


`burncloud-database-client` is the complete database solution for BurnCloud AI management systems. It provides a high-level, batteries-included approach to database operations with specialized repositories for AI model management, monitoring, and system administration.

## Features


- **🤖 AI Model Management**: Specialized repositories for managing AI models, deployments, and configurations
- **📊 Monitoring & Metrics**: Built-in support for system and model performance tracking
- **🔒 Security & Access Control**: User management, API keys, and firewall rule management
- **🔄 Database Migrations**: Automatic schema management and versioning
- **🏊 Connection Pooling**: Efficient connection management for high-performance applications
- **🎯 Repository Pattern**: Type-safe, high-level data access layer
- **📈 Metrics Collection**: Comprehensive monitoring and logging capabilities
- **⚙️ Configuration Management**: Backup, restore, and configuration management tools

## Quick Start


### Installation


```toml
[dependencies]
burncloud-database-client = "0.1"
```

### Basic Usage


```rust
use burncloud_database_client::*;

#[tokio::main]

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create and initialize the database
    let db = BurnCloudDatabaseBuilder::new()
        .with_postgres("localhost", 5432, "burncloud", "user", "password")
        .with_pool_size(10)
        .build_and_initialize()
        .await?;

    // Add an AI model
    let model = AiModel {
        id: uuid::Uuid::new_v4(),
        name: "GPT-4".to_string(),
        version: "turbo".to_string(),
        size_gb: 45.0,
        model_type: ModelType::ChatCompletion,
        provider: "OpenAI".to_string(),
        // ... other fields
    };

    let context = QueryContext::default();
    db.ai_models.base.create(&model, &context).await?;

    // Query running deployments
    let running = db.deployments.get_running_deployments(&context).await?;
    println!("Running deployments: {}", running.len());

    // Get system statistics
    let stats = db.get_database_stats().await?;
    println!("Total models: {}", stats.models_count);

    Ok(())
}
```

## Core Components


### BurnCloudDatabase Manager


The central hub that provides access to all repositories and management functions:

```rust
let db = BurnCloudDatabaseBuilder::new()
    .with_postgres("localhost", 5432, "burncloud", "user", "pass")
    .build_and_initialize()
    .await?;

// Access specialized repositories
db.ai_models       // AI model management
db.deployments     // Model deployments
db.system_metrics  // System monitoring
db.model_metrics   // Model performance
db.request_logs    // API request logging
db.user_settings   // User preferences
db.security_config // Security management
```

### AI Model Management


```rust
// Search for models
let chat_models = db.ai_models.find_by_type(ModelType::ChatCompletion, &context).await?;

// Find by status
let available = db.ai_models.find_by_status(ModelStatus::Available, &context).await?;

// Text search
let search_results = db.ai_models.search("GPT", &context).await?;
```

### Deployment Management


```rust
// Get running deployments
let running = db.deployments.get_running_deployments(&context).await?;

// Find deployments by model
let model_deployments = db.deployments.find_by_model_id(model_id, &context).await?;

// Check port availability
let port_in_use = db.deployments.find_by_port(8080, &context).await?;
```

### Monitoring & Metrics


```rust
// Record system metrics
let metrics = SystemMetrics {
    cpu_usage: 45.2,
    memory_usage: 78.5,
    // ... other metrics
};
db.system_metrics.base.create(&metrics, &context).await?;

// Get latest metrics
let latest = db.system_metrics.get_latest(&context).await?;

// Query time range
let start = chrono::Utc::now() - chrono::Duration::hours(24);
let end = chrono::Utc::now();
let recent = db.system_metrics.find_by_time_range(start, end, &context).await?;
```

### Database Migrations


Automatic schema management with versioned migrations:

```rust
// Migrations run automatically on initialization
db.initialize().await?;

// Manual migration management
let status = db.migration_manager.get_migration_status().await?;
db.migration_manager.rollback_migration("003").await?;
```

### Configuration Management


```rust
// Backup configuration
let backup = db.backup_config().await?;

// Restore from backup
db.restore_config(&backup).await?;

// Cleanup old data
let stats = db.cleanup_old_data(30).await?; // Keep 30 days
println!("Cleaned {} old records", stats.metrics_deleted);
```

## Database Support


All major databases are supported through feature flags:

```toml
[dependencies]
burncloud-database-client = { version = "0.1", features = ["postgres"] }  # Default
burncloud-database-client = { version = "0.1", features = ["mysql"] }
burncloud-database-client = { version = "0.1", features = ["sqlite"] }
burncloud-database-client = { version = "0.1", features = ["mongodb"] }
burncloud-database-client = { version = "0.1", features = ["all"] }       # All databases
```

## Examples


See the [examples](examples/) directory for complete usage examples:

- [Basic Usage]examples/burncloud_usage.rs - Complete example with all features
- [Model Management]examples/model_management.rs - AI model operations
- [Monitoring]examples/monitoring.rs - Metrics and logging
- [Migrations]examples/migrations.rs - Database schema management

## Performance


- **Connection Pooling**: Efficient resource management with configurable pool sizes
- **Prepared Statements**: All queries use prepared statements for security and performance
- **Batch Operations**: Support for bulk inserts and updates
- **Indexing**: Optimized database schemas with comprehensive indexing strategies
- **Cleanup**: Automatic cleanup of old data to maintain performance

## Security


- **SQL Injection Protection**: All queries use parameterized statements
- **Access Control**: Role-based permissions and API key management
- **Audit Logging**: Comprehensive logging of all database operations
- **Encryption**: Support for encrypted connections to all database backends

## Contributing


We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

## License


Licensed under either of

 * Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license ([LICENSE-MIT]LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.