0.02
No commit activity in last 3 years
No release in over 3 years
This gem is used in the JRuby neo4j gem but should work on any Ruby implementation since it simply translate a Ruby block (the dsl) to a cypher string.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

A Ruby DSL for the Neo4j Cypher query language for both MRI and JRuby. The JRuby neo4j-core gem’s cypher dsl has been moved to this gem.

Docs¶ ↑

Why ?¶ ↑

Why should I write my queries using the neo4j-cypher DSL instead of using original cypher syntax ?

Let’s look at a simple example using the cypher query language without the DSL. For example: Find my friends I got 1994

START me=node(1) 
MATCH (me)-[friend_rel:`friends`]->(friends) 
WHERE (friend_rel.since = 1994) 
RETURN friends

Instead of relying on a strict order of the clauses (START, MATCH, WHERE …) and having to use variables (me and friends) you can write the same query using the DSL like this:

node(1).outgoing(rel(:friends).where{|r| r[:since] == 1994})

This is more or less plain english (for me), navigate from node(1) outgoing relationships friends where friends since property is equal 1994. Remember just like ruby, the last value evaluated is the return value which means it will return your friend.

Another example: Return the age property of all the nodes between node 1 and node 3.

(node(1) >> node >> node(3)).nodes.extract(&:age)

Notice the cypher extract function works like the standard ruby map method. The query above will generate the following cypher string:

START v2=node(3),v3=node(1) 
MATCH v1 = (v2)-->(v4)-->(v3) 
RETURN extract(x in nodes(v1) : x.age)

So, the answer why you should use it is simply that it might improve the readability of the code for (ruby) programmers and make it more fun to write queries.

Please read the Neo4j Cypher Docs for more examples.

License¶ ↑

The neo4j-cypher gem is released under the MIT license