print_graph/
print_graph.rs1use std::env;
2
3use std::io;
4use tdb_succinct::TdbDataType;
5use terminus_store::*;
6use tokio;
7
8async fn print_graph(store_path: &str, graph: &str) -> io::Result<()> {
9 let store = open_directory_store(store_path);
10 let graph = store
11 .open(graph)
12 .await?
13 .expect(&format!("expected graph {} to exist", graph));
14
15 match graph.head().await? {
16 Some(layer) => {
17 for id_triple in layer.triples() {
18 let triple = layer
21 .id_triple_to_string(&id_triple)
22 .expect("expected id triple to be mapable to string");
23
24 println!(
25 "{}, {}, {} {:?}",
26 triple.subject,
27 triple.predicate,
28 match triple.object {
29 ObjectType::Node(_) => "node",
30 ObjectType::Value(_) => "value",
31 },
32 match triple.object {
33 ObjectType::Node(n) => String::make_entry(&n),
34 ObjectType::Value(v) => v,
35 }
36 );
37 }
38 }
39 None => {}
40 }
41
42 Ok(())
43}
44
45#[tokio::main]
46async fn main() {
47 let args: Vec<String> = env::args().collect();
48 if args.len() != 3 {
49 println!("usage: {} <path> <graph_name>", args[0]);
50 } else {
51 print_graph(&args[1], &args[2]).await.unwrap();
52 }
53}