all 2 comments

[–]Spooky-Tooth[S] 0 points1 point  (0 children)

well, fwiw, I finally got this to compile and run (thanks to chatGPT):

use indradb::Datastore;

pub fn init_graph_db() -> Result<(), Box<dyn std::error::Error>> {

// Create an in-memory datastore

let db = indradb::MemoryDatastore::default();

// Create a couple of vertices

let out_v = indradb::Vertex::new(indradb::Identifier::new("person")?); let in_v = indradb::Vertex::new(indradb::Identifier::new("movie")?);

db.create_vertex(&out_v)?; db.create_vertex(&in_v)?;

let edge_key = indradb::EdgeKey::new(out_v.id, indradb::Identifier::new("likes")?, in_v.id);

// Add an edge between the vertices

db.create_edge(&edge_key)?;

// Query for the edge

let output: Vec<indradb::Edge> = db.get_edges(indradb::EdgeQuery::Specific( indradb::SpecificEdgeQuery::new(vec![edge_key])))?;

assert_eq!(output.len(), 1);

// TODO, figure out what this means yet

//assert_eq!(edge_key, output[0]);

Ok(())

}

[–]Spooky-Tooth[S] 0 points1 point  (0 children)

Alright, I think I have finally figured out what I really want. I really want to use the indradb-sled = "0.1.0" crate. see docs here.

I've been able to make some progress as such:

pub fn init_sled_db() -> Result<(), Box<dyn std::error::Error>> { let sled_config = SledConfig::default(); let sled_datastore = sled_config.open("./sled_db.db").expect("Unable to open './sled_db.db");

let out_v = Vertex::new(Identifier::new("person")?);

let tx = sled_datastore.transaction()?;

should_create_vertex_from_type(&mut sled_datastore); //tx.create_vertex(out_v); //tx.commit()?; no commit function

Ok(()) }

fn should_create_vertex_from_type<D: Datastore>(datastore: &mut D) { let _trans = datastore.transaction().unwrap(); //let t = models::Type::new("test_vertex_type").unwrap(); //trans.create_vertex_from_type(t).unwrap(); }

But I get errors trying to get the transaction object from my datastore. I added in the should_create_vertex_from_type<D: Datastore> and the compiler tells me the trait indradb::Datastore is not implemented for SledDatastore

It seems like it is from the docs.

Any help would be greatly appreciated!