neo4j-contrib / py2neo

EOL! Py2neo is a comprehensive Neo4j driver library and toolkit for Python.
https://py2neo.org
Apache License 2.0
20 stars 8 forks source link

API support for MERGE Cypher command #213

Closed bruth closed 10 years ago

bruth commented 10 years ago

I am working on a project that requires synchronization between two sources. This requires a lookup followed by an update on the properties to ensure the graph is synced.

The new MERGE clause provides native "get or create" support, but also enables specifying ON CREATE and ON MATCH clauses which would allow for updating the properties on match in one statement.

technige commented 10 years ago

There's nothing stopping you from executing a Cypher query containing a MERGE statement. Are you thinking of a wrapper function?

bruth commented 10 years ago

Yes, for now I created a class that constructs the MERGE statements and hit the HTTP API directly since I am only accessing a single endpoint for now: https://github.com/cbmi/origins/blob/master/origins/io/neo4j.py.

I would presume a wrapper function would remove at least one additional request and ensure the step happens in a single statement/transaction.

On Dec 5, 2013, at 5:56 AM, Nigel Small notifications@github.com wrote:

There's nothing stopping you from executing a Cypher query containing a MERGE statement. Are you thinking of a wrapper function?

— Reply to this email directly or view it on GitHub.

technige commented 10 years ago

I have generally only provided wrapper functions in py2neo where there is an explicit REST endpoint available. In this case, MERGE is a Cypher keyword and would not really benefit from a specific method, except perhaps to avoid having to know the Cypher syntax.

To my knowledge, new REST endpoints are no longer being added to the server as most (if not all) of the development effort is going into the Cypher language which is all tunnelled through a single endpoint. Also, I have no plans at this stage to construct any kind of client-side Cypher builder, partly due to the speed at which the language is evolving and partly because it would be a lot of effort on my part for no extra functionality. It would simply be another way to use Cypher, albeit indirectly.

In terms of batches (as discussed in https://github.com/nigelsmall/py2neo/issues/221 by @SunPowered) the BatchRequest object is only able to provide references to previously created objects when an explicit HTTP Location header is received. This is only the case for the main REST API and not for general Cypher queries which can of course return multiple items. Clearly, with the stagnation of the main REST API, this facility will become less and less useful over time.

My general recommendation is to invest effort in the Cypher language and the new transactional endpoint which will provide much of the same functionality as the traditional API and batches.

bruth commented 10 years ago

@nigelsmall Thanks for the response and your reasoning is understood. I have been constructing Cypher statements directly for my purposes, both to learn the language and it's more explicit.