static string JS_client_client = "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief ArangoShell client API\n" "///\n" "/// @file\n" "///\n" "/// DISCLAIMER\n" "///\n" "/// Copyright 2012 triagens GmbH, Cologne, Germany\n" "///\n" "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" "/// you may not use this file except in compliance with the License.\n" "/// You may obtain a copy of the License at\n" "///\n" "/// http://www.apache.org/licenses/LICENSE-2.0\n" "///\n" "/// Unless required by applicable law or agreed to in writing, software\n" "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" "/// See the License for the specific language governing permissions and\n" "/// limitations under the License.\n" "///\n" "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" "///\n" "/// @author Achim Brandt\n" "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- global variables\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief default collection for saving queries\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "var DEFAULT_QUERY_COLLECTION = \"query\";\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help texts\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "var HELP = \"\";\n" "var helpQueries = \"\";\n" "var helpArangoDatabase = \"\";\n" "var helpArangoCollection = \"\";\n" "var helpArangoQueryCursor = \"\";\n" "var helpArangoStoredStatement = \"\";\n" "var helpArangoStatement = \"\";\n" "var helpExtended = \"\";\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a formatted type string for object\n" "/// \n" "/// If the object has an id, it will be included in the string.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function TRI_GetIdString (object, typeName) {\n" " var result = \"[object \" + typeName;\n" " \n" " if (object._id) {\n" " result += \":\" + object._id;\n" " }\n" " else if (object.data && object.data._id) {\n" " result += \":\" + object.data._id;\n" " }\n" "\n" " result += \"]\";\n" "\n" " return result;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief handles error results\n" "/// \n" "/// throws an exception in case of an an error\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function TRI_CheckRequestResult (requestResult) {\n" " if (requestResult == undefined) { \n" " requestResult = {\n" " \"error\" : true,\n" " \"code\" : 0,\n" " \"errorNum\" : 0,\n" " \"errorMessage\" : \"Unknown error. Request result is empty\"\n" " } \n" " }\n" " \n" " if (requestResult[\"error\"] != undefined && requestResult[\"error\"]) { \n" " throw new ArangoError(requestResult);\n" " } \n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief create a formatted headline text \n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function TRI_CreateHelpHeadline (text) {\n" " var x = parseInt(Math.abs(78 - text.length) / 2);\n" " \n" " var p = \"\";\n" " for (var i = 0; i < x; ++i) {\n" " p += \"-\";\n" " }\n" " \n" " return \"\\n\" + p + \" \" + text + \" \" + p + \"\\n\";\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- public functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief turn off pretty printing\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function print_plain (data) {\n" " var p = PRETTY_PRINT;\n" " PRETTY_PRINT = false;\n" " var c;\n" " if (typeof(COLOR_OUTPUT) != undefined) {\n" " c = COLOR_OUTPUT;\n" " COLOR_OUTPUT = undefined;\n" " }\n" " \n" " try {\n" " print(data);\n" " PRETTY_PRINT = p;\n" " if (typeof(c) != undefined) {\n" " COLOR_OUTPUT = c;\n" " } \n" " }\n" " catch (e) {\n" " PRETTY_PRINT = p;\n" " if (typeof(c) != undefined) {\n" " COLOR_OUTPUT = c;\n" " } \n" " throw e.message; \n" " } \n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief start pretty printing\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function start_pretty_print () {\n" " print(\"use pretty printing\");\n" " PRETTY_PRINT=true;\n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief stop pretty printing\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function stop_pretty_print () {\n" " print(\"stop pretty printing\");\n" " PRETTY_PRINT=false;\n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief start pretty printing with optional color\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function start_color_print (color) {\n" " if (typeof(color) == \"string\") {\n" " COLOR_OUTPUT = color;\n" " }\n" " else {\n" " COLOR_OUTPUT = COLOR_BRIGHT;\n" " }\n" " print(\"start \" + COLOR_OUTPUT + \"color\" + COLOR_OUTPUT_RESET + \" printing\");\n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief stop pretty printing\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function stop_color_print () {\n" " print(\"stop color printing\");\n" " COLOR_OUTPUT = undefined;\n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the overall help\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function help () {\n" " print(HELP);\n" " print(helpQueries);\n" " print(helpArangoDatabase);\n" " print(helpArangoCollection);\n" " print(helpArangoStatement);\n" " print(helpArangoQueryCursor);\n" " print(helpExtended);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- Module \"internal\"\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief change internal.output to shell output\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ModuleCache[\"/internal\"].exports.output = TRI_SYS_OUTPUT;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief log function\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ModuleCache[\"/internal\"].exports.log = function(level, msg) {\n" " internal.output(level, \": \", msg, \"\\n\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief starts the pager\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ModuleCache[\"/internal\"].exports.start_pager = SYS_START_PAGER;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief stops the pager\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ModuleCache[\"/internal\"].exports.stop_pager = SYS_STOP_PAGER;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoError\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoError (error) {\n" " if (error != null) {\n" " this.error = error.error;\n" " this.code = error.code;\n" " this.errorNum = error.errorNum;\n" " this.errorMessage = error.errorMessage;\n" " }\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief prints an error\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoError.prototype._PRINT = function() {\n" " internal.output(this.toString());\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief toString function\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoError.prototype.toString = function() {\n" " var result = \"\";\n" " if (typeof(COLOR_BRIGHT) != \"undefined\") {\n" " result = COLOR_BRIGHT + \"Error: \" + COLOR_OUTPUT_RESET;\n" " }\n" " else {\n" " result = \"Error: \";\n" " }\n" "\n" " result += \"[\" + this.code + \":\" + this.errorNum + \"] \" + this.errorMessage;\n" " \n" " return result;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief prints an error\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoError.prototype.toString = function() {\n" " var errorNum = this.errorNum;\n" " var errorMessage = this.errorMessage;\n" "\n" " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoDatabase\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoDatabase (connection) {\n" " this._connection = connection;\n" " this._collectionConstructor = ArangoCollection;\n" "}\n" "\n" "ModuleCache[\"/internal\"].exports.ArangoDatabase = ArangoDatabase;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help for ArangoDatabase\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpArangoDatabase = TRI_CreateHelpHeadline(\"ArangoDatabase help\") +\n" "'ArangoDatabase constructor: ' + \"\\n\" +\n" "' > db = new ArangoDatabase(connection); ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Administration Functions: ' + \"\\n\" +\n" "' _help(); this help ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Collection Functions: ' + \"\\n\" +\n" "' _collections() list all collections ' + \"\\n\" +\n" "' _collection() get collection by identifier/name ' + \"\\n\" +\n" "' _create(, ) creates a new collection ' + \"\\n\" +\n" "' _truncate() delete all documents ' + \"\\n\" +\n" "' _drop() delete a collection ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Document Functions: ' + \"\\n\" +\n" "' _document() get document by handle ' + \"\\n\" +\n" "' _replace(, ) over-writes document ' + \"\\n\" +\n" "' _remove() deletes document ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Query Functions: ' + \"\\n\" +\n" "' _createStatement(); create and return select query ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Attributes: ' + \"\\n\" +\n" "' collection with the given name ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the help for ArangoDatabase\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._help = function () { \n" " print(helpArangoDatabase);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a string representation of the database object\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype.toString = function () { \n" " return \"[object ArangoDatabase]\";\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- collection functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return all collections from the database\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._collections = function () {\n" " var requestResult = this._connection.GET(\"/_api/collection\");\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " if (requestResult[\"collections\"] != undefined) {\n" " var collections = requestResult[\"collections\"];\n" " var result = []\n" " \n" " // add all collentions to object\n" " for (var i = 0; i < collections.length; ++i) {\n" " var collection = new this._collectionConstructor(this, collections[i]);\n" "\n" " this[collection._name] = collection;\n" " result.push(collection);\n" " }\n" " \n" " return result;\n" " }\n" " \n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a single collection, identified by its id or name\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._collection = function (id) {\n" " var requestResult = this._connection.GET(\"/_api/collection/\" + encodeURIComponent(id));\n" " \n" " // return null in case of not found\n" " if (requestResult != null\n" " && requestResult.error == true \n" " && requestResult.errorNum == internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {\n" " return null;\n" " }\n" "\n" " // check all other errors and throw them\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " var name = requestResult[\"name\"];\n" "\n" " if (name != undefined) {\n" " return this[name] = new this._collectionConstructor(this, requestResult);\n" " }\n" " \n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief creates a new collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._create = function (name, properties) {\n" " var body = {\n" " \"name\" : name\n" " };\n" "\n" " if (properties != null) {\n" " if (properties.hasOwnProperty(\"waitForSync\")) {\n" " body.waitForSync = properties.waitForSync;\n" " }\n" "\n" " if (properties.hasOwnProperty(\"journalSize\")) {\n" " body.journalSize = properties.journalSize;\n" " }\n" " }\n" "\n" " var requestResult = this._connection.POST(\"/_api/collection\", JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " var name = requestResult[\"name\"];\n" "\n" " if (name != undefined) {\n" " return this[name] = new this._collectionConstructor(this, requestResult);\n" " }\n" " \n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief truncates a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._truncate = function (id) {\n" " for (var name in this) {\n" " if (this.hasOwnProperty(name)) {\n" " var collection = this[name];\n" "\n" " if (collection instanceof this._collectionConstructor) {\n" " if (collection._id == id || collection._name == id) {\n" " return collection.truncate();\n" " }\n" " }\n" " }\n" " }\n" "\n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief drops a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._drop = function (id) {\n" " for (var name in this) {\n" " if (this.hasOwnProperty(name)) {\n" " var collection = this[name];\n" "\n" " if (collection instanceof this._collectionConstructor) {\n" " if (collection._id == id || collection._name == id) {\n" " return collection.drop();\n" " }\n" " }\n" " }\n" " }\n" "\n" " return undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns one index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._index = function (id) {\n" " if (id.hasOwnProperty(\"id\")) {\n" " id = id.id;\n" " }\n" "\n" " var requestResult = this._connection.GET(\"/_api/index/\" + id);\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief deletes one index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._dropIndex = function (id) {\n" " if (id.hasOwnProperty(\"id\")) {\n" " id = id.id;\n" " }\n" "\n" " var requestResult = this._connection.DELETE(\"/_api/index/\" + id);\n" "\n" " if (requestResult != null\n" " && requestResult.error == true \n" " && requestResult.errorNum == internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {\n" " return false;\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return true;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- document functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a single document from the collection, identified by its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._document = function (id) {\n" " var rev = null;\n" " var requestResult;\n" "\n" " if (id.hasOwnProperty(\"_id\")) {\n" " if (id.hasOwnProperty(\"_rev\")) {\n" " rev = id._rev;\n" " }\n" "\n" " id = id._id;\n" " }\n" "\n" " if (rev == null) {\n" " requestResult = this._connection.GET(\"/document/\" + id);\n" " }\n" " else {\n" " requestResult = this._connection.GET(\"/document/\" + id, {'if-match' : '\"' + rev + '\"' });\n" " }\n" "\n" " if (requestResult != null\n" " && requestResult.error == true \n" " && requestResult.errorNum == internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief delete a document in the collection, identified by its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._remove = function (id, overwrite) {\n" " var rev = null;\n" " var requestResult;\n" "\n" " if (id.hasOwnProperty(\"_id\")) {\n" " if (id.hasOwnProperty(\"_rev\")) {\n" " rev = id._rev;\n" " }\n" "\n" " id = id._id;\n" " }\n" "\n" " var policy = \"\";\n" "\n" " if (overwrite) {\n" " policy = \"?policy=last\";\n" " }\n" "\n" " if (rev == null) {\n" " requestResult = this._connection.DELETE(\"/document/\" + id + policy);\n" " }\n" " else {\n" " requestResult = this._connection.DELETE(\"/document/\" + id + policy, {'if-match' : '\"' + rev + '\"' });\n" " }\n" "\n" " if (requestResult != null && requestResult.error == true) {\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" " }\n" "\n" " if (overwrite) {\n" " if (requestResult.errorNum == internal.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code) {\n" " return false;\n" " }\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return true;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief update a document in the collection, identified by its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._replace = function (id, data, overwrite) { \n" " var rev = null;\n" " var requestResult;\n" "\n" " if (id.hasOwnProperty(\"_id\")) {\n" " if (id.hasOwnProperty(\"_rev\")) {\n" " rev = id._rev;\n" " }\n" "\n" " id = id._id;\n" " }\n" "\n" " var policy = \"\";\n" "\n" " if (overwrite) {\n" " policy = \"?policy=last\";\n" " }\n" "\n" " if (rev == null) {\n" " requestResult = this._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data));\n" " }\n" " else {\n" " requestResult = this._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data), {'if-match' : '\"' + rev + '\"' });\n" " }\n" "\n" " if (requestResult != null && requestResult.error == true) {\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- query functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief factory method to create a new statement\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoDatabase.prototype._createStatement = function (data) { \n" " return new ArangoStatement(this, data);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoEdges\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoEdges (connection) {\n" " this._connection = connection;\n" " this._collectionConstructor = ArangoEdgesCollection;\n" "}\n" "\n" "ArangoEdges.prototype = new ArangoDatabase();\n" "\n" "ModuleCache[\"/internal\"].exports.ArangoEdges = ArangoEdges;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help for ArangoEdges\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpArangoEdges = TRI_CreateHelpHeadline(\"ArangoEdges help\") +\n" "'ArangoEdges constructor: ' + \"\\n\" +\n" "' > edges = new ArangoEdges(connection); ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Administration Functions: ' + \"\\n\" +\n" "' _help(); this help ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Attributes: ' + \"\\n\" +\n" "' collection with the given name ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the help for ArangoEdges\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdges.prototype._help = function () { \n" " print(helpArangoEdges);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a string representation of the database object\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdges.prototype.toString = function () { \n" " return \"[object ArangoEdges]\";\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoCollection\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoCollection (database, data) {\n" " this._database = database;\n" "\n" " if (typeof data === \"string\") {\n" " this._name = data;\n" " }\n" " else if (data != null) {\n" " this._id = data.id;\n" " this._name = data.name;\n" " this._status = data.status;\n" " }\n" "}\n" "\n" "ModuleCache[\"/internal\"].exports.ArangoCollection = ArangoCollection;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constants\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief collection is corrupted\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.STATUS_CORRUPTED = 0;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief collection is new born\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.STATUS_NEW_BORN = 1;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief collection is unloaded\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.STATUS_UNLOADED = 2;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief collection is loaded\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.STATUS_LOADED = 3;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief collection is unloading\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.STATUS_UNLOADING = 4;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief collection is deleted\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.STATUS_DELETED = 5;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help for ArangoCollection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpArangoCollection = TRI_CreateHelpHeadline(\"ArangoCollection help\") +\n" "'ArangoCollection constructor: ' + \"\\n\" +\n" "' > col = db.mycoll; ' + \"\\n\" +\n" "' > col = db._create(\"mycoll\"); ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Administration Functions: ' + \"\\n\" +\n" "' name() collection name ' + \"\\n\" +\n" "' status() status of the collection ' + \"\\n\" +\n" "' truncate() delete all documents ' + \"\\n\" +\n" "' properties() show collection properties ' + \"\\n\" +\n" "' drop() delete a collection ' + \"\\n\" +\n" "' load() load a collection into memeory ' + \"\\n\" +\n" "' unload() unload a collection from memory ' + \"\\n\" +\n" "' rename(new-name) renames a collection ' + \"\\n\" +\n" "' refresh() refreshes the status and name ' + \"\\n\" +\n" "' _help(); this help ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Document Functions: ' + \"\\n\" +\n" "' count() number of documents ' + \"\\n\" +\n" "' save() create document and return handle ' + \"\\n\" +\n" "' document() get document by handle ' + \"\\n\" +\n" "' replace(, ) over-writes document ' + \"\\n\" +\n" "' delete() deletes document ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Attributes: ' + \"\\n\" +\n" "' _database database object ' + \"\\n\" +\n" "' _id collection identifier ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a string representation of the collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.toString = function () { \n" " return TRI_GetIdString(this, \"ArangoCollection\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief prints the collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype._PRINT = function () { \n" " var status = \"unknown\";\n" "\n" " switch (this.status()) {\n" " case ArangoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n" " case ArangoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n" " case ArangoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n" " case ArangoCollection.STATUS_LOADED: status = \"loaded\"; break;\n" " case ArangoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n" " case ArangoCollection.STATUS_DELETED: status = \"deleted\"; break;\n" " }\n" " \n" " internal.output(\"[ArangoCollection \", this._id, \", \\\"\", this.name(), \"\\\" (status \" + status + \")]\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the help for ArangoCollection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype._help = function () { \n" " print(helpArangoCollection);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- public functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns the name of a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.name = function () {\n" " if (this._name == null) {\n" " this.refresh();\n" " }\n" "\n" " return this._name;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns the status of a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.status = function () {\n" " if (this._status == null) {\n" " this.refresh();\n" " }\n" "\n" " return this._status;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief gets or sets the properties of a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.properties = function (properties) {\n" " var requestResult;\n" "\n" " if (properties == null) {\n" " requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" " }\n" " else {\n" " var body = {};\n" "\n" " if (properties.hasOwnProperty(\"waitForSync\")) {\n" " body.waitForSync = properties.waitForSync;\n" " }\n" "\n" " requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\", JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" " }\n" "\n" " return { \n" " waitForSync : requestResult.waitForSync,\n" " journalSize : requestResult.journalSize\n" " };\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief gets the figures of a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.figures = function () {\n" " var requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/figures\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult.figures;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief drops a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.drop = function () {\n" " var requestResult = this._database._connection.DELETE(\"/_api/collection/\" + encodeURIComponent(this._id));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " this._status = ArangoCollection.STATUS_DELETED;\n" "\n" " var database = this._database;\n" "\n" " for (var name in database) {\n" " if (database.hasOwnProperty(name)) {\n" " var collection = database[name];\n" "\n" " if (collection instanceof ArangoCollection) {\n" " if (collection._id == this._id) {\n" " delete database[name];\n" " }\n" " }\n" " }\n" " }\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns all documents\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.toArray = function () {\n" " return this.all().toArray();\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns all indexes\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.getIndexes = function () {\n" " var requestResult = this._database._connection.GET(\"/_api/index?collection=\" + encodeURIComponent(this._id));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult.indexes;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns one index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.index = function (id) {\n" " if (id.hasOwnProperty(\"id\")) {\n" " id = id.id;\n" " }\n" "\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " var requestResult = {\n" " errorNum: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code,\n" " errorMessage: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" " else if (s[0] != this._id) {\n" " var requestResult = {\n" " errorNum: internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code,\n" " errorMessage: internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.message\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " var requestResult = this._database._connection.GET(\"/_api/index/\" + id);\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief deletes one index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.dropIndex = function (id) {\n" " if (id.hasOwnProperty(\"id\")) {\n" " id = id.id;\n" " }\n" "\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " var requestResult = {\n" " errorNum: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code,\n" " errorMessage: internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" " else if (s[0] != this._id) {\n" " var requestResult = {\n" " errorNum: internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code,\n" " errorMessage: internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.message\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " var requestResult = this._database._connection.DELETE(\"/_api/index/\" + id);\n" "\n" " if (requestResult != null\n" " && requestResult.error == true \n" " && requestResult.errorNum == internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {\n" " return false;\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return true;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief adds a cap constraint\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.ensureCapConstraint = function (size) {\n" " var body;\n" "\n" " body = { type : \"cap\", size : size };\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief adds a unique constraint\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.ensureUniqueConstraint = function () {\n" " var body;\n" " var fields = [];\n" " \n" " for (var i = 0; i < arguments.length; ++i) {\n" " fields.push(arguments[i]);\n" " }\n" "\n" " body = { type : \"hash\", unique : true, fields : fields };\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief adds a hash index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.ensureHashIndex = function () {\n" " var body;\n" " var fields = [];\n" " \n" " for (var i = 0; i < arguments.length; ++i) {\n" " fields.push(arguments[i]);\n" " }\n" "\n" " body = { type : \"hash\", unique : false, fields : fields };\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief queries by example\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.BY_EXAMPLE_HASH = function (index, example, skip, limit) {\n" " var body;\n" "\n" " limit = limit || null;\n" " skip = skip || null;\n" "\n" " if (index.hasOwnProperty(\"id\")) {\n" " index = index.id;\n" " }\n" "\n" " body = { collection : this._id, index : index, skip : skip, limit : limit, example : {} };\n" "\n" " for (var key in example) {\n" " if (example.hasOwnProperty(key)) {\n" " body.example[key] = example[key];\n" " }\n" " }\n" "\n" " var requestResult = this._database._connection.PUT(\"/_api/simple/BY-EXAMPLE-HASH\", JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief adds an geo index\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.ensureGeoIndex = function (lat, lon) {\n" " var body;\n" "\n" " if (typeof lon == \"boolean\") {\n" " body = { type : \"geo\", fields : [ lat ], geoJson : lon, constraint : false };\n" " }\n" " else if (lon == undefined) {\n" " body = { type : \"geo\", fields : [ lat ], geoJson : false, constraint : false };\n" " }\n" " else {\n" " body = { type : \"geo\", fields : [ lat, lon ], constraint : false };\n" " }\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief adds an geo constraint\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.ensureGeoConstraint = function (lat, lon, ignoreNull) {\n" " var body;\n" "\n" " // only two parameter\n" " if (ignoreNull == undefined) {\n" " ignoreNull = lon;\n" "\n" " if (typeof ignoreNull != \"boolean\") {\n" " throw \"usage: ensureGeoConstraint(, , ) or ensureGeoConstraint(, , )\";\n" " }\n" "\n" " body = { type : \"geo\", fields : [ lat ], geoJson : false, constraint : true, ignoreNull : ignoreNull };\n" " }\n" "\n" " // three parameter\n" " else {\n" " if (typeof lon == \"boolean\") {\n" " body = { type : \"geo\", fields : [ lat ], geoJson : lon, constraint : true, ignoreNull : ignoreNull };\n" " }\n" " else {\n" " body = { type : \"geo\", fields : [ lat, lon ], constraint : true, ignoreNull : ignoreNull };\n" " }\n" " }\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/index?collection=\" + encodeURIComponent(this._id), JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief truncates a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.truncate = function () {\n" " var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/truncate\", \"\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " this._status = null;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief loads a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.load = function () {\n" " var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/load\", \"\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " this._status = null;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief unloads a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.unload = function () {\n" " var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/unload\", \"\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " this._status = null;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief renames a collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.rename = function (name) {\n" " var body = { name : name };\n" " var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/rename\", JSON.stringify(body));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " delete this._database[this._name];\n" " this._database[name] = this;\n" "\n" " this._status = null;\n" " this._name = null;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief refreshes a collection status and name\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.refresh = function () {\n" " var requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id));\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " this._name = requestResult['name'];\n" " this._status = requestResult['status'];\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- document functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns the number of documents\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.count = function () {\n" " var requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/count\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult[\"count\"];\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a single document from the collection, identified by its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.document = function (id) {\n" " var rev = null;\n" " var requestResult;\n" "\n" " if (id.hasOwnProperty(\"_id\")) {\n" " if (id.hasOwnProperty(\"_rev\")) {\n" " rev = id._rev;\n" " }\n" "\n" " id = id._id;\n" " }\n" "\n" " if (rev == null) {\n" " requestResult = this._database._connection.GET(\"/document/\" + id);\n" " }\n" " else {\n" " requestResult = this._database._connection.GET(\"/document/\" + id, {'if-match' : '\"' + rev + '\"' });\n" " }\n" "\n" " if (requestResult != null\n" " && requestResult.error == true \n" " && requestResult.errorNum == internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" " }\n" " else if (s[0] != this._id) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief save a document in the collection, return its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.save = function (data) { \n" " var requestResult = this._database._connection.POST(\"/document?collection=\" + encodeURIComponent(this._id), JSON.stringify(data));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief delete a document in the collection, identified by its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.remove = function (id, overwrite) {\n" " var rev = null;\n" " var requestResult;\n" "\n" " if (id.hasOwnProperty(\"_id\")) {\n" " if (id.hasOwnProperty(\"_rev\")) {\n" " rev = id._rev;\n" " }\n" "\n" " id = id._id;\n" " }\n" "\n" " var policy = \"\";\n" "\n" " if (overwrite) {\n" " policy = \"?policy=last\";\n" " }\n" "\n" " if (rev == null) {\n" " requestResult = this._database._connection.DELETE(\"/document/\" + id + policy);\n" " }\n" " else {\n" " requestResult = this._database._connection.DELETE(\"/document/\" + id + policy, {'if-match' : '\"' + rev + '\"' });\n" " }\n" "\n" " if (requestResult != null && requestResult.error == true) {\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" " }\n" " else if (s[0] != this._id) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" " }\n" "\n" " if (overwrite) {\n" " if (requestResult.errorNum == internal.errors.ERROR_ARANGO_DOCUMENT_NOT_FOUND.code) {\n" " return false;\n" " }\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return true;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief update a document in the collection, identified by its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoCollection.prototype.replace = function (id, data, overwrite) { \n" " var rev = null;\n" " var requestResult;\n" "\n" " if (id.hasOwnProperty(\"_id\")) {\n" " if (id.hasOwnProperty(\"_rev\")) {\n" " rev = id._rev;\n" " }\n" "\n" " id = id._id;\n" " }\n" "\n" " var policy = \"\";\n" "\n" " if (overwrite) {\n" " policy = \"?policy=last\";\n" " }\n" "\n" " if (rev == null) {\n" " requestResult = this._database._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data));\n" " }\n" " else {\n" " requestResult = this._database._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data), {'if-match' : '\"' + rev + '\"' });\n" " }\n" "\n" " if (requestResult != null && requestResult.error == true) {\n" " var s = id.split(\"/\");\n" "\n" " if (s.length != 2) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_DOCUMENT_HANDLE_BAD.code;\n" " }\n" " else if (s[0] != this._id) {\n" " requestResult.errorNum = internal.errors.ERROR_ARANGO_CROSS_COLLECTION_REQUEST.code;\n" " }\n" "\n" " throw new ArangoError(requestResult);\n" " }\n" "\n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoEdgesCollection\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoEdgesCollection (database, data) {\n" " this._database = database;\n" "\n" " if (typeof data === \"string\") {\n" " this._name = data;\n" " }\n" " else {\n" " this._id = data.id;\n" " this._name = data.name;\n" " this._status = data.status;\n" " }\n" "}\n" "\n" "ArangoEdgesCollection.prototype = new ArangoCollection();\n" "\n" "ModuleCache[\"/internal\"].exports.ArangoEdgesCollection = ArangoEdgesCollection;\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help for ArangoCollection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpArangoEdgesCollection = TRI_CreateHelpHeadline(\"ArangoEdgesCollection help\") +\n" "'ArangoEdgesCollection constructor: ' + \"\\n\" +\n" "' > col = edges.mycoll; ' + \"\\n\" +\n" "' > col = db._create(\"mycoll\"); ' + \"\\n\" +\n" "' ' + \"\\n\" +\n" "'Attributes: ' + \"\\n\" +\n" "' _database database object ' + \"\\n\" +\n" "' _id collection identifier ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a string representation of the collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype.toString = function () { \n" " return TRI_GetIdString(this, \"ArangoEdgesCollection\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief prints the collection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype._PRINT = function () { \n" " var status = \"unknown\";\n" "\n" " switch (this.status()) {\n" " case ArangoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n" " case ArangoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n" " case ArangoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n" " case ArangoCollection.STATUS_LOADED: status = \"loaded\"; break;\n" " case ArangoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n" " case ArangoCollection.STATUS_DELETED: status = \"deleted\"; break;\n" " }\n" " \n" " internal.output(\"[ArangoEdgesCollection \", this._id, \", \\\"\", this.name(), \"\\\" (status \" + status + \")]\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the help for ArangoCollection\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype._help = function () { \n" " print(helpArangoEdgesCollection);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- document functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief save a document in the collection, return its id\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype.save = function (from, to, data) { \n" " if (from.hasOwnProperty(\"_id\")) {\n" " from = from._id;\n" " }\n" "\n" " if (to.hasOwnProperty(\"_id\")) {\n" " to = to._id;\n" " }\n" "\n" " var url = \"/edge?collection=\" + encodeURIComponent(this._id)\n" " + \"&from=\" + encodeURIComponent(from)\n" " + \"&to=\" + encodeURIComponent(to);\n" "\n" " var requestResult = this._database._connection.POST(url, JSON.stringify(data));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns the edges starting or ending in a vertex\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype.edges = function (vertex) {\n" "\n" " // if vertex is a list, iterator and concat\n" " if (vertex instanceof Array) {\n" " var edges = [];\n" "\n" " for (var i = 0; i < vertex.length; ++i) {\n" " var e = this.edges(vertex[i]);\n" " \n" " edges.push.apply(edges, e);\n" " }\n" "\n" " return edges;\n" " }\n" "\n" " if (vertex.hasOwnProperty(\"_id\")) {\n" " vertex = vertex._id;\n" " }\n" "\n" " // get the edges\n" " requestResult = this._database._connection.GET(\"/edges/\" + encodeURIComponent(this._id) + \"?vertex=\" + encodeURIComponent(vertex));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult['edges'];\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns the edges ending in a vertex\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype.inEdges = function (vertex) {\n" "\n" " // if vertex is a list, iterator and concat\n" " if (vertex instanceof Array) {\n" " var edges = [];\n" "\n" " for (var i = 0; i < vertex.length; ++i) {\n" " var e = this.inEdges(vertex[i]);\n" " \n" " edges.push.apply(edges, e);\n" " }\n" "\n" " return edges;\n" " }\n" "\n" " if (vertex.hasOwnProperty(\"_id\")) {\n" " vertex = vertex._id;\n" " }\n" "\n" " // get the edges\n" " requestResult = this._database._connection.GET(\"/edges/\" + encodeURIComponent(this._id) + \"?direction=in&vertex=\" + encodeURIComponent(vertex));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult['edges'];\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief returns the edges starting in a vertex\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoEdgesCollection.prototype.outEdges = function (vertex) {\n" "\n" " // if vertex is a list, iterator and concat\n" " if (vertex instanceof Array) {\n" " var edges = [];\n" "\n" " for (var i = 0; i < vertex.length; ++i) {\n" " var e = this.outEdges(vertex[i]);\n" " \n" " edges.push.apply(edges, e);\n" " }\n" "\n" " return edges;\n" " }\n" "\n" " if (vertex.hasOwnProperty(\"_id\")) {\n" " vertex = vertex._id;\n" " }\n" "\n" " // get the edges\n" " requestResult = this._database._connection.GET(\"/edges/\" + encodeURIComponent(this._id) + \"?direction=out&vertex=\" + encodeURIComponent(vertex));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return requestResult['edges'];\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoQueryCursor\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoQueryCursor (database, data) {\n" " this._database = database;\n" " this.data = data;\n" " this._hasNext = false;\n" " this._hasMore = false;\n" " this._pos = 0;\n" " this._count = 0;\n" " this._total = 0;\n" " \n" " if (data.result != undefined) {\n" " this._count = data.result.length;\n" " \n" " if (this._pos < this._count) {\n" " this._hasNext = true;\n" " }\n" " \n" " if (data.hasMore != undefined && data.hasMore) {\n" " this._hasMore = true;\n" " } \n" " }\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help for ArangoQueryCursor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpArangoQueryCursor = TRI_CreateHelpHeadline(\"ArangoQueryCursor help\") +\n" "'ArangoQueryCursor constructor: ' + \"\\n\" +\n" "' > cu1 = qi1.execute(); ' + \"\\n\" +\n" "'Functions: ' + \"\\n\" +\n" "' hasMore(); returns true if there ' + \"\\n\" +\n" "' are more results ' + \"\\n\" +\n" "' next(); returns the next document ' + \"\\n\" +\n" "' elements(); returns all documents ' + \"\\n\" +\n" "' _help(); this help ' + \"\\n\" +\n" "'Attributes: ' + \"\\n\" +\n" "' _database database object ' + \"\\n\" +\n" "'Example: ' + \"\\n\" +\n" "' > st = db._createStatement({ \"query\" : \"for c in coll return c\" });' + \"\\n\" +\n" "' > c = st.execute(); ' + \"\\n\" +\n" "' > documents = c.elements(); ' + \"\\n\" +\n" "' > c = st.execute(); ' + \"\\n\" +\n" "' > while (c.hasNext()) { print( c.next() ); } ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the help for the cursor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype._help = function () {\n" " print(helpArangoQueryCursor);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a string representation of the cursor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype.toString = function () { \n" " return TRI_GetIdString(this, \"ArangoQueryCursor\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- public functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return whether there are more results available in the cursor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype.hasNext = function () {\n" " return this._hasNext;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return the next result document from the cursor\n" "///\n" "/// If no more results are available locally but more results are available on\n" "/// the server, this function will make a roundtrip to the server\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype.next = function () {\n" " if (!this._hasNext) {\n" " throw \"No more results\";\n" " }\n" " \n" " var result = this.data.result[this._pos];\n" " this._pos++;\n" " \n" " // reached last result\n" " if (this._pos == this._count) {\n" " this._hasNext = false;\n" " this._pos = 0;\n" " \n" " if (this._hasMore && this.data.id) {\n" " this._hasMore = false;\n" " \n" " // load more results \n" " var requestResult = this._database._connection.PUT(\"/_api/cursor/\"+ encodeURIComponent(this.data.id), \"\");\n" "\n" " TRI_CheckRequestResult(requestResult);\n" " \n" " this.data = requestResult;\n" " this._count = requestResult.result.length;\n" " \n" " if (this._pos < this._count) {\n" " this._hasNext = true;\n" " }\n" " \n" " if (requestResult.hasMore != undefined && requestResult.hasMore) {\n" " this._hasMore = true;\n" " } \n" " } \n" " }\n" " \n" " return result;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return all remaining result documents from the cursor\n" "///\n" "/// If no more results are available locally but more results are available on\n" "/// the server, this function will make one or multiple roundtrips to the \n" "/// server. Calling this function will also fully exhaust the cursor.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype.elements = function () { \n" " var result = [];\n" " \n" " while (this.hasNext()) { \n" " result.push( this.next() ); \n" " }\n" " \n" " return result;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief explicitly dispose the cursor\n" "///\n" "/// Calling this function will mark the cursor as deleted on the server. It will\n" "/// therefore make a roundtrip to the server. Using a cursor after it has been\n" "/// disposed is considered a user error\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype.dispose = function () {\n" " if (!this.data.id) {\n" " // client side only cursor\n" " return;\n" " }\n" "\n" " var requestResult = this._database._connection.DELETE(\"/_api/cursor/\"+ encodeURIComponent(this.data.id), \"\");\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " this.data.id = undefined;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return the total number of documents in the cursor\n" "///\n" "/// The number will remain the same regardless how much result documents have\n" "/// already been fetched from the cursor.\n" "///\n" "/// This function will return the number only if the cursor was constructed \n" "/// with the \"doCount\" attribute. Otherwise it will return undefined.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoQueryCursor.prototype.count = function () {\n" " if (!this.data.id) {\n" " throw \"cursor has been disposed\";\n" " }\n" "\n" " return this.data.count;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- ArangoStatement\n" "// -----------------------------------------------------------------------------\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- constructors and destructors\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief constructor\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "function ArangoStatement (database, data) {\n" " this._database = database;\n" " this._doCount = false;\n" " this._batchSize = null;\n" " this._bindVars = {};\n" " \n" " if (!(data instanceof Object)) {\n" " throw \"ArangoStatement needs initial data\";\n" " }\n" " \n" " if (data.query == undefined || data.query == \"\") {\n" " throw \"ArangoStatement needs a valid query attribute\";\n" " }\n" " this.setQuery(data.query);\n" "\n" " if (data.count != undefined) {\n" " this.setCount(data.count);\n" " }\n" " if (data.batchSize != undefined) {\n" " this.setBatchSize(data.batchSize);\n" " }\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- private functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief help for ArangoStatement\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpArangoStatement = TRI_CreateHelpHeadline(\"ArangoStatement help\") +\n" "'ArangoStatement constructor: ' + \"\\n\" +\n" "' > st = new ArangoStatement({ \"query\" : \"for ...\" }); ' + \"\\n\" +\n" "' > st = db._createStatement({ \"query\" : \"for ...\" }); ' + \"\\n\" +\n" "'Functions: ' + \"\\n\" +\n" "' bind(, ); bind single variable ' + \"\\n\" +\n" "' bind(); bind multiple variables ' + \"\\n\" +\n" "' setBatchSize(); set max. number of results ' + \"\\n\" +\n" "' to be transferred per roundtrip ' + \"\\n\" +\n" "' setCount(); set count flag (return number of ' + \"\\n\" +\n" "' results in \"count\" attribute) ' + \"\\n\" +\n" "' getBatchSize(); return max. number of results ' + \"\\n\" +\n" "' to be transferred per roundtrip ' + \"\\n\" +\n" "' getCount(); return count flag (return number of' + \"\\n\" +\n" "' results in \"count\" attribute) ' + \"\\n\" +\n" "' getQuery(); return query string ' + \"\\n\" +\n" "' execute(); execute query and return cursor ' + \"\\n\" +\n" "' _help(); this help ' + \"\\n\" +\n" "'Attributes: ' + \"\\n\" +\n" "' _database database object ' + \"\\n\" +\n" "'Example: ' + \"\\n\" +\n" "' > st = db._createStatement({ \"query\" : \"for c in coll filter ' + \"\\n\" +\n" "' c.x = @a@ && c.y = @b@ return c\" }); ' + \"\\n\" +\n" "' > st.bind(\"a\", \"hello\"); ' + \"\\n\" +\n" "' > st.bind(\"b\", \"world\"); ' + \"\\n\" +\n" "' > c = st.execute(); ' + \"\\n\" +\n" "' > print(c.elements()); ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief print the help for ArangoStatement\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype._help = function () {\n" " print(helpArangoStatement);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return a string representation of the statement\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.toString = function () { \n" " return TRI_GetIdString(this, \"ArangoStatement\");\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- public functions\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @addtogroup ArangoShell\n" "/// @{\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief bind a parameter to the statement\n" "///\n" "/// This function can be called multiple times, once for each bind parameter.\n" "/// All bind parameters will be transferred to the server in one go when \n" "/// execute() is called.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.bind = function (key, value) {\n" " if (key instanceof Object) {\n" " if (value != undefined) {\n" " throw \"invalid bind parameter declaration\";\n" " }\n" " this._bindVars = key;\n" " }\n" " else if (typeof(key) == \"string\") {\n" " if (this._bindVars[key] != undefined) {\n" " throw \"redeclaration of bind parameter\";\n" " }\n" " this._bindVars[key] = value;\n" " }\n" " else if (typeof(key) == \"number\") {\n" " var strKey = String(parseInt(key));\n" " if (strKey != String(key)) {\n" " throw \"invalid bind parameter declaration\";\n" " }\n" " if (this._bindVars[strKey] != undefined) {\n" " throw \"redeclaration of bind parameter\";\n" " }\n" " this._bindVars[strKey] = value;\n" " }\n" " else {\n" " throw \"invalid bind parameter declaration\";\n" " }\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief return the bind variables already set\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.getBindVariables = function () {\n" " return this._bindVars;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief get the count flag for the statement\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.getCount = function () {\n" " return this._doCount;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief get the maximum number of results documents the cursor will return\n" "/// in a single server roundtrip.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.getBatchSize = function () {\n" " return this._batchSize;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief get query string\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.getQuery = function () {\n" " return this._query;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief set the count flag for the statement\n" "///\n" "/// Setting the count flag will make the statement's result cursor return the\n" "/// total number of result documents. The count flag is not set by default.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.setCount = function (bool) {\n" " this._doCount = bool ? true : false;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief set the maximum number of results documents the cursor will return\n" "/// in a single server roundtrip.\n" "/// The higher this number is, the less server roundtrips will be made when\n" "/// iterating over the result documents of a cursor.\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.setBatchSize = function (value) {\n" " if (parseInt(value) > 0) {\n" " this._batchSize = parseInt(value);\n" " }\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief set the query string\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.setQuery = function (query) {\n" " this._query = query;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief parse a query and return the results\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.parse = function () {\n" " var body = {\n" " \"query\" : this._query,\n" " }\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/query\", JSON.stringify(body));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return true;\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief execute the query\n" "///\n" "/// Invoking execute() will transfer the query and all bind parameters to the\n" "/// server. It will return a cursor with the query results in case of success.\n" "/// In case of an error, the error will be printed\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "ArangoStatement.prototype.execute = function () {\n" " var body = {\n" " \"query\" : this._query,\n" " \"count\" : this._doCount,\n" " \"bindVars\" : this._bindVars\n" " }\n" "\n" " if (this._batchSize) {\n" " body[\"batchSize\"] = this._batchSize;\n" " }\n" "\n" " var requestResult = this._database._connection.POST(\"/_api/cursor\", JSON.stringify(body));\n" " \n" " TRI_CheckRequestResult(requestResult);\n" "\n" " return new ArangoQueryCursor(this._database, requestResult);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// -----------------------------------------------------------------------------\n" "// --SECTION-- initialisers\n" "// -----------------------------------------------------------------------------\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief general help\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "HELP = TRI_CreateHelpHeadline(\"Help\") +\n" "'Predefined objects: ' + \"\\n\" +\n" "' arango: ArangoConnection ' + \"\\n\" +\n" "' db: ArangoDatabase ' + \"\\n\" +\n" "'Example: ' + \"\\n\" +\n" "' > db._collections(); list all collections ' + \"\\n\" +\n" "' > db..all(); list all documents ' + \"\\n\" +\n" "' > id = db..save({ ... }); save a document ' + \"\\n\" +\n" "' > db..remove(<_id>); delete a document ' + \"\\n\" +\n" "' > db..document(<_id>); get a document ' + \"\\n\" +\n" "' > help show help pages ' + \"\\n\" +\n" "' > helpQueries query help ' + \"\\n\" +\n" "' > exit ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief query help\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpQueries = TRI_CreateHelpHeadline(\"Select query help\") +\n" "'Create a select query: ' + \"\\n\" +\n" "' > st = new ArangoStatement(db, { \"query\" : \"for...\" }); ' + \"\\n\" +\n" "' > st = db._createStatement({ \"query\" : \"for...\" }); ' + \"\\n\" +\n" "'Set query options: ' + \"\\n\" +\n" "' > st.setBatchSize(); set the max. number of results ' + \"\\n\" +\n" "' to be transferred per roundtrip ' + \"\\n\" +\n" "' > st.setCount(); set count flag (return number of ' + \"\\n\" +\n" "' results in \"count\" attribute) ' + \"\\n\" +\n" "'Get query options: ' + \"\\n\" +\n" "' > st.setBatchSize(); return the max. number of results ' + \"\\n\" +\n" "' to be transferred per roundtrip ' + \"\\n\" +\n" "' > st.getCount(); return count flag (return number of' + \"\\n\" +\n" "' results in \"count\" attribute) ' + \"\\n\" +\n" "' > st.getQuery(); return query string ' + \"\\n\" +\n" "' results in \"count\" attribute) ' + \"\\n\" +\n" "'Bind parameters to a query: ' + \"\\n\" +\n" "' > st.bind(, ); bind single variable ' + \"\\n\" +\n" "' > st.bind(); bind multiple variables ' + \"\\n\" +\n" "'Execute query: ' + \"\\n\" +\n" "' > c = st.execute(); returns a cursor ' + \"\\n\" +\n" "'Get all results in an array: ' + \"\\n\" +\n" "' > e = c.elements(); ' + \"\\n\" +\n" "'Or loop over the result set: ' + \"\\n\" +\n" "' > while (c.hasNext()) { print( c.next() ); } ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief extended help\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "helpExtended = TRI_CreateHelpHeadline(\"More help\") +\n" "'Pager: ' + \"\\n\" +\n" "' > internal.stop_pager() stop the pager output ' + \"\\n\" +\n" "' > internal.start_pager() start the pager ' + \"\\n\" +\n" "'Pretty printing: ' + \"\\n\" +\n" "' > stop_pretty_print() stop pretty printing ' + \"\\n\" +\n" "' > start_pretty_print() start pretty printing ' + \"\\n\" +\n" "'Color output: ' + \"\\n\" +\n" "' > stop_color_print() stop color printing ' + \"\\n\" +\n" "' > start_color_print() start color printing ' + \"\\n\" +\n" "' > start_color_print(COLOR_BLUE) set color ' + \"\\n\" +\n" "'Print function: ' + \"\\n\" +\n" "' > print(x) std. print function ' + \"\\n\" +\n" "' > print_plain(x) print without pretty printing' + \"\\n\" +\n" "' and without colors ';\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @brief create the global db object and load the collections\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "try {\n" " if (typeof arango !== 'undefined') {\n" "\n" " // default databases\n" " db = new ArangoDatabase(arango);\n" " edges = new ArangoEdges(arango);\n" "\n" " // load collection data\n" " db._collections();\n" " edges._collections();\n" "\n" " // export to internal\n" " ModuleCache[\"/internal\"].exports.db = db;\n" " ModuleCache[\"/internal\"].exports.edges = db;\n" "\n" " // load simple queries\n" " require(\"simple-query\");\n" "\n" " print(HELP);\n" " }\n" "}\n" "catch (err) {\n" " print(err);\n" "}\n" "\n" "////////////////////////////////////////////////////////////////////////////////\n" "/// @}\n" "////////////////////////////////////////////////////////////////////////////////\n" "\n" "// Local Variables:\n" "// mode: outline-minor\n" "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"\n" "// End:\n" ;