Skip to content
A Ruby library for working with Google's Cayley graph database.
Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib
spec
.gitignore
.rspec
Gemfile
README.md
cayley.gemspec

README.md

cayley-ruby

A ruby library for working with Google's Cayley graph database.

Installation

You can install it via gem

gem install cayley

Usage

Start your Cayley

# example using 30kmoviedata from cayley's repository
./cayley http --dbpath=30kmoviedata.nq.gz

You can use methods from Gremlin API documentation, just translate method names to snake style equivalent.

As a first step you need to create your client

require 'cayley'

graph = Cayley::Graph.new

# or

graph = Cayley::Graph.new(host: 'localhost', port: 64210)

Then using 30kmovies.nt db from cayley's repository you can do this

graph.vertex.get_limit(5)

graph.vertex('Humphrey Bogart').all

graph.v('Humphrey Bogart').all

graph.v('Humphrey Bogart').in('name').all

graph.v('Casablanca').in('name').all

graph.v.has('name', 'Casablanca').all

You can also use morphism

film_to_actor = graph.morphism
                     .out('/film/film/starring')
                     .out('/film/performance/actor')
graph.v
     .has('name', 'Casablanca')
     .follow(film_to_actor)
     .out('name').all

For more info take a look at Cayley's repository

Advanced

By default result of your queries are wrapped in Hashie::Mash so you can do things like these

graph.v.all.each do |result|
  puts result.id # instead of result['id']
end

If you want to use plain ruby hashes you can disable wrapping by

graph = Cayley::Graph.new(result_wrapper: nil)

Or you can use some custom wrapper if you put class instead of nil.

Debugging

If you are not sure why you are getting nil as a result of your query and you are not able to find out the solution you can turn on debug mode where used Gremlin query is printed out.

graph = Cayley::Graph.new(debug: true)

TODO

  • logger
  • tests
You can’t perform that action at this time.