Giter VIP home page Giter VIP logo

neo4j-cypher's Introduction

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

neo4j-cypher's People

Contributors

andreasronge avatar blizkreeg avatar saterus avatar kamranjon avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.