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

How to use result #18

Open
martin-flower opened this issue Jul 27, 2017 · 4 comments
Open

How to use result #18

martin-flower opened this issue Jul 27, 2017 · 4 comments

Comments

@martin-flower
Copy link
Contributor

martin-flower commented Jul 27, 2017

Hi - I am new to both Gremlin and to Go. Having spent the afternoon with the debugger, I now have the following code (after g.addV()). If this is wrong, maybe you could show the correct usage in the README file. Thanks.

idFromGremlin := int64(res.([]interface{})[0].([]interface{})[0].(map[string]interface{})["id"].(float64))
labelFromGremlin := res.([]interface{})[0].([]interface{})[0].(map[string]interface{})["label"].(string)
typeFromGremlin := res.([]interface{})[0].([]interface{})[0].(map[string]interface{})["type"].(string)
properties := res.([]interface{})[0].([]interface{})[0].(map[string]interface{})["properties"].(map[string]interface{})
nameFromGremlin := properties["name"].([]interface{})[0].(map[string]interface{})["value"]

@qasaur
Copy link
Owner

qasaur commented Aug 2, 2017

Hi Martin,

There really isn't any prescribed best practices for using gremgo, so you should use what works best for you. With that being said there are plans on making manipulation of results a little more intuitive instead of having chains of interfaces like in your example, because I find that a little too tedious.

@rayascott-zz
Copy link

rayascott-zz commented Aug 4, 2017

Perhaps one of you can help me, as I'm new to gremlin, Go and although I know Java, I've never used Groovy. I've also never used web sockets. I seem to be able to send a very basic parameterised script to the Groovy script engine, and I get back the resulting text.

Right now I send this script to the engine:

graph = JanusGraphFactory.open(cassandra)
features = graph.features()

And I'm receiving this...

[[FEATURES

GraphFeatures
-- Persistence: true
-- Transactions: true
...

My first question is, how do you tell the groovy script what to return? Does it just return the last evaluated expression? And how do you get it to return data in a format that's useful? Perhaps just a return statement that is returning a string variable?

Do I need to build up a JSON document in my script that is returned, from iterating over the results?

If your example code showed how to manipulate the data that is returned, say, something that has an array and a map, or collection of some sort, that would be super useful to us, as that's ultimately what we'll be working with most of the time.

@eonpatapon
Copy link

go-gremlin/gremlin is just returning the json (as []bytes), it doesn't do any json unmarshal.

I find it more practical because depending on the query results I can unmarshal them to custom structs I defined myself.

@tejasmanohar
Copy link

tejasmanohar commented Apr 6, 2018

@eonpatapon I'd agree with eonpatapon. Maybe there should be an ExecBytes(), but I think an even better solution would be being able to pass in your own response interface{} that's forwarded to Unmarshal().

Repository owner deleted a comment from jalamari2018 Mar 19, 2024
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

No branches or pull requests

5 participants