use super::DirGraph;
use crate::graph::schema::SchemaDefinition;
impl DirGraph {
pub fn set_schema(&mut self, schema: SchemaDefinition) {
self.schema_definition = Some(schema);
}
pub fn get_schema(&self) -> Option<&SchemaDefinition> {
self.schema_definition.as_ref()
}
pub fn clear_schema(&mut self) {
self.schema_definition = None;
}
pub fn primary_key_for(&self, node_type: &str) -> Option<&str> {
self.schema_definition
.as_ref()?
.node_schemas
.get(node_type)?
.primary_key
.as_deref()
}
pub fn set_instructions(&mut self, text: &str, channel: Option<&str>) {
let key = channel.unwrap_or("").to_string();
if text.is_empty() {
self.graph_instructions.remove(&key);
} else {
self.graph_instructions.insert(key, text.to_string());
}
}
pub fn layer_for(&self, node_type: &str) -> Option<&str> {
self.schema_definition
.as_ref()?
.node_schemas
.get(node_type)?
.layer
.as_deref()
}
pub fn get_instructions(&self, channel: Option<&str>) -> Option<&str> {
self.graph_instructions
.get(channel.unwrap_or(""))
.or_else(|| self.graph_instructions.get(""))
.map(String::as_str)
}
}