1
0
Fork 0
arangodb/RestServer/js-actions.h

174 lines
6.1 KiB
C

static string JS_actions =
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief JavaScript actions functions\n"
"///\n"
"/// @file\n"
"///\n"
"/// DISCLAIMER\n"
"///\n"
"/// Copyright by triAGENS GmbH - All rights reserved.\n"
"///\n"
"/// The Programs (which include both the software and documentation)\n"
"/// contain proprietary information of triAGENS GmbH; they are\n"
"/// provided under a license agreement containing restrictions on use and\n"
"/// disclosure and are also protected by copyright, patent and other\n"
"/// intellectual and industrial property laws. Reverse engineering,\n"
"/// disassembly or decompilation of the Programs, except to the extent\n"
"/// required to obtain interoperability with other independently created\n"
"/// software or as specified by law, is prohibited.\n"
"///\n"
"/// The Programs are not intended for use in any nuclear, aviation, mass\n"
"/// transit, medical, or other inherently dangerous applications. It shall\n"
"/// be the licensee's responsibility to take all appropriate fail-safe,\n"
"/// backup, redundancy, and other measures to ensure the safe use of such\n"
"/// applications if the Programs are used for such purposes, and triAGENS\n"
"/// GmbH disclaims liability for any damages caused by such use of\n"
"/// the Programs.\n"
"///\n"
"/// This software is the confidential and proprietary information of\n"
"/// triAGENS GmbH. You shall not disclose such confidential and\n"
"/// proprietary information and shall use it only in accordance with the\n"
"/// terms of the license agreement you entered into with triAGENS GmbH.\n"
"///\n"
"/// Copyright holder is triAGENS GmbH, Cologne, Germany\n"
"///\n"
"/// @author Dr. Frank Celler\n"
"/// @author Copyright 2011, triAGENS GmbH, Cologne, Germany\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"// -----------------------------------------------------------------------------\n"
"// --SECTION-- public functions\n"
"// -----------------------------------------------------------------------------\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @addtogroup V8Json V8 JSON\n"
"/// @{\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief returns a result of a query as documents\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function queryResult (req, res, query) {\n"
" var result;\n"
" var offset = 0;\n"
" var page = 0;\n"
" var blocksize = 0;\n"
" var t;\n"
" var result;\n"
"\n"
" t = time();\n"
"\n"
" if (req.blocksize) {\n"
" blocksize = req.blocksize;\n"
"\n"
" if (req.page) {\n"
" page = req.page;\n"
" offset = page * blocksize;\n"
" query = query.skip(offset).limit(blocksize);\n"
" }\n"
" else {\n"
" query = query.limit(blocksize);\n"
" }\n"
" }\n"
"\n"
" result = query.toArray();\n"
"\n"
" result = {\n"
" total : query.count(),\n"
" count : query.count(true),\n"
" offset : offset,\n"
" blocksize : blocksize,\n"
" page : page,\n"
" runtime : time() - t,\n"
" documents : result\n"
" };\n"
"\n"
" res.responseCode = 200;\n"
" res.contentType = \"application/json\";\n"
" res.body = JSON.stringify(result);\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief returns a result of a query as references\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function queryReferences (req, res, query) {\n"
" var result;\n"
" var offset = 0;\n"
" var page = 0;\n"
" var blocksize = 0;\n"
" var t;\n"
" var result;\n"
"\n"
" t = time();\n"
"\n"
" if (req.blocksize) {\n"
" blocksize = req.blocksize;\n"
"\n"
" if (req.page) {\n"
" page = req.page;\n"
" offset = page * blocksize;\n"
" query = query.skip(offset).limit(blocksize);\n"
" }\n"
" else {\n"
" query = query.limit(blocksize);\n"
" }\n"
" }\n"
"\n"
" result = [];\n"
"\n"
" while (query.hasNext()) {\n"
" result.push(query.nextRef());\n"
" }\n"
"\n"
" result = {\n"
" total : query.count(),\n"
" count : query.count(true),\n"
" offset : offset,\n"
" blocksize : blocksize,\n"
" page : page,\n"
" runtime : time() - t,\n"
" references : result\n"
" };\n"
"\n"
" res.responseCode = 200;\n"
" res.contentType = \"application/json\";\n"
" res.body = JSON.stringify(result);\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief returns a result\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function actionResult (req, res, code, result) {\n"
" if (code == 204) {\n"
" res.responseCode = code;\n"
" }\n"
" else {\n"
" res.responseCode = code;\n"
" res.contentType = \"application/json\";\n"
" res.body = JSON.stringify(result);\n"
" }\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief returns an error\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function actionError (req, res, err) {\n"
" res.responseCode = 500;\n"
" res.contentType = \"application/json\";\n"
" res.body = JSON.stringify({ 'error' : \"\" + err });\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @}\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"// Local Variables:\n"
"// mode: outline-minor\n"
"// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"\n"
"// End:\n"
;