A simple Ruby wrapper around the Neo4j graph database that works with the server and embedded Neo4j API. This gem can be used both from JRuby and normal MRI. It can be used standalone without the neo4j gem.
To make a basic connection to Neo4j to execute Cypher queries, first choose an adaptor. Adaptors for HTTP and Embedded mode (jRuby only) are available (support for Neo4j 3.0's Bolt protocol is planned). You can create an adaptor like:
http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474')
# or
neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new('/file/path/to/graph.db')
Once you have an adaptor you can create a session like so:
neo4j_session = Neo4j::Core::CypherSession.new(http_adaptor)
From there you can make queries with a Cypher string:
# Basic query
neo4j_session.query('MATCH (n) RETURN n LIMIT 10')
# Query with parameters
neo4j_session.query('MATCH (n) RETURN n LIMIT {limit}', limit: 10)
Or via the Neo4j::Core::Query
class
query_obj = Neo4j::Core::Query.new.match(:n).return(:n).limit(10)
neo4j_session.query(query_obj)
Making multiple queries with one request is support with the HTTP Adaptor:
results = neo4j_session.queries do
append 'MATCH (n:Foo) RETURN n LIMIT 10'
append 'MATCH (n:Bar) RETURN n LIMIT 5'
end
results[0] # results of first query
results[1] # results of second query
When doing batched queries, there is also a shortcut for getting a new Neo4j::Core::Query
:
results = neo4j_session.queries do
append query.match(:n).return(:n).limit(10)
end
results[0] # result
https://github.com/neo4jrb/neo4j-core/tree/v2.x
All new documentation will be done via our readthedocs site, though some old documentation has yet to be moved from our wiki (also there is the neo4j-core wiki)
Consulting support? Contact Chris and/or Brian
Pull request with high test coverage and good code climate values will be accepted faster.
Notice, only JRuby can run all the tests (embedded and server db). To run tests with coverage: rake coverage
.
- Neo4j.rb - MIT, see the LICENSE file http://github.com/neo4jrb/neo4j-core/tree/master/LICENSE.
- Lucene - Apache, see http://lucene.apache.org/java/docs/features.html
- Neo4j - Dual free software/commercial license, see http://neo4j.org/
Notice there are different license for the neo4j-community, neo4j-advanced and neo4j-enterprise jar gems. Only the neo4j-community gem is by default required.