ignis-db 0.2.0

A comprehensive PostgreSQL ORM with macro-driven schema management
Documentation
//! Alias system for building type-safe database queries

use crate::schema::Table;

/// Table alias for use in queries
#[derive(Debug, Clone)]
pub struct TableAlias {
    pub table: Table,
    pub alias: String,
}

impl TableAlias {
    /// Create a new table alias
    pub fn new(table: Table, alias: impl Into<String>) -> Self {
        Self {
            table,
            alias: alias.into(),
        }
    }

    /// Get the alias name
    pub fn alias(&self) -> &str {
        &self.alias
    }

    /// Get the underlying table
    pub fn table(&self) -> &Table {
        &self.table
    }
}

/// Extension trait for tables to create aliases
pub trait TableExt {
    fn alias(self, alias: impl Into<String>) -> TableAlias;
}

impl TableExt for Table {
    fn alias(self, alias: impl Into<String>) -> TableAlias {
        TableAlias::new(self, alias)
    }
}