arangodbarangodb-php

Arangov2.8 - Examples of register user functions in AQL


I need to filter some nodes by regex but since Arango v2.8 does not have this functionality I want to try registering user functions can anyone give me an example of how to register a simple function and use it in AQL?

I'm trying:

var myfunc = function (ideation_node) {
  for (var i = 0; i < ideation_node.length; ++i) {

    if (true) {
      return ideation_node[i];
    }
  }
  return null;
}

RETURN myfunctions::myfunc()

Solution

  • You use triagens/ArangoDb/AqlUserFunction to register a user function.

        $funcHandler = new \triagens\ArangoDb\AqlUserFunction($arangoConnection);
        $funcHandler->name = 'myfunctions::myFunc';
        $funcHandler->code = 'function(ideation_node){...}';
        $funcHandler->register();    
    

    In AQL-Statements registered functions are used like any other function, using the fully-qualified (i.e. with namespace-prefix) name of the function.

    Make sure that the function is side-effect free and don't manipulate input-parameters, but use return-values to pass the calculation results to the outside world.