ignis-db 0.2.0

A comprehensive PostgreSQL ORM with macro-driven schema management
Documentation
//! Multi-platform database demonstration
//!
//! This example shows how to use the new multi-platform database abstraction
//! to work with both PostgreSQL and MySQL databases.

use ignis_db::{Database, DatabaseConfig, DatabaseType, MySQL, PostgreSQL};

fn main() -> anyhow::Result<()> {
    println!("🚀 Ignis-DB Multi-Platform Demo");
    println!("================================");

    // Create database configurations
    let postgres_config =
        DatabaseConfig::postgres("localhost", 5433, "postgres", "postgres", "postgres");

    let mysql_config = DatabaseConfig::mysql("localhost", 3307, "mysql", "mysql", "mysql");

    // Create database instances
    let postgres_db = PostgreSQL::new("postgres");
    let mysql_db = MySQL::new("mysql");

    // Demonstrate database type information
    println!("\n📊 Database Information:");
    println!(
        "PostgreSQL: {} ({})",
        postgres_db.name(),
        postgres_db.database_type().display_name()
    );
    println!(
        "MySQL: {} ({})",
        mysql_db.name(),
        mysql_db.database_type().display_name()
    );

    // Demonstrate type mapping
    println!("\n🔧 Type Mapping Examples:");

    // PostgreSQL type mapping
    let postgres_type_mapping = postgres_db.type_mapping();
    println!(
        "PostgreSQL String -> {}",
        postgres_type_mapping.rust_to_sql_type("String")
    );
    println!(
        "PostgreSQL i32 -> {}",
        postgres_type_mapping.rust_to_sql_type("i32")
    );
    println!(
        "PostgreSQL DateTime<Utc> -> {}",
        postgres_type_mapping.rust_to_sql_type("chrono::DateTime<chrono::Utc>")
    );

    // MySQL type mapping
    let mysql_type_mapping = mysql_db.type_mapping();
    println!(
        "MySQL String -> {}",
        mysql_type_mapping.rust_to_sql_type("String")
    );
    println!(
        "MySQL i32 -> {}",
        mysql_type_mapping.rust_to_sql_type("i32")
    );
    println!(
        "MySQL DateTime<Utc> -> {}",
        mysql_type_mapping.rust_to_sql_type("chrono::DateTime<chrono::Utc>")
    );

    // Demonstrate SQL generation
    println!("\n📝 SQL Generation Examples:");

    // PostgreSQL SQL generation
    let postgres_sql_gen = postgres_db.sql_generator();
    println!(
        "PostgreSQL identifier: {}",
        postgres_sql_gen.quote_identifier("user_name")
    );
    println!(
        "PostgreSQL string: {}",
        postgres_sql_gen.quote_string("Hello, World!")
    );
    println!(
        "PostgreSQL timestamp: {}",
        postgres_sql_gen.current_timestamp_function()
    );

    // MySQL SQL generation
    let mysql_sql_gen = mysql_db.sql_generator();
    println!(
        "MySQL identifier: {}",
        mysql_sql_gen.quote_identifier("user_name")
    );
    println!(
        "MySQL string: {}",
        mysql_sql_gen.quote_string("Hello, World!")
    );
    println!(
        "MySQL timestamp: {}",
        mysql_sql_gen.current_timestamp_function()
    );

    // Demonstrate connection strings
    println!("\n🔗 Connection Strings:");
    let postgres_conn_mgr = postgres_db.connection_manager();
    let mysql_conn_mgr = mysql_db.connection_manager();

    println!(
        "PostgreSQL: {}",
        postgres_conn_mgr.connection_string(&postgres_config)
    );
    println!("MySQL: {}", mysql_conn_mgr.connection_string(&mysql_config));

    // Demonstrate database-specific features
    println!("\n⭐ Database-Specific Features:");

    // PostgreSQL supports materialized views
    println!(
        "PostgreSQL supports materialized views: {}",
        postgres_db.database_type() == DatabaseType::PostgreSQL
    );

    // MySQL uses different auto-increment syntax
    println!(
        "PostgreSQL auto-increment: {}",
        postgres_sql_gen.auto_increment_keyword()
    );
    println!(
        "MySQL auto-increment: {}",
        mysql_sql_gen.auto_increment_keyword()
    );

    // Demonstrate type mapping differences
    println!("\n🔄 Type Mapping Differences:");

    let test_types = vec![
        "String",
        "i32",
        "bool",
        "chrono::DateTime<chrono::Utc>",
        "uuid::Uuid",
    ];

    for rust_type in test_types {
        let postgres_type = postgres_type_mapping.rust_to_sql_type(rust_type);
        let mysql_type = mysql_type_mapping.rust_to_sql_type(rust_type);

        if postgres_type != mysql_type {
            println!(
                "{} -> PostgreSQL: {}, MySQL: {}",
                rust_type, postgres_type, mysql_type
            );
        }
    }

    println!("\n✅ Multi-platform demo completed successfully!");
    println!("\n🎯 Next Steps:");
    println!("1. Implement actual database connections using sqlx");
    println!("2. Add schema introspection for both databases");
    println!("3. Implement migration management");
    println!("4. Add comprehensive testing");

    Ok(())
}