mirror of https://gitee.com/bigwinds/arangodb
Pulled addVertex into Common + tiny style fixes
This commit is contained in:
parent
a81a0f0728
commit
c357fa1133
|
@ -115,10 +115,10 @@ Edge.prototype.setProperty = function (name, value) {
|
||||||
|
|
||||||
update[name] = value;
|
update[name] = value;
|
||||||
|
|
||||||
requestResult = this._graph._connection.PUT("/_api/graph/"
|
requestResult = this._graph._connection.PUT("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._graph._properties._key)
|
encodeURIComponent(this._graph._properties._key) +
|
||||||
+ "/edge/"
|
"/edge/" +
|
||||||
+ encodeURIComponent(this._properties._key),
|
encodeURIComponent(this._properties._key),
|
||||||
JSON.stringify(update));
|
JSON.stringify(update));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -173,10 +173,10 @@ Vertex.prototype.edges = function () {
|
||||||
var edges;
|
var edges;
|
||||||
var cursor;
|
var cursor;
|
||||||
|
|
||||||
requestResult = graph._connection.POST("/_api/graph/"
|
requestResult = graph._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(graph._properties._key)
|
encodeURIComponent(graph._properties._key) +
|
||||||
+ "/edges/"
|
"/edges/" +
|
||||||
+ encodeURIComponent(this._properties._key),
|
encodeURIComponent(this._properties._key),
|
||||||
'{ "filter" : { "direction" : "any" } }');
|
'{ "filter" : { "direction" : "any" } }');
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -204,10 +204,10 @@ Vertex.prototype.getInEdges = function () {
|
||||||
var edges;
|
var edges;
|
||||||
var cursor;
|
var cursor;
|
||||||
|
|
||||||
requestResult = graph._connection.POST("/_api/graph/"
|
requestResult = graph._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(graph._properties._key)
|
encodeURIComponent(graph._properties._key) +
|
||||||
+ "/edges/"
|
"/edges/" +
|
||||||
+ encodeURIComponent(this._properties._key),
|
encodeURIComponent(this._properties._key),
|
||||||
JSON.stringify({ filter : { direction : "in", labels: labels } }));
|
JSON.stringify({ filter : { direction : "in", labels: labels } }));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -235,10 +235,10 @@ Vertex.prototype.getOutEdges = function () {
|
||||||
var edges;
|
var edges;
|
||||||
var cursor;
|
var cursor;
|
||||||
|
|
||||||
requestResult = graph._connection.POST("/_api/graph/"
|
requestResult = graph._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(graph._properties._key)
|
encodeURIComponent(graph._properties._key) +
|
||||||
+ "/edges/"
|
"/edges/" +
|
||||||
+ encodeURIComponent(this._properties._key),
|
encodeURIComponent(this._properties._key),
|
||||||
JSON.stringify({ filter : { direction : "out", labels: labels } }));
|
JSON.stringify({ filter : { direction : "out", labels: labels } }));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -266,10 +266,10 @@ Vertex.prototype.getEdges = function () {
|
||||||
var edges;
|
var edges;
|
||||||
var cursor;
|
var cursor;
|
||||||
|
|
||||||
requestResult = graph._connection.POST("/_api/graph/"
|
requestResult = graph._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(graph._properties._key)
|
encodeURIComponent(graph._properties._key) +
|
||||||
+ "/edges/"
|
"/edges/" +
|
||||||
+ encodeURIComponent(this._properties._key),
|
encodeURIComponent(this._properties._key),
|
||||||
JSON.stringify({ filter : { labels: labels } }));
|
JSON.stringify({ filter : { labels: labels } }));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -312,10 +312,10 @@ Vertex.prototype.setProperty = function (name, value) {
|
||||||
|
|
||||||
update[name] = value;
|
update[name] = value;
|
||||||
|
|
||||||
requestResult = this._graph._connection.PUT("/_api/graph/"
|
requestResult = this._graph._connection.PUT("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._graph._properties._key)
|
encodeURIComponent(this._graph._properties._key) +
|
||||||
+ "/vertex/"
|
"/vertex/" +
|
||||||
+ encodeURIComponent(this._properties._key),
|
encodeURIComponent(this._properties._key),
|
||||||
JSON.stringify(update));
|
JSON.stringify(update));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -414,14 +414,14 @@ Graph.prototype.initialize = function (name, vertices, edges) {
|
||||||
Graph.prototype.drop = function () {
|
Graph.prototype.drop = function () {
|
||||||
var requestResult;
|
var requestResult;
|
||||||
|
|
||||||
requestResult = this._connection.DELETE("/_api/graph/"
|
requestResult = this._connection.DELETE("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key));
|
encodeURIComponent(this._properties._key));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief adds an edge to the graph
|
/// @brief saves an edge to the graph
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, params) {
|
Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, params) {
|
||||||
|
@ -439,27 +439,18 @@ Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, params) {
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief adds a vertex to the graph
|
/// @brief saves a vertex to the graph
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Graph.prototype.addVertex = function (id, data) {
|
Graph.prototype._saveVertex = function (id, params) {
|
||||||
var requestResult;
|
var requestResult;
|
||||||
var params;
|
|
||||||
var key;
|
|
||||||
|
|
||||||
if (data === null || typeof data !== "object") {
|
if (is.existy(id)) {
|
||||||
params = {};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
params = data._shallowCopy || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id !== undefined) {
|
|
||||||
params._key = id;
|
params._key = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
requestResult = this._connection.POST("/_api/graph/"
|
requestResult = this._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key) + "/vertex",
|
encodeURIComponent(this._properties._key) + "/vertex",
|
||||||
JSON.stringify(params));
|
JSON.stringify(params));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -474,10 +465,10 @@ Graph.prototype.addVertex = function (id, data) {
|
||||||
Graph.prototype.getVertex = function (id) {
|
Graph.prototype.getVertex = function (id) {
|
||||||
var requestResult;
|
var requestResult;
|
||||||
|
|
||||||
requestResult = this._connection.GET("/_api/graph/"
|
requestResult = this._connection.GET("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key)
|
encodeURIComponent(this._properties._key) +
|
||||||
+ "/vertex/"
|
"/vertex/" +
|
||||||
+ encodeURIComponent(id));
|
encodeURIComponent(id));
|
||||||
|
|
||||||
if (requestResult.error === true && requestResult.code === 404) {
|
if (requestResult.error === true && requestResult.code === 404) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -502,9 +493,9 @@ Graph.prototype.getVertices = function () {
|
||||||
var cursor;
|
var cursor;
|
||||||
var Iterator;
|
var Iterator;
|
||||||
|
|
||||||
requestResult = this._connection.POST("/_api/graph/"
|
requestResult = this._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key)
|
encodeURIComponent(this._properties._key) +
|
||||||
+ "/vertices",
|
"/vertices",
|
||||||
"{}");
|
"{}");
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -539,10 +530,10 @@ Graph.prototype.getVertices = function () {
|
||||||
Graph.prototype.getEdge = function (id) {
|
Graph.prototype.getEdge = function (id) {
|
||||||
var requestResult;
|
var requestResult;
|
||||||
|
|
||||||
requestResult = this._connection.GET("/_api/graph/"
|
requestResult = this._connection.GET("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key)
|
encodeURIComponent(this._properties._key) +
|
||||||
+ "/edge/"
|
"/edge/" +
|
||||||
+ encodeURIComponent(id));
|
encodeURIComponent(id));
|
||||||
|
|
||||||
if (requestResult.error === true && requestResult.code === 404) {
|
if (requestResult.error === true && requestResult.code === 404) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -567,9 +558,9 @@ Graph.prototype.getEdges = function () {
|
||||||
var cursor;
|
var cursor;
|
||||||
var Iterator;
|
var Iterator;
|
||||||
|
|
||||||
requestResult = this._connection.POST("/_api/graph/"
|
requestResult = this._connection.POST("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key)
|
encodeURIComponent(this._properties._key) +
|
||||||
+ "/edges",
|
"/edges",
|
||||||
"{}");
|
"{}");
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
@ -604,10 +595,10 @@ Graph.prototype.getEdges = function () {
|
||||||
Graph.prototype.removeVertex = function (vertex) {
|
Graph.prototype.removeVertex = function (vertex) {
|
||||||
var requestResult;
|
var requestResult;
|
||||||
|
|
||||||
requestResult = this._connection.DELETE("/_api/graph/"
|
requestResult = this._connection.DELETE("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key)
|
encodeURIComponent(this._properties._key) +
|
||||||
+ "/vertex/"
|
"/vertex/" +
|
||||||
+ encodeURIComponent(vertex._properties._key));
|
encodeURIComponent(vertex._properties._key));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
|
||||||
|
@ -621,10 +612,10 @@ Graph.prototype.removeVertex = function (vertex) {
|
||||||
Graph.prototype.removeEdge = function (edge) {
|
Graph.prototype.removeEdge = function (edge) {
|
||||||
var requestResult;
|
var requestResult;
|
||||||
|
|
||||||
requestResult = this._connection.DELETE("/_api/graph/"
|
requestResult = this._connection.DELETE("/_api/graph/" +
|
||||||
+ encodeURIComponent(this._properties._key)
|
encodeURIComponent(this._properties._key) +
|
||||||
+ "/edge/"
|
"/edge/" +
|
||||||
+ encodeURIComponent(edge._properties._key));
|
encodeURIComponent(edge._properties._key));
|
||||||
|
|
||||||
arangosh.checkRequestResult(requestResult);
|
arangosh.checkRequestResult(requestResult);
|
||||||
|
|
||||||
|
|
|
@ -631,6 +631,42 @@ Graph.prototype.addEdge = function (out_vertex, in_vertex, id, label, data, wait
|
||||||
return this._saveEdge(id, out_vertex, in_vertex, this._prepareEdgeData(data, label), waitForSync);
|
return this._saveEdge(id, out_vertex, in_vertex, this._prepareEdgeData(data, label), waitForSync);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief adds a vertex to the graph
|
||||||
|
///
|
||||||
|
/// @FUN{@FA{graph}.addVertex(@FA{id})}
|
||||||
|
///
|
||||||
|
/// Creates a new vertex and returns the vertex object. The identifier
|
||||||
|
/// @FA{id} must be a unique identifier or null.
|
||||||
|
///
|
||||||
|
/// @FUN{@FA{graph}.addVertex(@FA{id}, @FA{data})}
|
||||||
|
///
|
||||||
|
/// Creates a new vertex and returns the vertex object. The vertex contains
|
||||||
|
/// the properties defined in @FA{data}.
|
||||||
|
///
|
||||||
|
/// @EXAMPLES
|
||||||
|
///
|
||||||
|
/// Without any properties:
|
||||||
|
///
|
||||||
|
/// @verbinclude graph-graph-add-vertex
|
||||||
|
///
|
||||||
|
/// With given properties:
|
||||||
|
///
|
||||||
|
/// @verbinclude graph-graph-add-vertex2
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Graph.prototype.addVertex = function (id, data, waitForSync) {
|
||||||
|
var params;
|
||||||
|
|
||||||
|
if (data === null || typeof data !== "object") {
|
||||||
|
params = {};
|
||||||
|
} else {
|
||||||
|
params = data._shallowCopy || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._saveVertex(id, params, waitForSync);
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @}
|
/// @}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -638,7 +638,7 @@ Graph.prototype.drop = function (waitForSync) {
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief adds an edge to the graph
|
/// @brief saves an edge to the graph
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, shallow, waitForSync) {
|
Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, shallow, waitForSync) {
|
||||||
|
@ -654,41 +654,13 @@ Graph.prototype._saveEdge = function(id, out_vertex, in_vertex, shallow, waitFor
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief adds a vertex to the graph
|
/// @brief saves a vertex to the graph
|
||||||
///
|
|
||||||
/// @FUN{@FA{graph}.addVertex(@FA{id})}
|
|
||||||
///
|
|
||||||
/// Creates a new vertex and returns the vertex object. The identifier
|
|
||||||
/// @FA{id} must be a unique identifier or null.
|
|
||||||
///
|
|
||||||
/// @FUN{@FA{graph}.addVertex(@FA{id}, @FA{data})}
|
|
||||||
///
|
|
||||||
/// Creates a new vertex and returns the vertex object. The vertex contains
|
|
||||||
/// the properties defined in @FA{data}.
|
|
||||||
///
|
|
||||||
/// @EXAMPLES
|
|
||||||
///
|
|
||||||
/// Without any properties:
|
|
||||||
///
|
|
||||||
/// @verbinclude graph-graph-add-vertex
|
|
||||||
///
|
|
||||||
/// With given properties:
|
|
||||||
///
|
|
||||||
/// @verbinclude graph-graph-add-vertex2
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Graph.prototype.addVertex = function (id, data, waitForSync) {
|
Graph.prototype._saveVertex = function (id, shallow, waitForSync) {
|
||||||
var ref;
|
var ref;
|
||||||
var shallow;
|
|
||||||
|
|
||||||
if (data === null || typeof data !== "object") {
|
if (is.existy(id)) {
|
||||||
shallow = {};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
shallow = data._shallowCopy || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id !== undefined && id !== null) {
|
|
||||||
shallow._key = String(id);
|
shallow._key = String(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue