-
Notifications
You must be signed in to change notification settings - Fork 276
Neo4j::Cypher API
The API for the neo4j-cypher gem consists of one method: Neo4j::Cypher.query
which returns an object of type Neo4j::Cypher::Result
The Neo4j::Cypher.query
method takes a ruby block as argument and returns an Neo4j::Cypher::Result
. The Neo4j::Cypher::Result#to_s
method returns the query as a string.
Example:
Neo4j::Cypher.query do
node(3) > :r > :x
end.to_s
This will generate the following string "START v1=node(3) MATCH v2 = (v1)-[:`r`]->(x) RETURN v2"
The Neo4j::Cypher::Result
has two useful method to_s
(as shown above) and return_names
.
As shown in the example above the DSL can automatically generate new variables. In order to know which values are returned use the return_names
method.
Example:
Neo4j::Cypher.query do
node(3) > :r > :x
end.return_names
It will return the following array: [:v2]
The neo4j-cypher gem includes a small adaptor for the neography gem which makes the following possible:
require 'neography'
require 'neo4j-cypher'
require 'neo4j-cypher/neography' #adds a Neography::Rest#execute_cypher method
@neo = Neography::Rest.new
@neo.execute_cypher(n) { |me| me > ':friends' > node > ':friends' > node(:foaf)[:name].ret }['data']
See this for a complete example. Notice that using JRuby is not required !
The neo4j-core gem also wraps the neo4j-cypher API.
The following example will also execute the query using the native neo4j database.
require 'neo4j-core'
q = Neo4j.query{ node(42) }
Notice that the neo4j-core gem must be run on JRuby
WARNING: Much of the information in this wiki is out of date. We are in the process of moving things to readthedocs
- Project Introduction
- Neo4j::ActiveNode
- Neo4j::ActiveRel
- Search and Scope
- Validation, Uniqueness, and Case Sensitivity
- Indexing VS Legacy Indexing
- Optimized Methods
- Inheritance
- Core: Nodes & Rels
- Introduction
- Persistence
- Find : Lucene
- Relationships
- Third Party Gems & extensions
- Scaffolding & Generators
- HA Cluster