Skip to content

Neo4j::core introduction

andreasronge edited this page Oct 4, 2012 · 7 revisions

This gem is only a thin JRuby wrapper around the Neo4j Java API. It does not wrap nodes in Ruby object. It can be used instead of the neo4j-wrapper or neo4j gems when you don't need a Ruby mapping for relationships and nodes, check the GitHub Project.

API

Content

Example

require 'neo4j-core'
Neo4j::Transaction.run do
  andreas = Neo4j::Node.new(:name => 'andreas')
  peter = Neo4j::Node.new(:name => 'peter')
  Neo4j::Relationship.new(:friends, andreas, peter, :since => 2008)
  Neo4j.ref_node.outgoing(:people) << andreas << peter
end

# Traversal API and Ruby Enumerable
Neo4j.ref_node.outgoing(:people).count # => 2 
Neo4j.ref_node.outgoing(:people).find{|n| n[:name] == 'andreas'}.props #  => {"_neo_id"=>7, "name"=>"andreas"}

# The same in Cypher, check the cypher DSL docs !

# the following line returns  2
Neo4j.query(Neo4j.ref_node) {|ref_node| ref_node.outgoing(:people).count.as(:nbr_people)}.first[:nbr_people]  

# The following line returns [:v1] 
Neo4j.query(Neo4j.ref_node) {|ref_node| ref_node.outgoing(:people)[:name] == 'andreas'}.columns 

# The following line returns {"_neo_id"=>7, "name"=>"andreas"}
Neo4j.query(Neo4j.ref_node) {|ref_node| ref_node.outgoing(:people)[:name] == 'andreas'}.first[:v1].props

Installation

rvm use jruby-1.7.0.RC1
gem install neo4j-core

It only works with JRuby !

Clone this wiki locally