use ignis_db::{Database, DatabaseConfig, DatabaseType, MySQL, PostgreSQL};
fn main() -> anyhow::Result<()> {
println!("🚀 Ignis-DB Multi-Platform Demo");
println!("================================");
let postgres_config =
DatabaseConfig::postgres("localhost", 5433, "postgres", "postgres", "postgres");
let mysql_config = DatabaseConfig::mysql("localhost", 3307, "mysql", "mysql", "mysql");
let postgres_db = PostgreSQL::new("postgres");
let mysql_db = MySQL::new("mysql");
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()
);
println!("\n🔧 Type Mapping Examples:");
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>")
);
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>")
);
println!("\n📝 SQL Generation Examples:");
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()
);
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()
);
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));
println!("\n⭐ Database-Specific Features:");
println!(
"PostgreSQL supports materialized views: {}",
postgres_db.database_type() == DatabaseType::PostgreSQL
);
println!(
"PostgreSQL auto-increment: {}",
postgres_sql_gen.auto_increment_keyword()
);
println!(
"MySQL auto-increment: {}",
mysql_sql_gen.auto_increment_keyword()
);
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(())
}