简体   繁体   中英

ArangoDb: How to write a user defined function in WebUi of ArangoDb

How to write a user defined function in the webUI version of ArangoDb community Edition. In their documentation they have given example for writing user defined functions in Arangoshell but not for webUI. Is there a way to write a function in the webUI version?

require("@arangodb/aql/functions").register("MYFUNCTIONS::TEMPERATURE::CELSIUSTOFAHRENHEIT",
function (celsius) {
  "use strict";
  return celsius * 1.8 + 32;
});

This is NOT the intended usage of user defined functions, the AQL-Documentation clearly states:

These functions are written in JavaScript, and are deployed via an API;

You don't have to use arangosh and the js api client, bindings should provide you with access to the UDF api (eg AqlUSerFunction.php of the arangodb-php library).

But if you are so inclined, you can use the knowledge that

Internally, UDFs are stored in a system collection named _aqlfunctions of the selected database. When an AQL statement refers to such a UDF, it is loaded from that collection. The UDFs will be exclusively available for queries in that particular database.

And insert function documents into _aqlfunctions manually.

They are (currently) of the form

{
  "name": "MYNAMESPACE::FUNCTIONNAME",
  "code": "(function (PARAMS) {  return "value"; })",
  "isDeterministic": BOOL
}

You can show system collections by clicking on the cog-wheel icon in the upper right and enabling "Type: [X] System".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM