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;

/// The SQL body of an asset — the `SELECT` statement that defines it.
///
/// Header comment lines (`-- @key: value`) are stripped by [`BuildGraph`] before
/// the source is stored, so what remains is valid SQL ready to send to the database.
/// Construction fails with [`AssetError::EmptySource`] if the stripped body is blank.
///
/// [`BuildGraph`]: crate::BuildGraph
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssetSource(String);

impl AssetSource {
    pub fn new(sql: impl Into<String>) -> Result<Self, AssetError> {
        let sql = sql.into();
        if sql.trim().is_empty() {
            return Err(AssetError::EmptySource);
        }
        Ok(Self(sql))
    }

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

impl fmt::Display for AssetSource {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(&self.0)
    }
}

impl FromStr for AssetSource {
    type Err = AssetError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::new(s)
    }
}

impl AsRef<str> for AssetSource {
    fn as_ref(&self) -> &str {
        &self.0
    }
}