Skip to content

veny/orientdb4r

Repository files navigation

            _            _      _ _     _  _
  ___  _ __(_) ___ _ __ | |_ __| | |__ | || |  _ __
 / _ \| '__| |/ _ \ '_ \| __/ _` | '_ \| || |_| '__|
| (_) | |  | |  __/ | | | || (_| | |_) |__   _| |
 \___/|_|  |_|\___|_| |_|\__\__,_|_.__/   |_| |_|

Ruby binding for Orient DB

A Ruby client for the NoSQL Graph/Document database Orient DB (orientdb.org).

<img src=“https://badge.fury.io/rb/orientdb4r.svg” alt=“Gem Version” /> <img src=“https://secure.travis-ci.org/veny/orientdb4r.png” alt=“Build Status” /> <img src=“https://coveralls.io/repos/veny/orientdb4r/badge.svg?branch=master” alt=“Coverage Status” />

USAGE

see Wiki page for more sample at github.com/veny/orientdb4r/wiki

require 'orientdb4r'

DB = 'foo'
CLASS = 'myclass'

client = Orientdb4r.client  # equivalent for :host => 'localhost', :port => 2480, :ssl => false

client.database_exists? :database => DB, :user => 'admin', :password => 'admin'
=> false

client.create_database :database => DB, :storage => :memory, :user => 'root', :password => 'root'
=> false

client.connect :database => DB, :user => 'admin', :password => 'admin'
=> true

unless client.class_exists? CLASS
  client.create_class(CLASS) do |c|
    c.property 'prop1', :integer, :notnull => true, :min => 1, :max => 99
    c.property 'prop2', :string, :mandatory => true
    c.link     'users', :linkset, 'OUser' # by default: :mandatory => false, :notnull => false
  end
end

admin = client.query("SELECT FROM OUser WHERE name = 'admin'")[0]
1.upto(5) do |i|
  # insert link to admin only to first two
  client.command "INSERT INTO #{CLASS} (prop1, prop2, users) VALUES (#{i}, 'text#{i}', [#{admin['@rid'] if i<3}])"
end

puts client.query "SELECT FROM #{CLASS}"
=> {"@type"=>"d", "@rid"=>"#6:0", "@version"=>0, "@class"=>"myclass", "prop1"=>1, "prop2"=>"text1", "users"=>["#4:0"]}
=> {"@type"=>"d", "@rid"=>"#6:1", "@version"=>0, "@class"=>"myclass", "prop1"=>2, "prop2"=>"text2", "users"=>["#4:0"]}
=> {"@type"=>"d", "@rid"=>"#6:2", "@version"=>0, "@class"=>"myclass", "prop1"=>3, "prop2"=>"text3", "users"=>[]}
=> {"@type"=>"d", "@rid"=>"#6:3", "@version"=>0, "@class"=>"myclass", "prop1"=>4, "prop2"=>"text4", "users"=>[]}
=> {"@type"=>"d", "@rid"=>"#6:4", "@version"=>0, "@class"=>"myclass", "prop1"=>5, "prop2"=>"text5", "users"=>[]}

puts client.query "SELECT count(*) FROM #{CLASS}"
=> {"@type"=>"d", "@version"=>0, "count"=>5, "@fieldTypes"=>"count=l"}

puts client.query "SELECT max(prop1) FROM #{CLASS}"
=> {"@type"=>"d", "@version"=>0, "max"=>5}

puts client.query "TRAVERSE any() FROM (SELECT FROM #{CLASS} WHERE prop1 = 1)"
=> {"@type"=>"d", "@rid"=>"#6:0", "@version"=>0, "@class"=>"myclass", "prop1"=>1, "prop2"=>"text1", "users"=>["#4:0"]}
=> {"@type"=>"d", "@rid"=>"#4:0", "@version"=>0, "@class"=>"OUser", "name"=>"admin", "password"=>"{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918", "status"=>"ACTIVE", "roles"=>["#3:0"]}
=> {"@type"=>"d", "@rid"=>"#3:0", "@version"=>0, "@class"=>"ORole", "name"=>"admin", "mode"=>1, "rules"=>{}, "@fieldTypes"=>"mode=b"}

client.drop_class CLASS
client.disconnect
=> ["401 Unauthorized: Logged out", 401]

INSTALL

> sudo gem install orientdb4r

Important Upgrade Notice

  • see changelog.txt

FEATURES/PROBLEMS

  • Supports only REST API right now

REQUIREMENTS

  • Ruby 1.9.x+

  • OrientDB 1.0.x-1.3.x for v0.3.x

  • OrientDB 1.4.0+ for v0.4.x

  • OrientDB 1.6.0+ for v0.5.x

TESTS

> cd /path/to/repository
> bundle exec rake db:setup4test  # to create the temp DB which doesn't seem to be a default since v1.5
> bundle exec rake test

Make sure before starting the tests:

  • database server is running on localhost:2480

  • there is a root account with username=root and password=root; if your password is different, specify it with an ‘ORIENTDB_ROOT_PASS` environment variable

AUTHOR

LICENSE

CONTRIBUTING

  1. Fork it ( github.com/veny/orientdb4r/fork )

  2. Create your feature branch ( git checkout -b my-new-feature )

  3. Commit your changes ( git commit -am 'Add some feature' )

  4. Push to the branch ( git push origin my-new-feature )

  5. Create a new Pull Request