Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: triAGENS/AvocadoDB
base: 97abd519db
...
head fork: triAGENS/AvocadoDB
compare: 0c1e24769d
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
7 BasicsC/errors.dat
@@ -159,6 +159,7 @@ ERROR_KEYVALUE_KEY_NOT_FOUND,1802,"key not found","Will be raised when the speci
ERROR_KEYVALUE_KEY_NOT_UNIQUE,1803,"key is not unique","Will be raised when the specified key is not unique"
ERROR_KEYVALUE_KEY_NOT_CHANGED,1804,"key value not changed","Will be raised when updating the value for a key does not work"
ERROR_KEYVALUE_KEY_NOT_REMOVED,1805,"key value not removed","Will be raised when deleting a key/value pair does not work"
+ERROR_KEYVALUE_NO_VALUE,1806,"missing value","Will be raised when the value is missing"
################################################################################
## Graph errors
@@ -168,8 +169,10 @@ ERROR_GRAPH_INVALID_GRAPH,1901,"invalid graph","Will be raised when an invalid n
ERROR_GRAPH_COULD_NOT_CREATE_GRAPH,1902,"could not create graph","Will be raised when an invalid name, vertices or edges is passed to the server"
ERROR_GRAPH_INVALID_VERTEX,1903,"invalid vertex","Will be raised when an invalid vertex id is passed to the server"
ERROR_GRAPH_COULD_NOT_CREATE_VERTEX,1904,"could not create vertex","Will be raised when the vertex could not be created"
-ERROR_GRAPH_INVALID_EDGE,1905,"invalid edge","Will be raised when an invalid edge id is passed to the server"
-ERROR_GRAPH_COULD_NOT_CREATE_EDGE,1906,"could not create edge","Will be raised when the edge could not be created"
+ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX,1905,"could not change vertex","Will be raised when the vertex could not be changed"
+ERROR_GRAPH_INVALID_EDGE,1906,"invalid edge","Will be raised when an invalid edge id is passed to the server"
+ERROR_GRAPH_COULD_NOT_CREATE_EDGE,1907,"could not create edge","Will be raised when the edge could not be created"
+ERROR_GRAPH_COULD_NOT_CHANGE_EDGE,1908,"could not change edge","Will be raised when the edge could not be changed"
################################################################################
## Simple Client
View
1  BasicsC/voc-errors.c
@@ -110,6 +110,7 @@ void TRI_InitialiseErrorMessages (void) {
REG_ERROR(ERROR_KEYVALUE_KEY_NOT_UNIQUE, "key is not unique");
REG_ERROR(ERROR_KEYVALUE_KEY_NOT_CHANGED, "key value not changed");
REG_ERROR(ERROR_KEYVALUE_KEY_NOT_REMOVED, "key value not removed");
+ REG_ERROR(ERROR_KEYVALUE_NO_VALUE, "missing value");
REG_ERROR(ERROR_GRAPH_INVALID_GRAPH, "invalid graph");
REG_ERROR(ERROR_GRAPH_COULD_NOT_CREATE_GRAPH, "could not create graph");
REG_ERROR(ERROR_GRAPH_INVALID_VERTEX, "invalid vertex");
View
12 BasicsC/voc-errors.h
@@ -238,6 +238,8 @@ extern "C" {
/// Will be raised when updating the value for a key does not work
/// - 1805: @CODE{key value not removed}
/// Will be raised when deleting a key/value pair does not work
+/// - 1806: @CODE{missing value}
+/// Will be raised when the value is missing
/// - 1901: @CODE{invalid graph}
/// Will be raised when an invalid name is passed to the server
/// - 1902: @CODE{could not create graph}
@@ -1301,6 +1303,16 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_KEYVALUE_KEY_NOT_REMOVED (1805)
////////////////////////////////////////////////////////////////////////////////
+/// @brief 1806: ERROR_KEYVALUE_NO_VALUE
+///
+/// missing value
+///
+/// Will be raised when the value is missing
+////////////////////////////////////////////////////////////////////////////////
+
+#define TRI_ERROR_KEYVALUE_NO_VALUE (1806)
+
+////////////////////////////////////////////////////////////////////////////////
/// @brief 1901: ERROR_GRAPH_INVALID_GRAPH
///
/// invalid graph
View
12 js/actions/system/api-blueprint.js
@@ -332,7 +332,7 @@ function deleteVertex(req, res) {
function putVertex(req, res) {
if (req.suffix.length < 1) {
- actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, "vertex not found");
+ actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, "vertex not found");
return;
}
@@ -358,7 +358,7 @@ function putVertex(req, res) {
var json = JSON.parse(req.requestBody);
if (!json || !(json instanceof Object)) {
- actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_VERTEX, "missing request body");
+ actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, "missing request body");
return;
}
@@ -371,7 +371,7 @@ function putVertex(req, res) {
actions.resultOk(req, res, actions.HTTP_OK, { "vertex" : result} );
}
catch (err) {
- actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_VERTEX, err);
+ actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX, err);
}
}
@@ -614,7 +614,7 @@ function deleteEdge(req, res) {
function putEdge(req, res) {
if (req.suffix.length < 1) {
- actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, "edge not found");
+ actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, "edge not found");
return;
}
@@ -640,7 +640,7 @@ function putEdge(req, res) {
var json = JSON.parse(req.requestBody);
if (!json || !(json instanceof Object)) {
- actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CREATE_EDGE, "missing request body");
+ actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, "missing request body");
return;
}
@@ -654,7 +654,7 @@ function putEdge(req, res) {
actions.resultOk(req, res, actions.HTTP_OK, { "edge" : result} );
}
catch (err) {
- actions.resultBad(req, res, actions.ERROR_GRAPH_INVALID_EDGE, err);
+ actions.resultBad(req, res, actions.ERROR_GRAPH_COULD_NOT_CHANGE_EDGE, err);
}
}
View
113 js/actions/system/key-value.js
@@ -83,25 +83,25 @@ function buildDocumentFromReq(req) {
}
var doc = {
- "key" : key,
- "value" : req.requestBody
+ "$key" : key,
+ "$value" : req.requestBody
}
if (req.headers["x-voc-expires"] != undefined) {
var d = new Date(req.headers["x-voc-expires"]);
// store time stamp as double
- doc["x-voc-expires"] = d.getTime() / 1000;
+ doc["$expires"] = d.getTime() / 1000;
}
if (req.headers["x-voc-extended"] != undefined) {
var json = JSON.parse(req.headers["x-voc-extended"]);
if (json != undefined) {
- doc["x-voc-extended"] = json;
+ doc["$extended"] = json;
}
}
// store time stamp as double
- doc["x-voc-created"] = internal.time();
+ doc["$created"] = internal.time();
return doc;
}
@@ -109,6 +109,11 @@ function buildDocumentFromReq(req) {
////////////////////////////////////////////////////////////////////////////////
/// @brief create a key value pair
+///
+/// @REST{POST /_api/key/@FA{collection-name}/@FA{key}}
+/// {data}
+///
+/// headers "x-voc-expires" and "x-voc-extended"
////////////////////////////////////////////////////////////////////////////////
function postKeyValue(req, res) {
@@ -124,14 +129,18 @@ function postKeyValue(req, res) {
actions.collectionNotFound(req, res, collection);
return;
}
-
+
+ if (req.requestBody == "") {
+ actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_NO_VALUE, actions.getErrorMessage(actions.ERROR_KEYVALUE_NO_VALUE));
+ return;
+ }
+
var doc = buildDocumentFromReq(req);
- var s = db[collection].byExample({"key" : doc.key});
- s.execute();
+ var oldDoc = internal.db._collection(collection).firstExample("$key", doc["$key"]);
- if (s._countTotal != 0) {
- actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_EXISTS, actions.getMessage(actions.ERROR_KEYVALUE_KEY_EXISTS));
+ if (oldDoc != undefined) {
+ actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_EXISTS, actions.getErrorMessage(actions.ERROR_KEYVALUE_KEY_EXISTS));
}
else {
var id = db[collection].save(doc);
@@ -149,6 +158,10 @@ function postKeyValue(req, res) {
////////////////////////////////////////////////////////////////////////////////
/// @brief update the value of a key value pair
+///
+/// @REST{PUT /_api/key/@FA{collection-name}/@FA{key}}
+/// {data}
+///
////////////////////////////////////////////////////////////////////////////////
function putKeyValue(req, res) {
@@ -167,10 +180,9 @@ function putKeyValue(req, res) {
var doc = buildDocumentFromReq(req);
- var s = db[collection].byExample({"key" : doc.key});
- s.execute();
+ var oldDoc = internal.db._collection(collection).firstExample("$key", doc["$key"]);
- if (s._countTotal < 1) {
+ if (oldDoc == undefined) {
if (req.parameters["create"] == 1) {
var id = db[collection].save(doc);
var result = {
@@ -180,17 +192,14 @@ function putKeyValue(req, res) {
actions.resultOk(req, res, actions.HTTP_CREATED, result);
return;
}
- actions.resultError(req, res, actions.HTTP_NOT_FOUND, actions.ERROR_KEYVALUE_KEY_NOT_FOUND, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_FOUND));
- }
- else if (s._countTotal > 1) {
- actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_UNIQUE, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_UNIQUE));
+ actions.resultError(req, res, actions.HTTP_NOT_FOUND, actions.ERROR_KEYVALUE_KEY_NOT_FOUND, actions.getErrorMessage(actions.ERROR_KEYVALUE_KEY_NOT_FOUND));
}
else {
// get _id
- var id = s._execution._documents[0]._id;
+ var id = oldDoc._id;
// save x-voc-created
- var created = s._execution._documents[0]["x-voc-created"];
+ var created = oldDoc["$created"];
if (created != undefined) {
doc["x-voc-created"] = created;
}
@@ -200,7 +209,7 @@ function putKeyValue(req, res) {
actions.resultOk(req, res, actions.HTTP_ACCEPTED, {"changed" : true});
}
else {
- actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_CHANGED, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_CHANGED));
+ actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_CHANGED, actions.getErrorMessage(actions.ERROR_KEYVALUE_KEY_NOT_CHANGED));
}
}
}
@@ -211,6 +220,9 @@ function putKeyValue(req, res) {
////////////////////////////////////////////////////////////////////////////////
/// @brief delete an existing key value pair
+///
+/// @REST{DELETE /_api/key/@FA{collection-name}/@FA{key}}
+///
////////////////////////////////////////////////////////////////////////////////
function deleteKeyValue(req, res) {
@@ -233,22 +245,18 @@ function deleteKeyValue(req, res) {
key += "/" + req.suffix[i];
}
- var s = db[collection].byExample({"key" : key});
- s.execute();
+ var doc = internal.db._collection(collection).firstExample("$key", key);
- if (s._countTotal < 1) {
- actions.resultError(req, res, actions.HTTP_NOT_FOUND, actions.ERROR_KEYVALUE_KEY_NOT_FOUND, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_FOUND));
- }
- else if (s._countTotal > 1) {
- actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_UNIQUE, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_UNIQUE));
+ if (doc == undefined) {
+ actions.resultError(req, res, actions.HTTP_NOT_FOUND, actions.ERROR_KEYVALUE_KEY_NOT_FOUND, actions.getErrorMessage(actions.ERROR_KEYVALUE_KEY_NOT_FOUND));
}
else {
- var id = s._execution._documents[0]._id;
+ var id = doc._id;
if (db[collection].remove(id)) {
actions.resultOk(req, res, actions.HTTP_ACCEPTED, {"removed" : true});
}
else {
- actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_REMOVED, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_REMOVED));
+ actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_REMOVED, actions.getErrorMessage(actions.ERROR_KEYVALUE_KEY_NOT_REMOVED));
}
}
}
@@ -259,6 +267,11 @@ function deleteKeyValue(req, res) {
////////////////////////////////////////////////////////////////////////////////
/// @brief return an existing key value pair
+///
+/// @REST{GET /_api/key/@FA{collection-name}/@FA{key}}
+///
+/// returned headers: "x-voc-expires", "x-voc-extended" and "x-voc-created"
+///
////////////////////////////////////////////////////////////////////////////////
function getKeyValue(req, res) {
@@ -281,32 +294,28 @@ function getKeyValue(req, res) {
key += "/" + req.suffix[i];
}
- var s = db[collection].byExample({"key" : key});
- s.execute();
-
- if (s._countTotal < 1) {
- actions.resultError(req, res, actions.HTTP_NOT_FOUND, actions.ERROR_KEYVALUE_KEY_NOT_FOUND, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_FOUND));
- }
- else if (s._countTotal > 1) {
- actions.resultError(req, res, actions.HTTP_BAD, actions.ERROR_KEYVALUE_KEY_NOT_UNIQUE, actions.getMessage(actions.ERROR_KEYVALUE_KEY_NOT_UNIQUE));
+ var doc = internal.db._collection(collection).firstExample("$key", key);
+
+ if (doc == undefined) {
+ actions.resultError(req, res, actions.HTTP_NOT_FOUND, actions.ERROR_KEYVALUE_KEY_NOT_FOUND, actions.getErrorMessage(actions.ERROR_KEYVALUE_KEY_NOT_FOUND));
}
else {
var headers = {};
- if (s._execution._documents[0]["x-voc-expires"] != undefined) {
+ if (doc["$expires"] != undefined) {
// format timestamp
- headers["x-voc-expires"] = formatTimeStamp(s._execution._documents[0]["x-voc-expires"]);
+ headers["x-voc-expires"] = formatTimeStamp(doc["$expires"]);
}
- if (s._execution._documents[0]["x-voc-extended"] != undefined) {
+ if (doc["$extended"] != undefined) {
// serialize header value
- headers["x-voc-extended"] = JSON.stringify(s._execution._documents[0]["x-voc-extended"]);
+ headers["x-voc-extended"] = JSON.stringify(doc["$extended"]);
}
- if (s._execution._documents[0]["x-voc-created"] != undefined) {
+ if (doc["$created"] != undefined) {
// format timestamp
- headers["x-voc-created"] = formatTimeStamp(s._execution._documents[0]["x-voc-created"]);
+ headers["x-voc-created"] = formatTimeStamp(doc["$created"]);
}
- actions.resultOk(req, res, actions.HTTP_OK, s._execution._documents[0].value, headers);
+ actions.resultOk(req, res, actions.HTTP_OK, doc["$value"], headers);
}
}
catch (err) {
@@ -366,6 +375,9 @@ actions.defineHttp({
////////////////////////////////////////////////////////////////////////////////
/// @brief key value pair search
+///
+/// @REST{GET /_api/keys/@FA{collection-name}/@FA{key-prefix}}
+///
////////////////////////////////////////////////////////////////////////////////
function searchKeyValue(req, res) {
@@ -392,17 +404,14 @@ function searchKeyValue(req, res) {
// TODO: build a query which selects the keys
//
- var query = "select f from `" + collection + "` f ";
- var bindVars = {};
- var cursor = AQL_STATEMENT(query,
- bindVars,
- false,
- 1000);
+ var cursor = internal.db._collection(collection).all()
+
result = [];
+
while (cursor.hasNext() ) {
var doc = cursor.next();
- if (doc["key"] != undefined && doc["key"].indexOf(prefix) === 0) {
- result.push(doc["key"]);
+ if (doc["$key"] != undefined && doc["$key"].indexOf(prefix) === 0) {
+ result.push(doc["$key"]);
}
}
View
1  js/common/bootstrap/errors.js
@@ -104,6 +104,7 @@ ModuleCache["/internal"].exports.errors = {
"ERROR_KEYVALUE_KEY_NOT_UNIQUE" : { "code" : 1803, "message" : "key is not unique" },
"ERROR_KEYVALUE_KEY_NOT_CHANGED" : { "code" : 1804, "message" : "key value not changed" },
"ERROR_KEYVALUE_KEY_NOT_REMOVED" : { "code" : 1805, "message" : "key value not removed" },
+ "ERROR_KEYVALUE_NO_VALUE" : { "code" : 1806, "message" : "missing value" },
"ERROR_GRAPH_INVALID_GRAPH" : { "code" : 1901, "message" : "invalid graph" },
"ERROR_GRAPH_COULD_NOT_CREATE_GRAPH" : { "code" : 1902, "message" : "could not create graph" },
"ERROR_GRAPH_INVALID_VERTEX" : { "code" : 1903, "message" : "invalid vertex" },
View
1  js/common/bootstrap/js-errors.h
@@ -105,6 +105,7 @@ static string JS_common_bootstrap_errors =
" \"ERROR_KEYVALUE_KEY_NOT_UNIQUE\" : { \"code\" : 1803, \"message\" : \"key is not unique\" }, \n"
" \"ERROR_KEYVALUE_KEY_NOT_CHANGED\" : { \"code\" : 1804, \"message\" : \"key value not changed\" }, \n"
" \"ERROR_KEYVALUE_KEY_NOT_REMOVED\" : { \"code\" : 1805, \"message\" : \"key value not removed\" }, \n"
+ " \"ERROR_KEYVALUE_NO_VALUE\" : { \"code\" : 1806, \"message\" : \"missing value\" }, \n"
" \"ERROR_GRAPH_INVALID_GRAPH\" : { \"code\" : 1901, \"message\" : \"invalid graph\" }, \n"
" \"ERROR_GRAPH_COULD_NOT_CREATE_GRAPH\" : { \"code\" : 1902, \"message\" : \"could not create graph\" }, \n"
" \"ERROR_GRAPH_INVALID_VERTEX\" : { \"code\" : 1903, \"message\" : \"invalid vertex\" }, \n"

No commit comments for this range

Something went wrong with that request. Please try again.