1
0
Fork 0

added drop function for graphs

This commit is contained in:
gschwab 2014-05-20 12:56:33 +02:00
parent b3ad2e303f
commit ad10fc85e6
2 changed files with 48 additions and 4 deletions

View File

@ -430,6 +430,51 @@ var _graph = function(graphName) {
return new Graph(graphName, g.edgeDefinitions, collections[0], collections[1]); return new Graph(graphName, g.edgeDefinitions, collections[0], collections[1]);
}; };
////////////////////////////////////////////////////////////////////////////////
/// @brief drop a graph.
////////////////////////////////////////////////////////////////////////////////
var _drop = function(graphId, dropCollections) {
var gdb = db._graphs;
if (gdb === null || gdb === undefined) {
throw "_graphs collection does not exist.";
}
if (!gdb.exists(graphId)) {
throw "Graph " + graphId + " does not exist.";
}
if (dropCollections !== false) {
var graph = gdb.document(graphId);
var edgeDefinitions = graph.edgeDefinitions;
require("internal").print(edgeDefinitions);
edgeDefinitions.forEach(
function(edgeDefinition) {
var from = edgeDefinition.from;
var to = edgeDefinition.to;
var edge = edgeDefinition.collection;
db._drop(edge);
from.forEach(
function(col) {
db._drop(col);
}
);
to.forEach(
function(col) {
db._drop(col);
}
);
}
);
}
gdb.remove(graphId);
return true;
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief return all edge collections of the graph. /// @brief return all edge collections of the graph.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -587,6 +632,7 @@ exports._directedRelationDefinition = _directedRelationDefinition;
exports._graph = _graph; exports._graph = _graph;
exports.edgeDefinitions = edgeDefinitions; exports.edgeDefinitions = edgeDefinitions;
exports._create = _create; exports._create = _create;
exports._drop = _drop;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE // --SECTION-- END-OF-FILE

View File

@ -757,11 +757,11 @@ function EdgesAndVerticesSuite() {
setUp : function() { setUp : function() {
try { try {
arangodb.db._collection("_graphs").remove("_graphs/blubGraph") arangodb.db._collection("_graphs").remove("_graphs/unitTestGraph")
} catch (err) { } catch (err) {
} }
g = graph._create( g = graph._create(
"blubGraph", "unitTestGraph",
graph.edgeDefinitions( graph.edgeDefinitions(
graph._undirectedRelationDefinition("unitTestEdgeCollection1", "unitTestVertexCollection1"), graph._undirectedRelationDefinition("unitTestEdgeCollection1", "unitTestVertexCollection1"),
graph._directedRelationDefinition("unitTestEdgeCollection2", graph._directedRelationDefinition("unitTestEdgeCollection2",
@ -941,8 +941,6 @@ function EdgesAndVerticesSuite() {
assertEqual(result._id, ids.vId35); assertEqual(result._id, ids.vId35);
} }
}; };
} }