Skip to content
Andreas Ronge edited this page Sep 28, 2012 · 3 revisions

With

The ability to chain queries together allows for powerful constructs. In Cypher, the WITH clause is used to pipe the result from one query to the next.

WITH is also used to separate reading from updating of the graph. Every sub-query of a query must be either read-only or write-only.

Example:

node(1) <=> node(:other_person).ret.with(count) { |_, foaf| foaf > 1 }) >> node

Notice that the first argument for the with is the node(:other_person) which is not used (the _ parameter). The foaf parmeter in the ruby block foaf > 1 is the count value.

Same as

START v2=node(1) MATCH (v2)--(other_person)-->(v3) WITH other_person,count(*) as v1 WHERE v1 > 1 RETURN other_person

Create Nodes

Example:

node.new(:name => 'Andreas', :age => 42)

Same as CREATE (v1 {name : 'Andreas', age : 42}) RETURN v1

Delete

Delete a node:

node(4).del

START v1=node(4) DELETE v1

Delete a relationship

node(3) > rel('r').del > node.del

Same as START v1=node(3) MATCH (v1)-[r]->(v2) DELETE r,v2

Create Paths

Example:

node(1).create_path { |n| n > rel(:friends) > node(2) }

Same as START v1=node(1),v2=node(2) WITH v1 CREATE (v1)-[:friends]->(v2)

More ?

See the RSpecs for more examples see here

Clone this wiki locally