Skip to content

Commit

Permalink
adding schema indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 15, 2013
1 parent a547370 commit ea658b0
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
script: "bundle exec rake neo4j:install['enterprise','1.9'] neo4j:start spec --trace"
script: "bundle exec rake neo4j:install['enterprise','2.0.0-M03'] neo4j:start spec --trace"
language: ruby
rvm:
- 1.9.3
14 changes: 14 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'neography/rest/properties'
require 'neography/rest/indexes'
require 'neography/rest/auto_indexes'
require 'neography/rest/schema_indexes'

require 'neography/rest/nodes'
require 'neography/rest/node_properties'
Expand Down Expand Up @@ -49,6 +50,7 @@ def initialize(options = ENV['NEO4J_URL'] || {})
@other_node_relationships = OtherNodeRelationships.new(@connection)
@node_indexes = NodeIndexes.new(@connection)
@node_auto_indexes = NodeAutoIndexes.new(@connection)
@schema_indexes = SchemaIndexes.new(@connection)
@node_traversal = NodeTraversal.new(@connection)
@node_paths = NodePaths.new(@connection)

Expand All @@ -70,6 +72,18 @@ def initialize(options = ENV['NEO4J_URL'] || {})
def list_relationship_types
@relationship_types.list
end

def get_schema_index(label)
@schema_indexes.list(label)
end

def create_schema_index(label, properties)
@schema_indexes.create(label, properties)
end

def delete_schema_index(label, property)
@schema_indexes.drop(label, property)
end

# nodes

Expand Down
34 changes: 34 additions & 0 deletions lib/neography/rest/schema_indexes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Neography
class Rest
class SchemaIndexes
extend Neography::Rest::Paths
include Neography::Rest::Helpers

add_path :base, "/schema/index/:label"
add_path :drop, "/schema/index/:label/:index"

def initialize(connection)
@connection = connection
end

def list(label)
@connection.get(base_path(:label => label))
end

def drop(label, index)
@connection.delete(drop_path(:label => label, :index => index))
end

def create(label, keys = [])
options = {
:body => (
{ :property_keys => keys
}
).to_json,
:headers => json_content_type
}
@connection.post(base_path(:label => label), options)
end
end
end
end
32 changes: 32 additions & 0 deletions spec/integration/rest_schema_index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

describe Neography::Rest do
before(:each) do
@neo = Neography::Rest.new
end

describe "create a schema index" do
it "can create a schema index" do
si = @neo.create_schema_index("person", ["name"])
si.should_not be_nil
si["property-keys"].should include("name")
end

end

describe "list schema indexes" do
it "can get a listing of node indexes" do
si = @neo.get_schema_index("person")
si.should_not be_nil
si.first["label"].should include("person")
si.first["property-keys"].should include("name")
end
end

describe "drop schema indexes" do
it "can drop an existing schema index" do
si = @neo.delete_schema_index("person", "name")
si.should be_nil
end
end
end
31 changes: 31 additions & 0 deletions spec/unit/rest/schema_index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

module Neography
class Rest
describe SchemaIndexes do

let(:connection) { stub(:configuration => "http://configuration") }
subject { SchemaIndexes.new(connection) }

it "create schema indexes" do
options = {
:body => '{"property_keys":["name"]}',
:headers => json_content_type
}
connection.should_receive(:post).with("/schema/index/person", options)
subject.create("person", ["name"])
end

it "get schema indexes" do
connection.should_receive(:get).with("/schema/index/person")
subject.list("person")
end

it "delete schema indexes" do
connection.should_receive(:delete).with("/schema/index/person/name")
subject.drop("person","name")
end

end
end
end

0 comments on commit ea658b0

Please sign in to comment.