Neo4r is an Active Model compliant Ruby wrapper for the Neo4j graph database. It uses the Neography gems.
- ruby ~> 2.1
- neography ~> 1.6
- 2.0.x
- 2.1.x
Add this line to your application's Gemfile:
gem 'neo4r'
And then execute:
$ bundle
Or install it yourself as:
$ gem install neo4r
Neo4r uses Neography to handle Neo4j REST API. So the configuration is same with Neography. Please see the Neography document.
A sample Node model.
class User < Neo4r::Node
end
Create a new node.
user = User.new
user.name = "hiroponz"
user.mail = "[email protected]"
user.age = 35
user.save # => true
Search nodes. The syntax of an exact match is only implemented.
users = User.where(name: "hiroponz")
puts users.first.name # => "hiroponz"
Update nodes.
user = User.where(name: "hiroponz").first
user.age = 36
user.save # => true
Delete nodes.
user = User.where(name: "hiroponz").first
user.destroy => true
Add connection.
zakuni = User.new
zakuni.name = "zakuni"
zakuni.save
hiroponz = User.new
hiroponz.name = "hiroponz"
hiroponz.save
hryk = User.new
hryk.name = "hryk"
hryk.save
suga = User.new
suga.name = "suga"
suga.save
hryk.incoming(:boss) << zakuni
hryk.incoming(:boss) << hiroponz
suga.incoming(:boss) << hryk
Traverse connection.
suga.incoming(:boss).each { |user| puts user.name }
# output
# => "hryk"
suga.incoming(:boss).depth(:all).each { |user| puts user.name }
# output
# => "hryk"
# => "hiroponz"
# => "zakuni"
Delete connection.
hryk.rels(:boss).to_other(hiroponz).destroy
- Fork it ( https://github.com/hiroponz/neo4r/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request