Skip to content
andreasronge edited this page Sep 26, 2014 · 8 revisions

Query API

Query with Strings

Example

n = Neo4j::Session.query("MATCH (n) WHERE ID(n) = #{n.neo_id} RETURN n").first.n

with params:

n = Neo4j::Session.query("MATCH (n) WHERE ID(n) = {foobar} RETURN n", foobar: n.neo_id).first.n

Cypher DSL API

Examples

Examples using queries as strings:

# same as Neo4j::Session.current.query
Neo4j::Session.query.create(n: Label: {mydata: 'Hello'}).exec

# With cypher parameters
Neo4j::Session.query.start(n: "node({a_parameter})").params(a_parameter: 0).pluck("ID(n)").first

Example of chained queries:

query = Neo4j::Session.query.match(n: :person) # Returns a Query object
 

query.return(:n) # Also returns a Query object

query.return(:n).to_a # Returns an array of result rows as Structs (i.e. [<struct n=Node>, etc...])

query.pluck(:n) # Returns an array of nodes

query.return(n: [:name, :age]) # => [<struct name='Brian', age=33>, etc...]

query.where(name: /kalle.*/)

query.order(n: {name: :desc, age: :asc}).skip(5).limit(4) # sorting and skip and limit the result

query.match('n-[:friends]->o').where(o: {age: 42}, n: {age: 1})

query.match('n-[f:friends]->o').pluck(:f) # [<Relationship>, etc..]

WARNING: Much of the information in this wiki is out of day. We are in the process of moving things to readthedocs

Api

Contribute

Clone this wiki locally