ignis-db 0.2.0

A comprehensive PostgreSQL ORM with macro-driven schema management
Documentation
//! Composite type support utilities for Ignis
//!
//! This module provides helper types and utilities for working with PostgreSQL composite types.
//! The actual procedural macro `#[derive(PgComposite)]` is defined in the ignis-derive crate.

/// Trait for types that can generate PostgreSQL composite type DDL
pub trait CompositeTypeDdl {
    /// Generate CREATE TYPE DDL for this composite type
    fn generate_create_ddl() -> String;

    /// Generate DROP TYPE DDL for this composite type  
    fn generate_drop_ddl() -> String;

    /// Get the PostgreSQL type name
    fn pg_type_name() -> &'static str;
}

/// Utility functions for composite type handling
pub mod utils {
    use syn::Type;

    /// Convert Rust types to PostgreSQL SQL types
    pub fn rust_type_to_sql_type(ty: &Type) -> String {
        match ty {
            Type::Path(type_path) => {
                let path = &type_path.path;
                if let Some(segment) = path.segments.last() {
                    match segment.ident.to_string().as_str() {
                        "i16" => "SMALLINT".to_string(),
                        "i32" => "INTEGER".to_string(),
                        "i64" => "BIGINT".to_string(),
                        "f32" => "REAL".to_string(),
                        "f64" => "DOUBLE PRECISION".to_string(),
                        "bool" => "BOOLEAN".to_string(),
                        "String" => "TEXT".to_string(),
                        "Uuid" => "UUID".to_string(),
                        "Decimal" => "NUMERIC".to_string(),
                        "Option" => {
                            // For Option<T>, extract T and make it nullable
                            if let syn::PathArguments::AngleBracketed(args) = &segment.arguments {
                                if let Some(syn::GenericArgument::Type(inner_type)) =
                                    args.args.first()
                                {
                                    return rust_type_to_sql_type(inner_type);
                                }
                            }
                            "TEXT".to_string()
                        }
                        _ => "TEXT".to_string(), // Default fallback
                    }
                } else {
                    "TEXT".to_string()
                }
            }
            _ => "TEXT".to_string(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_composite_type_ddl_trait_exists() {
        // This test just verifies the trait compiles
        fn assert_ddl_trait<T: CompositeTypeDdl>() {}
        // Would test with actual composite types once implemented
    }
}