Let’s say you want to write a query that takes all non-admin users with a power level over 9000 and returns their score rounded to the closest 100. In plain AQL this could be written like this:
FOR user IN users FILTER user.isAdmin == false && user.powerLevel > 9000 RETURN ROUND(user.score / 100) * 100
Trying to construct this query using the query builder would previously have resulted in code like this:
var qb = require('aqb'); var query = qb.for('user').in('users').filter( qb.and( qb.eq('user.isAdmin', false), qb.gt('user.powerLevel', 9000) ) ).return( qb.times(qb.ROUND(qb.div('user.score', 100)), 100) );
As of AQB 1.10.0, you can instead write the following:
var qb = require('aqb'); var query = qb.for('user').in('users').filter( qb.ref('user.isAdmin').eq(false) .and(qb.ref('user.powerLevel').gt(9000)) ).return( qb.ROUND(qb.ref('user.score').div(100)).times(100) );
Alan Plum, Geschäftsführer Foss & Haas – Software-Architektur & Entwicklung
This article originally appeared on the ArangoDB blog on April 20, 2015.