use crate::GraphEntityKind;
pub const METADATA_PREFIX: &str = "uqa.graph.guard.v1:";
pub struct GraphRecordGuard {
kind: GraphEntityKind,
id: u64,
}
impl GraphRecordGuard {
pub fn new(kind: GraphEntityKind, id: u64) -> Self {
Self { kind, id }
}
pub fn from_kind_name(kind: &str, id: u64) -> Option<Self> {
let kind = match kind {
"vertex" => GraphEntityKind::Vertex,
"edge" => GraphEntityKind::Edge,
_ => return None,
};
Some(Self::new(kind, id))
}
pub fn lifetime(&self) -> String {
format!("{METADATA_PREFIX}entity:{}:{}", self.kind.as_str(), self.id)
}
pub fn references(&self) -> String {
format!(
"{METADATA_PREFIX}references:{}:{}",
self.kind.as_str(),
self.id
)
}
pub fn membership_references(&self, graph: &str) -> String {
format!(
"{METADATA_PREFIX}membership:{}:{}:{graph}",
self.kind.as_str(),
self.id
)
}
}