Reputation: 3906
I know that ArangoDB allows for custom AQL functions to be defined server side, but is it possible to define server-side Javascript functions that can be called during transactions?
I'm using the Java driver to connect to ArangoDB, which performs transactions by sending a Javascript function as a string.
To avoid sending a large and complex string every time (one transaction I'm using is ~500 lines long), I'd prefer to have it stored server-side, and called more simply from Java.
E.g. instead of running something like:
String action = "function (params) {"
+ "const db = require('@arangodb').db;"
+ "return db._query('FOR i IN test RETURN i._key').toArray();"
+ "}";
String[] keys = arango.db().transaction(action, String[].class, new TransactionOptions());
I'd like to call something like:
String action = "my_function";
String[] keys = arango.db().transaction(action, String[].class, new TransactionOptions());
Or:
String action = "function(params) {"
+ "const my_function = require("somefunc");
+ "return my_function(params);
+ "}";
Is this possible to achieve?
Upvotes: 0
Views: 58
Reputation: 11915
You can write custom endpoints with Foxx.
It is a microservice framework written in JavaScript that lets you execute complex JS code on the server-side, with access to ArangoDB's internal JS API (db
object etc.). You can encapsulate whatever business logic in it, e.g. your 500 lines of transaction code and add some parameters to control it from outside without having to send all the code each time.
Upvotes: 1