cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
/// Introspection view of the relations a [`QueryRunner`] exposes —
/// what the workspace looks like from the inside of a query. Engine
/// adapters fetch the metadata (Cozo's `::relations` / `::columns`,
/// or whatever the next backend offers) and shape it into this
/// structure.
///
/// [`QueryRunner`]: crate::domain::usecases::query::QueryRunner
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct QuerySchema {
    pub relations: Vec<QueryRelation>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryRelation {
    pub name: String,
    pub columns: Vec<QueryColumn>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryColumn {
    pub name: String,
    pub type_: String,
    pub is_key: bool,
}

impl QuerySchema {
    pub fn new(relations: Vec<QueryRelation>) -> Self {
        Self { relations }
    }

    pub fn is_empty(&self) -> bool {
        self.relations.is_empty()
    }
}

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

    #[test]
    fn empty_schema_is_empty() {
        assert!(QuerySchema::default().is_empty());
    }

    #[test]
    fn schema_carries_its_relations() {
        let s = QuerySchema::new(vec![QueryRelation {
            name: "issue".to_owned(),
            columns: vec![
                QueryColumn {
                    name: "id".to_owned(),
                    type_: "String".to_owned(),
                    is_key: true,
                },
                QueryColumn {
                    name: "title".to_owned(),
                    type_: "String".to_owned(),
                    is_key: false,
                },
            ],
        }]);
        assert_eq!(s.relations.len(), 1);
        assert_eq!(s.relations[0].columns.len(), 2);
        assert!(s.relations[0].columns[0].is_key);
    }
}