MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / load_graph_by_path

Method load_graph_by_path

graphlite/src/storage/data_adapter.rs:85–148  ·  view source on GitHub ↗

Load a GraphCache for a specific graph path using provided driver connection

(
        &self,
        driver: &dyn StorageDriver<Tree = Box<dyn StorageTree>>,
        graph_path: &str,
    )

Source from the content-addressed store, hash-verified

83
84 /// Load a GraphCache for a specific graph path using provided driver connection
85 pub fn load_graph_by_path(
86 &self,
87 driver: &dyn StorageDriver<Tree = Box<dyn StorageTree>>,
88 graph_path: &str,
89 ) -> Result<GraphCache, Box<dyn std::error::Error>> {
90 let graph_prefix = Self::normalize_graph_path(graph_path);
91
92 // Open graph-specific trees using provided driver
93 let nodes_tree = match driver.open_tree(&format!("nodes_{}", graph_prefix)) {
94 Ok(tree) => tree,
95 Err(e) => {
96 // If tree doesn't exist, return empty graph
97 if e.to_string().contains("does not exist")
98 || e.to_string().contains("Column family")
99 {
100 return Ok(GraphCache::new());
101 }
102 return Err(e.into());
103 }
104 };
105
106 let edges_tree = match driver.open_tree(&format!("edges_{}", graph_prefix)) {
107 Ok(tree) => tree,
108 Err(e) => {
109 // If tree doesn't exist, return empty graph
110 if e.to_string().contains("does not exist")
111 || e.to_string().contains("Column family")
112 {
113 return Ok(GraphCache::new());
114 }
115 return Err(e.into());
116 }
117 };
118
119 let mut graph = GraphCache::new();
120
121 // Load all nodes from graph-specific tree
122 for result in nodes_tree.iter()? {
123 let (_, data) = result?;
124 let serializable_node: SerializableNode = bincode::deserialize(&data)?;
125 let node = Node {
126 id: serializable_node.id,
127 labels: serializable_node.labels,
128 properties: serializable_node.properties,
129 };
130 graph.add_node(node)?;
131 }
132
133 // Load all edges from graph-specific tree
134 for result in edges_tree.iter()? {
135 let (_, data) = result?;
136 let serializable_edge: SerializableEdge = bincode::deserialize(&data)?;
137 let edge = Edge {
138 id: serializable_edge.id,
139 label: serializable_edge.label,
140 from_node: serializable_edge.from_node,
141 to_node: serializable_edge.to_node,
142 properties: serializable_edge.properties,

Callers 1

get_graphMethod · 0.80

Calls 5

containsMethod · 0.80
add_nodeMethod · 0.80
add_edgeMethod · 0.80
open_treeMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected