Ensure unique nodes with neo4jclient -
is there way ensure uniqueness when creating node neo4jclient?
this link transactions shows how using java , transactions, don't see transaction support in neo4jclient. able using explicit cypher string query this:
"start n=node:node_auto_index(name={id}) count(*) c c=0 create x={name:{id}} return c"
but hack. there better way?
transaction support come neo4j 2.0 , later version of neo4jclient. issue tracking work: https://bitbucket.org/readify/neo4jclient/issue/91/support-cypher-transactions-integrated
that doesn't give uniqueness though...
neo4j doesn't have unique indexes auto-enforce idea. (i expect we'll see neo4j 2.0 labels in future, not yet.)
you need either a) know you're creating unique, or b) check first.
you seem taking b route.
transactions allow check create within single transactional action, still multiple calls on wire.
the cypher text you've written out preferred: check , create in single statement. i'm intrigued know why think hack.
you can execute statement via neo4jclient like:
var id = 123; graphclient.cypher .start(new { n = node.byindexlookup("node_auto_index", "name", id)}) .with("count(*) c") .where("c=0") .create("x={0}", new mytype { name = id }) .return<node<mytype>>("c")
some of with
, where
statements nice if cleaner, it's functional now.
there's cypher's create unique
clause might cover scenario too.
Comments
Post a Comment