-
Notifications
You must be signed in to change notification settings - Fork 276
Neo4j v3 Setup
Include in your gemfile:
# for rubygems
gem 'neo4j', '~> 4.1.1'
# for master, which is typically stable:
gem 'neo4j', github: 'neo4jrb/neo4j'
If using Rails, include the railtie in application.rb
:
require 'rails/railtie'
If not using Rails, include the rake tasks in your Rakefile:
load 'neo4j/tasks/neo4j_server.rake'
load 'neo4j/tasks/migration.rake'
Rake tasks and basic server connection are defined in the neo4j-core gem. See its documentation for more details.
With the Rake tasks loaded, install Neo4j and start the server:
rake neo4j:install[community-2.1.6]
# OR
# rake neo4j:install[community-2.2.0-M02]
rake neo4j:start
To open a session to the neo4j server database:
# In JRuby or MRI, using Neo4j Server mode. When the railtie is included, this happens automatically.
Neo4j::Session.open(:server_db)
After you have created a session you can now use the database, see below.
On JRuby you can access the database in two different ways: using the embedded db or the server db.
Example, Open a session to the neo4j embedded database (running in the same JVM)
session = Neo4j::Session.open(:embedded_db, '/folder/db')
session.start
Example of a rails config/application.rb
file:
config.neo4j.session_options = { basic_auth: { username: 'foo', password: 'bar'} }
config.neo4j.session_type = :server_db
config.neo4j.session_path = 'http://localhost:7474'
For more configuration options, use the initialize
session option parameter which is used to initialize a Faraday session.
Example: config.neo4j.session_options = {initialize: { ssl: { verify: true }}
See https://gist.github.com/andreasronge/11189170 how to configure the Neo4j::Session with basic authentication from a non-rails application.
A _classname
property is added to all nodes during creation to store the object's class name. This prevents an extra query to the database when wrapping the node in a Ruby class. To change the property name, add this to application.rb
:
config.neo4j[:class_name_property] = :new_name
NOTE The above is not true when using the master branch and Neo4j v2.1.5 or greater. See https://github.com/neo4jrb/neo4j/wiki/Neo4j.rb-v4-Introduction for more info.
Add a Neo4j db to your application:
# Substitute "chalk" with the plan of your choice
heroku addons:add graphenedb:chalk
See https://devcenter.heroku.com/articles/graphenedb for more info, https://addons.heroku.com/graphenedb for plans.
Example of a rails config/application.rb
file:
config.neo4j.session_type = :server_db
config.neo4j.session_path = ENV["GRAPHENEDB_URL"] || 'http://localhost:7474'
rails new myapp -m http://neo4jrb.io/neo4j/neo4j.rb -O
cd myapp
rake neo4j:install[community-2.1.6]
rake neo4j:start
rails generate scaffold User name:string email:string
rails s
open http://localhost:3000/users
Or manually modify the rails config file config/application.rb
:
require 'neo4j/railtie'
module Blog
class Application < Rails::Application
# This is for embedded db, only available from JRuby
#config.neo4j.session_type = :embedded_db # or server_db
#config.neo4j.session_path = File.expand_path('neo4j-db', Rails.root) # or http://localhost:port
end
end
You can skip Active Record by using the -O flag when generating the rails project.
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