-
Notifications
You must be signed in to change notification settings - Fork 77
Queries
andreasronge edited this page Sep 26, 2014
·
8 revisions
Example
n = Neo4j::Session.query("MATCH (n) WHERE ID(n) = #{n.neo_id} RETURN n").first.nwith params:
n = Neo4j::Session.query("MATCH (n) WHERE ID(n) = {foobar} RETURN n", foobar: n.neo_id).first.nquery.breakquery.createquery.deletequery.execquery.matchquery.on_create_setquery.on_match_setquery.optional_matchquery.order_byquery.paramsquery.pluckquery.removequery.returnquery.setquery.set_propsquery.skipquery.startquery.to_cypherquery.union_cypherquery.usingquery.wherequery.with
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)").firstExample 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