aqlFor.php
Table of Contents
Functions
- aqlFor() : string
- Builds an ArangoDB AQL `FOR` clause, optionally including `SEARCH` and `OPTIONS` segments.
Functions
aqlFor()
Builds an ArangoDB AQL `FOR` clause, optionally including `SEARCH` and `OPTIONS` segments.
aqlFor([array<string|int, mixed> $init = [] ]) : string
The generated query follows this canonical form:
FOR <variableName> IN <expression> [SEARCH <searchExpression>] [OPTIONS { ... }]
This function simplifies the construction of AQL loops by automatically
compiling the parts (IN, SEARCH, OPTIONS) using helper functions such as
aqlSearch() and aqlOptions().
Supported $init keys
| Key | Type | Description |
|---|---|---|
AQL::DOC_REF |
`string | null` |
AQL::IN |
`string | null` |
AQL::SEARCH |
`string | null` |
AQL::OPTIONS |
`array | object |
Example: basic usage
echo aqlFor([
AQL::DOC_REF => 'doc',
AQL::IN => 'users'
]);
// → "FOR doc IN users"
Example: with SEARCH and OPTIONS
echo aqlFor
([
AQL::DOC_REF => 'u',
AQL::IN => 'searchUsers',
AQL::SEARCH => 'u.active == true',
AQL::OPTIONS =>
[
'indexHint' => 'byActive',
'forceIndexHint' => true,
'disableIndex' => false,
'useCache' => true,
'lookahead' => 5
]
]);
// → "FOR u IN searchUsers SEARCH u.active == true OPTIONS {\"indexHint\":\"byActive\",\"forceIndexHint\":true,\"disableIndex\":false,\"useCache\":true,\"lookahead\":5}"
Example: using a ForOptions schema object
use oihana\arango\db\options\ForOptions;
$opts = new ForOptions([
'useCache' => false,
'lookahead' => 3
]);
echo aqlFor
`([
AQL::DOC_REF => 'd',
AQL::IN => 'documents',
AQL::OPTIONS => $opts
]);
// → "FOR d IN documents OPTIONS {\"useCache\":false,\"lookahead\":3}"
Parameters
- $init : array<string|int, mixed> = []
-
An associative array defining the
FORclause elements. Example structure:[ AQL::DOC_REF => 'doc', AQL::IN => 'users', AQL::SEARCH => 'doc.age > 30', AQL::OPTIONS => [ 'useCache' => true ] ]
Tags
Return values
string —The complete AQL FOR clause, or an empty string if no valid input is provided.