Reputation: 941
I need to run some queries that the Foxx Repository object doesn't seem capable of handling (Maybe I'm just missing something). I'd like to use AQL, but I don't know how to call it from Foxx.
Example:
timestamps Collection:
{ user_id, time_stamp }
SQL Query (What I'd like to emulate):
SELECT * FROM timestamps WHERE user_id = 1024 AND time_stamp < 123456789
I can do:
timestamps.byExample( {user_id:1024} )
But this doesn't let me do a range as well.
Upvotes: 3
Views: 255
Reputation: 2764
In principle you can use the normal queries in a controller method. This will circumvent 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 });
});
That is OK, if you want to use non-Foxx collections. If you need a Foxx collection the name depends on the mount point, in this case you need to use collectionName. 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 });
});
Upvotes: 2