-
Notifications
You must be signed in to change notification settings - Fork 80
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.n
with params:
n = Neo4j::Session.query("MATCH (n) WHERE ID(n) = {foobar} RETURN n", foobar: n.neo_id).first.n
query.break
query.create
query.delete
query.exec
query.match
query.on_create_set
query.on_match_set
query.optional_match
query.order_by
query.params
query.pluck
query.remove
query.return
query.set
query.set_props
query.skip
query.start
query.to_cypher
query.union_cypher
query.using
query.where
query.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)").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