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

Calling methods on nodes returned by CypherQuery is awkward #60

Open
nieware opened this issue Dec 10, 2014 · 6 comments
Open

Calling methods on nodes returned by CypherQuery is awkward #60

nieware opened this issue Dec 10, 2014 · 6 comments

Comments

@nieware
Copy link

nieware commented Dec 10, 2014

I was stuck for a few hours today trying to figure out what I was doing wrong until the helpful guys at StackOverflow pointed me in the right direction. See here for details and example code:

http://stackoverflow.com/questions/27405705/golang-neoism-calling-methods-of-objects-returned-by-query-leads-to-panic

It turns out that you have to initialize the Db property of nodes returned by CypherQuery manually before you can call methods like SetProperty. Of course, you can do that once you are aware it has to be done, but it feels very awkward. Is there a more intuitive way of handling this?

@jmcvetta
Copy link
Owner

Right now Neoism doesn't distinguish between a Node and any other type of result struct. This is due in large part to how the data - returned in JSON as an array of arrays - is automagically unmarshalled into a slice of structs.

Check out CypherQuery.Unmarshal() to see the code. I've never really liked this implementation, and have been thinking about a better way to do it. So I'd be happy to have input on how to achieve the same goal, seamlessly unmarshaling query results into structs, in a less hackish way.

@jmcvetta
Copy link
Owner

See also #42 and #15

@wwwdata
Copy link
Contributor

wwwdata commented Mar 23, 2015

hm, got this problem today too. I was querying for a result struct with a node in it, see:

res := []struct {
        Node *neoism.Node
    }{}

so far so good, got the node with all the data, but calling SetProperties returned a

runtime error: invalid memory address or nil pointer dereference

after setting res[0].Node.Db = myDbObject it worked ... This should be filled automatically by neoism

@jmcvetta
Copy link
Owner

I agree, it would be better if Neoism could set this variable automagically. However please see my comment above as to why doing this is decidedly non-trivial.

If you would like to take a shot implementing this behavior, I will be very happy to accept the Pull Request.

@dowlingw
Copy link

+1 also hit this today, the documentation example returning a Node object is misleading.
At the very least clarifying this in the docs would be great.

Otherwise thanks for a really useful lib! :)

@jmcvetta
Copy link
Owner

Glad you enjoy Neoism!

Please feel free to update the docs in a way you think would clarify the current behavior and make things easier for other users. I will be happy to accept the PR. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants