Oihana PHP Arango

aqlFieldConditional.php

Table of Contents

Functions

aqlFieldConditional()  : string
Generate an AQL key/value expression for a conditional scalar field (`Field::WHEN`).

Functions

aqlFieldConditional()

Generate an AQL key/value expression for a conditional scalar field (`Field::WHEN`).

aqlFieldConditional(string $key, string $then, mixed $when[, mixed $else = null ][, string $doc = AQL::DOC ]) : string

Guards the projected value behind a condition — the SQL CASE WHEN … THEN … ELSE … shape, rendered as an AQL ternary:

price: doc.visibility == 'public' ? doc.price : null

The key is always present; only the value switches to the else branch (default null) when the condition is false — it never omits the key (that would require a MERGE, intentionally out of scope). The condition is compiled by buildWhenCondition() (inline, no bind variables) and the else branch by resolveWhenElse().

The $then expression is the already-built scalar projection — the bare field reference (doc.price) or, when the field also declares Field::ALTERS, the transformed value (LOWER(TRIM(doc.price))). The caller (aqlFields()) builds it.

Parameters
$key : string

The output key/label (possibly already double-quoted).

$then : string

The value projected when the condition holds (e.g. doc.price).

$when : mixed

The Field::WHEN condition descriptor.

$else : mixed = null

The Field::ELSE descriptor (literal or [ Field::PROPERTY => '<attr>' ]; default null).

$doc : string = AQL::DOC

The document reference for the condition/else operands (default: AQL::DOC).

Tags
throws
UnsupportedOperationException

If the condition descriptor is malformed.

ValidationException

If a condition or else attribute name is unsafe.

since
1.3.0
author

Marc Alcaraz

Return values
string

The AQL key/value snippet, e.g. price:doc.visibility == 'public' ? doc.price : null.

On this page

Search results