ignis-db 0.2.0

A comprehensive PostgreSQL ORM with macro-driven schema management
Documentation
//! Multi-platform database abstraction layer
//!
//! This module provides the core abstraction traits and implementations
//! for supporting multiple databases in Ignis-DB.

pub mod mysql;
pub mod postgres;
pub mod schema_utils;
pub mod traits;

pub use mysql::MySQL;
pub use postgres::PostgreSQL;
pub use traits::*;

/// Database connection configuration
#[derive(Debug, Clone)]
pub struct DatabaseConfig {
    pub host: String,
    pub port: u16,
    pub database: String,
    pub username: String,
    pub password: String,
    pub ssl_mode: Option<String>,
}

impl DatabaseConfig {
    /// Create a new database configuration
    pub fn new(
        host: impl Into<String>,
        port: u16,
        database: impl Into<String>,
        username: impl Into<String>,
        password: impl Into<String>,
    ) -> Self {
        Self {
            host: host.into(),
            port,
            database: database.into(),
            username: username.into(),
            password: password.into(),
            ssl_mode: None,
        }
    }

    /// Create a PostgreSQL configuration
    pub fn postgres(
        host: impl Into<String>,
        port: u16,
        database: impl Into<String>,
        username: impl Into<String>,
        password: impl Into<String>,
    ) -> Self {
        Self::new(host, port, database, username, password)
    }

    /// Create a MySQL configuration
    pub fn mysql(
        host: impl Into<String>,
        port: u16,
        database: impl Into<String>,
        username: impl Into<String>,
        password: impl Into<String>,
    ) -> Self {
        Self::new(host, port, database, username, password)
    }
}

/// Database type enumeration for runtime database selection
#[derive(Debug, Clone, PartialEq)]
pub enum DatabaseType {
    PostgreSQL,
    MySQL,
    SQLite,
    MSSQL,
}

impl DatabaseType {
    /// Get the default port for the database type
    pub fn default_port(&self) -> u16 {
        match self {
            DatabaseType::PostgreSQL => 5432,
            DatabaseType::MySQL => 3306,
            DatabaseType::SQLite => 0, // SQLite doesn't use ports
            DatabaseType::MSSQL => 1433,
        }
    }

    /// Get the database name for display purposes
    pub fn display_name(&self) -> &'static str {
        match self {
            DatabaseType::PostgreSQL => "PostgreSQL",
            DatabaseType::MySQL => "MySQL",
            DatabaseType::SQLite => "SQLite",
            DatabaseType::MSSQL => "Microsoft SQL Server",
        }
    }
}