'fixes sublimetext color bug, ignore

What is Neo4j.rb?

The Neo4j.rb project is made up of the follow Ruby gems:

  • neo4j A Object-Graph-Mapper (OGM) for the Neo4j graph database. It tries to follow API conventions established by ActiveRecord and familiar to most Ruby developers but with a Neo4j flavor.
  • neo4j-core A low level driver for connecting to Neo4j. Used by the neo4j gem.
  • neo4j-rake_tasks) A set of rake tasks for installing and managing a Neo4j database within your project. Used by the neo4j-core gem.

Ruby

(software) A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

Graph
Database

(computer science) A graph database stores data in a graph, the most generic of data structures, capable of elegantly representing any kind of data in a highly accessible way.

Neo4j

(databases) The world's leading graph database

If you're already familiar with ActiveRecord, DataMapper, or Mongoid, you'll find the Object Model features you've come to expect from an O*M:

  • Properties
  • Indexes / Constraints
  • Callbacks
  • Validation
  • Assocations
Because relationships are first-class citizens in Neo4j, models can be created for both nodes and relationships.

Additional features include

  • A chainable arel-inspired query builder
  • Transactions
  • Migration framework

Requirements

  • Ruby 2.0.0+ (tested in MRI and JRuby, MRI 2.2.1+ recommended)
  • Neo4j 2.1.5+ (version 4.0+ of the gem is required to use neo4j 2.2+)

Latest News

News Archive

Get started

Ruby

New to Ruby? Try Ruby in your browser!

Installation resources:

Neo4j

New to Neo4j? Try Neo4j in your browser!

Installation resources:

Introduction screencast

Ruby Rogues interview

Brian Underwood, one of the maintainers of the Neo4j.rb project, recently gave an interview with the Ruby Rogues. See episode #236.

Modeling

In your Gemfile

  gem 'neo4j'

A sample ActiveNode model

 class User
    include Neo4j::ActiveNode

    property :name
    property :age, type: Integer

    has_many :out, :friends, type: :friends_with, model_name: 'User'
    has_one :in,   :github_profile, type: :linked_to  # model_name: 'GithubProfile' assumed
  end

Using query chaining to get the github profiles for a user's friends

  user.friends.github_profile

If you're the sort who likes to watch a video, check out our intro screencast.
If you like to read, check out our documentation's setup page.

Simple queries

If you just want to execute some raw cypher queries you only need the neo4j-core gem.

  neo4j_session = Neo4j::Session.open(:server_db, ENV['NEO4J_DB_URL'])

  me = neo4j_session.query('MATCH (found:User) WHERE found.name = {aName} RETURN found',
                           aName: 'Andreas').first.found

There is also a query-building API which allows you to build cypher queries with method chaining:

  user = neo4j_session.query.match(found: :User).
                              where(found: {name: 'Andreas'}).
                              return(:user).
                              first.found

At each step in the chain a query object is returned which is also Enumerable. See the documentation for more info.

Also note that with the query chaining there is no need to use params (which are important for efficient neo4j queries). They will be used in the background in this case.

Install in Ruby on Rails

In your config/application.rb

  config.neo4j.session_type = :server_db
  config.neo4j.session_path = ENV['NEO4J_URL'] || 'http://localhost:7475'

The url format is http://user:password@localhost:7475

Getting involved

Like any open source project we happily welcome:

You can also join us on our mailing list

Getting Help

Need help using the gem? Think you've found a bug? There are a few ways to get help.

Source code of this site

If you notice anything wrong with this page, feel free to submit a pull request on the repository