Sha256: a3bcce65a810e72a843bc35c7bf76a4892c77ee7e2e6c0e0aae4298fe350d87a
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
require "httparty" module Graphshaper class AvocadoDbAdapter include HTTParty base_uri 'localhost:8529' format :json def initialize(vertex_collection_name, edge_collection_name) @vertex_collection_name = vertex_collection_name @edge_collection_name = edge_collection_name @vertex_matching = [] @edge_matching = [] [@vertex_collection_name, @edge_collection_name].each { |collection| drop_and_create_collection collection} end def add_vertex(id) cmd = "/document?collection=#{@vertex_collection_name}" body = "{ \"id\" : \"#{id}\" }" response = self.class.post(cmd, :body => body) @vertex_matching[id] = response.parsed_response["_id"] end def add_edge(edge_id, from, to) database_id_for_first_node = @vertex_matching[from] database_id_for_second_node = @vertex_matching[to] cmd = "/edge?collection=#{@edge_collection_name}&from=#{database_id_for_first_node}&to=#{database_id_for_second_node}" body = "{ \"id\" : \"#{edge_id}\" }" response = self.class.post(cmd, :body => body) @edge_matching[edge_id] = response.parsed_response["_id"] end def close end private def drop_and_create_collection(name) self.class.delete "/_api/collection/#{name}" self.class.post "/_api/collection", body: "{ \"name\" : \"#{name}\"}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
graphshaper-0.2.4 | lib/graphshaper/adapters/avocadodb_adapter.rb |
graphshaper-0.2.3 | lib/graphshaper/adapters/avocadodb_adapter.rb |