mirror of https://gitee.com/bigwinds/arangodb
edges
This commit is contained in:
parent
eef832ad4a
commit
aa85295697
|
@ -0,0 +1,31 @@
|
||||||
|
> curl -X GET --dump - http://localhost:8529/edges/17501660?vertex=17501660/18419164
|
||||||
|
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"_from": "17501660/18419164",
|
||||||
|
"_rev": 19140060,
|
||||||
|
"_to": "17501660/19008988",
|
||||||
|
"_id": "17501660/19140060"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_from": "17501660/18419164",
|
||||||
|
"_rev": 19336668,
|
||||||
|
"_to": "17501660/19008988",
|
||||||
|
"_id": "17501660/19336668",
|
||||||
|
"e": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_from": "17501660/19008988",
|
||||||
|
"_rev": 19402204,
|
||||||
|
"_to": "17501660/18419164",
|
||||||
|
"_id": "17501660/19402204",
|
||||||
|
"e": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"code": 200,
|
||||||
|
"error": false
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
> curl -X GET --dump - http://localhost:8529/edges/17501660?vertex=17501660/18419164&direction=in
|
||||||
|
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"_from": "17501660/19008988",
|
||||||
|
"_rev": 19402204,
|
||||||
|
"_to": "17501660/18419164",
|
||||||
|
"_id": "17501660/19402204",
|
||||||
|
"e": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"code": 200,
|
||||||
|
"error": false
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
> curl -X GET --dump - http://localhost:8529/edges/17501660?vertex=17501660/18419164&direction=out
|
||||||
|
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"_from": "17501660/18419164",
|
||||||
|
"_rev": 19336668,
|
||||||
|
"_to": "17501660/19008988",
|
||||||
|
"_id": "17501660/19336668",
|
||||||
|
"e": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_from": "17501660/18419164",
|
||||||
|
"_rev": 19140060,
|
||||||
|
"_to": "17501660/19008988",
|
||||||
|
"_id": "17501660/19140060"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"code": 200,
|
||||||
|
"error": false
|
||||||
|
}
|
|
@ -36,12 +36,26 @@ describe AvocadoDB do
|
||||||
|
|
||||||
doc.code.should eq(400)
|
doc.code.should eq(400)
|
||||||
doc.parsed_response['error'].should eq(true)
|
doc.parsed_response['error'].should eq(true)
|
||||||
doc.parsed_response['errorNum'].should eq(400)
|
doc.parsed_response['errorNum'].should eq(1205)
|
||||||
doc.parsed_response['code'].should eq(400)
|
doc.parsed_response['code'].should eq(400)
|
||||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||||
|
|
||||||
AvocadoDB.drop_collection(cn)
|
AvocadoDB.drop_collection(cn)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns an error if vertex-handle is missing" do
|
||||||
|
cn = "UnitTestsCollectionEdge"
|
||||||
|
cmd = "/edges/#{@cid}?vertex="
|
||||||
|
doc = AvocadoDB.log_get("#{prefix}-missing-handle", cmd)
|
||||||
|
|
||||||
|
doc.code.should eq(400)
|
||||||
|
doc.parsed_response['error'].should eq(true)
|
||||||
|
doc.parsed_response['errorNum'].should eq(400)
|
||||||
|
doc.parsed_response['code'].should eq(400)
|
||||||
|
doc.headers['content-type'].should eq("application/json")
|
||||||
|
|
||||||
|
AvocadoDB.drop_collection(cn)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -93,7 +107,6 @@ describe AvocadoDB do
|
||||||
id3 = doc.parsed_response['_id']
|
id3 = doc.parsed_response['_id']
|
||||||
|
|
||||||
# check edge
|
# check edge
|
||||||
|
|
||||||
cmd = "/edge/#{id3}"
|
cmd = "/edge/#{id3}"
|
||||||
doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd)
|
doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd)
|
||||||
|
|
||||||
|
@ -115,7 +128,6 @@ describe AvocadoDB do
|
||||||
id4 = doc.parsed_response['_id']
|
id4 = doc.parsed_response['_id']
|
||||||
|
|
||||||
# check edge
|
# check edge
|
||||||
|
|
||||||
cmd = "/edge/#{id4}"
|
cmd = "/edge/#{id4}"
|
||||||
doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd)
|
doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd)
|
||||||
|
|
||||||
|
@ -125,6 +137,52 @@ describe AvocadoDB do
|
||||||
doc.parsed_response['_to'].should eq(id2)
|
doc.parsed_response['_to'].should eq(id2)
|
||||||
doc.parsed_response['e'].should eq(1)
|
doc.parsed_response['e'].should eq(1)
|
||||||
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||||
|
|
||||||
|
# create third edge
|
||||||
|
cmd = "/edge?collection=#{@cid}&from=#{id2}&to=#{id1}"
|
||||||
|
body = "{ \"e\" : 2 }"
|
||||||
|
doc = AvocadoDB.log_post("#{prefix}-create-edge", cmd, :body => body)
|
||||||
|
|
||||||
|
doc.code.should eq(201)
|
||||||
|
doc.parsed_response['_id'].should be_kind_of(String)
|
||||||
|
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||||
|
|
||||||
|
id5 = doc.parsed_response['_id']
|
||||||
|
|
||||||
|
# check edge
|
||||||
|
cmd = "/edge/#{id5}"
|
||||||
|
doc = AvocadoDB.log_get("#{prefix}-read-edge", cmd)
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
doc.parsed_response['_id'].should eq(id5)
|
||||||
|
doc.parsed_response['_from'].should eq(id2)
|
||||||
|
doc.parsed_response['_to'].should eq(id1)
|
||||||
|
doc.parsed_response['e'].should eq(2)
|
||||||
|
doc.headers['content-type'].should eq("application/json; charset=utf-8")
|
||||||
|
|
||||||
|
# check ANY edges
|
||||||
|
cmd = "/edges/#{@cid}?vertex=#{id1}"
|
||||||
|
doc = AvocadoDB.log_get("#{prefix}-read-edges-any", cmd);
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
doc.parsed_response['edges'].should be_kind_of(Array)
|
||||||
|
doc.parsed_response['edges'].length.should be(3)
|
||||||
|
|
||||||
|
# check IN edges
|
||||||
|
cmd = "/edges/#{@cid}?vertex=#{id1}&direction=in"
|
||||||
|
doc = AvocadoDB.log_get("#{prefix}-read-edges-in", cmd);
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
doc.parsed_response['edges'].should be_kind_of(Array)
|
||||||
|
doc.parsed_response['edges'].length.should be(1)
|
||||||
|
|
||||||
|
# check OUT edges
|
||||||
|
cmd = "/edges/#{@cid}?vertex=#{id1}&direction=out"
|
||||||
|
doc = AvocadoDB.log_get("#{prefix}-read-edges-out", cmd);
|
||||||
|
|
||||||
|
doc.code.should eq(200)
|
||||||
|
doc.parsed_response['edges'].should be_kind_of(Array)
|
||||||
|
doc.parsed_response['edges'].length.should be(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ rspec --format d \
|
||||||
rest_create-document_spec.rb \
|
rest_create-document_spec.rb \
|
||||||
rest_read-document_spec.rb \
|
rest_read-document_spec.rb \
|
||||||
rest_update-document_spec.rb \
|
rest_update-document_spec.rb \
|
||||||
rest_delete-document_spec.rb
|
rest_delete-document_spec.rb \
|
||||||
|
rest_edge_spec.rb
|
||||||
|
|
|
@ -50,6 +50,20 @@ var API = "edges";
|
||||||
///
|
///
|
||||||
/// Returns the list of edges starting in the vertex identified by
|
/// Returns the list of edges starting in the vertex identified by
|
||||||
/// @FA{vertex-handle}.
|
/// @FA{vertex-handle}.
|
||||||
|
///
|
||||||
|
/// @EXAMPLES
|
||||||
|
///
|
||||||
|
/// Any direction
|
||||||
|
///
|
||||||
|
/// @verbinclude rest_edge-read-edges-any
|
||||||
|
///
|
||||||
|
/// In edges
|
||||||
|
///
|
||||||
|
/// @verbinclude rest_edge-read-edges-in
|
||||||
|
///
|
||||||
|
/// Out edges
|
||||||
|
///
|
||||||
|
/// @verbinclude rest_edge-read-edges-out
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function GET_edges (req, res) {
|
function GET_edges (req, res) {
|
||||||
|
@ -72,18 +86,24 @@ function GET_edges (req, res) {
|
||||||
var direction = req.parameters['direction'];
|
var direction = req.parameters['direction'];
|
||||||
var e;
|
var e;
|
||||||
|
|
||||||
if (direction == null || direction == "" || direction == "any") {
|
try {
|
||||||
e = collection.edges(vertex);
|
if (direction == null || direction == "" || direction == "any") {
|
||||||
|
e = collection.edges(vertex);
|
||||||
|
}
|
||||||
|
else if (direction == "in") {
|
||||||
|
e = collection.inEdges(vertex);
|
||||||
|
}
|
||||||
|
else if (direction == "out") {
|
||||||
|
e = collection.outEdges(vertex);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actions.resultBad(req, res, actions.ERROR_HTTP_BAD_PARAMETER,
|
||||||
|
"<direction> must be any, in, or out, not: " + JSON.stringify(direction));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (direction == "in") {
|
catch (err) {
|
||||||
e = collection.inEdges(vertex);
|
actions.resultException(req, res, err);
|
||||||
}
|
|
||||||
else if (direction == "out") {
|
|
||||||
e = collection.outEdges(vertex);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actions.resultBad(req, res, actions.ERROR_HTTP_BAD_PARAMETER,
|
|
||||||
"<direction> must be any, in, or out, not: " + JSON.stringify(direction));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue