Array of values to join. These values will behave exactly
like values interpolated in an aql
template string.
Seperator to insert between values. This value will behave exactly like a value passed to literal, i.e. it will be inlined as-is, rather than being converted into a bind parameter.
const users = db.collection("users");
const filters = [];
if (adminsOnly) filters.push(aql`FILTER user.admin`);
if (activeOnly) filters.push(aql`FILTER user.active`);
const result = await db.query(aql`
FOR user IN ${users}
${join(filters)}
RETURN user
`);
const users = db.collection("users");
const keys = ["jreyes", "ghermann"];
// BAD! NEEDLESSLY COMPLEX!
const docs = keys.map(key => aql`DOCUMENT(${users}, ${key}`));
const result = await db.query(aql`
FOR user IN [
${join(docs, ", ")}
]
RETURN user
`);
// Query:
// FOR user IN [
// DOCUMENT(@@value0, @value1), DOCUMENT(@@value0, @value2)
// ]
// RETURN user
// Bind parameters:
// @value0 -> "users"
// value1 -> "jreyes"
// value2 -> "ghermann"
// GOOD! MUCH SIMPLER!
const result = await db.query(aql`
FOR key IN ${keys}
LET user = DOCUMENT(${users}, key)
RETURN user
`);
// Query:
// FOR user IN @value0
// LET user = DOCUMENT(@@value1, key)
// RETURN user
// Bind parameters:
// value0 -> ["jreyes", "ghermann"]
// @value1 -> "users"
Constructs AqlQuery objects from an array of arbitrary values.
Note: Nesting
aql
template strings is a much safer alternative for most use cases. This low-level helper function only exists to complement theaql
tag when constructing complex queries from dynamic arrays of query fragments.