graphaware / neo4j-uuid

GraphAware Runtime Module that assigns a UUID to all nodes (and relationships) in the graph transparently
103 stars 22 forks source link

How to create a node and query the assigned UUID in a single call? #24

Closed foobargeez closed 8 years ago

foobargeez commented 8 years ago

Currently, doing something like this CREATE (n:testing {name:"haha"}) RETURN n.uuid returnsnull. Querying for the above node again immediately results a UUID. The module is probably behaving per design but I am stuck with a basic requirement -- how do I uniquely query for the newly created node as part of the second query if I don't have the UUID? I could be missing something fairly obvious and I would appreciate if someone can point me how to achieve this -- create a node and retrieve the UUID in the same call/transaction (I could be using the word transaction somewhat loosely) and additionally avoid a second query/read.

Thanks in advance!

foobargeez commented 8 years ago

Is #3 still applicable? If so, this can be closed.

ikwattro commented 8 years ago

Hi @foobargeez

Yes #3 is still of application, unfortunately :(

if the second cypher query is internal to your application, you can just return the internal id of the node :

CREATE (n:Testing {name:"haha"}) RETURN id(n)
---
// Later
MATCH (n) WHERE id(n) = 123 RETURN n.uuid

There is no current workaround to it apart from using your own uuid generation library, this is also a known limitation for current object graph mappers like the java-ogm or php-ogm in order to use this plugin as Id Strategy. While using a uuid generator yourself is not so much of a hassle generally.

Joshfindit commented 8 years ago

Just thinking out loud; since we're talking about create, can you create while specifying a uuid that you generated?

On Aug 2, 2016, at 11:58 AM, foobargeez notifications@github.com wrote:

Currently, doing something like this CREATE (n:testing {name:"haha"}) RETURN n.uuid return null. Querying for the above node again immediately results a UUID. The module is probably behaving per design but I am stuck with a basic requirement -- how do I uniquely query for the newly created node as part of the second query if I don't have the UUID? I could be missing something fairly obvious and I would appreciate if someone can point me how to achieve this -- create a node and retrieve the UUID in the same call/transaction (I could be using the word transaction somewhat loosely).

Thanks in advance!

― You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

foobargeez commented 8 years ago

Thanks. I almost forgot neo4j's native id -- thanks for the tip.

I currently create a UUID (v3) and assign to the node property while creating a node. I was asking as it's just redundant (from both efficiency and storage perspective) when I already have your UUID module and is working well (except this one glitch), so wanted to check.

ikwattro commented 8 years ago

@Joshfindit what do you mean exactly ?

@foobargeez yeah it doesn't make sense to have both an application side uuid generation together with this uuid module.

chrisregnier commented 7 years ago

Is there anyway to call the uuid generator directly from the CREATE query? Something like CREATE (n:Testing {name: 'Testing', uuid: ga.uuid.uuidGenerator()}) RETURN n

Also, should there be some docs about this in the README cause it took me a bit to figure out why this wasn't working or what to even search for?