wolf4ood / gremlin-rs

Gremlin Rust
Apache License 2.0
108 stars 30 forks source link

Question: using custom ids #202

Open skc11 opened 7 months ago

skc11 commented 7 months ago

Hi, is there a way to set our own Id property for vertices and edges when creating them ?

andreclaudino commented 5 months ago

I need the same feature. Tryied passing ~id property and upsert with coalesce (could not implement because I can't underst how to use coalesce), but look like it is not possible to use a custom id.

Ech0riginal commented 5 months ago

I do not believe TinkerPop3 has this ability out of the box. You can reference each Step here.

I did find that JanusGraph has the ability to store custom vertex IDs, here's the relevant documentation.

criminosis commented 4 months ago

I've had success doing it to JanusGraph via an anonymous traversal like inside a coalesce

g.V("custom_vertexid").fold().coalesce::<Vertex, >([.unfold(), .add_v("some_label_here") .property(gremlin_client::structure::T::Id, custom_vertex_id)])

But it doesn't seem like you can do on a traversal directly. If you try to do something like: graph.get_traversal().add_v("some_label_here").property(gremlin_client::structure::T::Id, custom_vertex_id) you fight the type system.

@wolf4ood The property() method there has a hard type requirement that key be &str, whereas the property() for an anonymous traversal (__ returns a TraversalBuilder) takes a key of type Into<GValue>. Not sure if that's intentional?

criminosis commented 4 months ago

I took a stab at adding custom id support in my fork's branch. They're featured in this PR if anyone wants to try the branch until it gets merged & release.