hinge 0.1.0

SQL-native ELT engine — dependency graph resolved automatically from FROM/JOIN clauses, parallel execution, single binary
Documentation
use crate::domain::asset::error::AssetError;
use std::fmt;
use std::str::FromStr;

/// A `schema.name` pair that uniquely identifies an asset in the graph.
///
/// Derived automatically from the file path:
/// `models/staging/orders.sql` → `AssetReference { schema: "staging", name: "orders" }`.
///
/// Implements `FromStr` so `"staging.orders".parse::<AssetReference>()` works.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssetReference {
    schema: String,
    name: String,
}

impl AssetReference {
    pub fn new(schema: impl Into<String>, name: impl Into<String>) -> Self {
        Self {
            schema: schema.into(),
            name: name.into(),
        }
    }

    pub fn schema(&self) -> &str {
        &self.schema
    }

    pub fn name(&self) -> &str {
        &self.name
    }
}

impl fmt::Display for AssetReference {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}.{}", self.schema, self.name)
    }
}

impl FromStr for AssetReference {
    type Err = AssetError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let parts: Vec<&str> = s.split('.').collect();

        if parts.len() != 2 {
            return Err(AssetError::InvalidReference(s.to_string()));
        }

        let schema = parts[0].trim();
        let name = parts[1].trim();

        if schema.is_empty() || name.is_empty() {
            return Err(AssetError::InvalidReference(s.to_string()));
        }

        Ok(Self {
            schema: schema.to_string(),
            name: name.to_string(),
        })
    }
}