Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements property_many and has_many #46

Merged
merged 9 commits into from Nov 14, 2019

Conversation

jdeepee
Copy link
Contributor

@jdeepee jdeepee commented Nov 12, 2019

These two methods are helper methods intended to make graph traversal code much cleaner.

This is a simple step in making the code to insert vertices with many properties and querying these properties much cleaner.

Currently inserting vertices with many properties involves chaining a lot of .property() calls and can end up being many lines long.
The same situation arises when de-serializing a Map into a rust data structure. Lots of chaining of .get()?.get()? for each field in the struct.

My thoughts to solve these two issues are the following:

  1. To avoid the .property() chaining: we make public a ToPropertyMany Trait which a user can implement on their struct. This must return a Vec<(String, GValue)>. The user could then write code that might looks something like this:
g.add_v("label")
    .properties_from_struct(PropertyStructure)
    .next()?;
  1. To avoid the .get() chaining: we have a derivable proc-macro TryFromGremlinMap. This can be implemented on any struct containing types which can be Into<GValue>. Then when a Map is returned from a given traversal the user can do the following MyStruct::try_from_gremlin_map(map)?. I have started the implementation for the proc macro at (https://github.com/jdeepee/gremlin-rs/tree/from_map_into_insertable/gremlin-derive) but its still very basic in its function. It also doesn't support serializing a GValue into another foreign type such as a Uuid.

I am interested to know your thoughts on my proposal to solve these two issues. If you have any experience with proc macro's I could also use some help there. Still trying to understand them fully.

@jdeepee
Copy link
Contributor Author

jdeepee commented Nov 12, 2019

Sorry for the duplicate commits

@wolf4ood
Copy link
Owner

Hi @jdeepee

about those 2 methods is fine for me as long as help you writing less lines. Just they will not be "Standard" traversal steps.

For the advanced solution with traits and proc macro, yes that would be super nice to have.

I have some experience with macro but less with proc macro. But i will help you with that.

Meanwhile i will merge this, and we can track the proposal in a separated issue

@wolf4ood wolf4ood merged commit f7e9302 into wolf4ood:master Nov 14, 2019
@wolf4ood wolf4ood added this to the 0.3.0 milestone Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants