How to run Foxx AQL
I need to run some requests that the Foxx repository object cannot handle (maybe I just missed something). I would like to use AQL, but I don't know how to call it from Foxx.
Example:
timestamps Collection:
{ user_id, time_stamp }
SQL Query (Which I would like to emulate):
SELECT * FROM timestamps WHERE user_id = 1024 AND time_stamp < 123456789
I can do:
timestamps.byExample( {user_id:1024} )
But that doesn't allow me to do the range.
+3
source to share
1 answer
Basically, you can use normal queries in a controller method. It will bypass the Foxx repository methods, but should work. Example:
controller.around("/hallo", function (req, res, options, next) {
var count = true;
var data = db._query("FOR u IN _users FILTER u.user == @name RETURN u",
{ name: "root" }).toArray();
res.json({ result: data });
});
This is fine if you want to use non-Foxx collections. If you need a Foxx collection, the name depends on the mount point, in which case you need to use the collection name. Let's say your collection is called "texts" then use
controller.around("/hallo", function (req, res, options, next) {
var count = true;
var data = db._query("FOR u IN @@texts RETURN u",
{ '@texts': applicationContext.collectionName("texts") }).toArray();
res.json({ result: data });
});
+2
source to share