diff --git a/js/common/modules/org/arangodb/general-graph.js b/js/common/modules/org/arangodb/general-graph.js index d186326e19..016b20b36d 100644 --- a/js/common/modules/org/arangodb/general-graph.js +++ b/js/common/modules/org/arangodb/general-graph.js @@ -430,6 +430,51 @@ var _graph = function(graphName) { 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. //////////////////////////////////////////////////////////////////////////////// @@ -587,6 +632,7 @@ exports._directedRelationDefinition = _directedRelationDefinition; exports._graph = _graph; exports.edgeDefinitions = edgeDefinitions; exports._create = _create; +exports._drop = _drop; // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE diff --git a/js/common/tests/shell-general-graph.js b/js/common/tests/shell-general-graph.js index c1641da63d..0ff51f8335 100644 --- a/js/common/tests/shell-general-graph.js +++ b/js/common/tests/shell-general-graph.js @@ -757,11 +757,11 @@ function EdgesAndVerticesSuite() { setUp : function() { try { - arangodb.db._collection("_graphs").remove("_graphs/blubGraph") + arangodb.db._collection("_graphs").remove("_graphs/unitTestGraph") } catch (err) { } g = graph._create( - "blubGraph", + "unitTestGraph", graph.edgeDefinitions( graph._undirectedRelationDefinition("unitTestEdgeCollection1", "unitTestVertexCollection1"), graph._directedRelationDefinition("unitTestEdgeCollection2", @@ -941,8 +941,6 @@ function EdgesAndVerticesSuite() { assertEqual(result._id, ids.vId35); } - - }; }