Oihana PHP Arango

resolveUpsertReturn.php

Table of Contents

Functions

resolveUpsertReturn()  : mixed
Resolves the `RETURN` expression of an upsert-family operation, expanding the {@see Clause::WITH_STATUS} shorthand into the ternary that reports which half of the upsert actually ran.

Functions

resolveUpsertReturn()

Resolves the `RETURN` expression of an upsert-family operation, expanding the {@see Clause::WITH_STATUS} shorthand into the ternary that reports which half of the upsert actually ran.

resolveUpsertReturn(array<string|int, mixed> $init, string $writeType) : mixed

An upsert either inserts or writes over an existing document, and the caller usually cannot tell which from the returned document alone. WITH_STATUS answers that by leaning on AQL's own signal: on an insert there is no OLD, so the ternary reads

RETURN { doc: NEW , type: OLD ? 'replace' : 'insert' }

The write half is named by the caller, since it differs between the operations — aqlRepsert() overwrites the document (UpsertType::REPLACE) where aqlUpsert() merges into it (UpsertType::UPDATE). The insert half is always UpsertType::INSERT.

Any other AQL::RETURN value is passed through untouched, so a caller can still return a hand-written expression; the default is Clause::NEW.

Parameters
$init : array<string|int, mixed>

The operation options; AQL::RETURN holds the requested expression.

$writeType : string

The upsert type reported when the document already existed.

Tags
example
use function oihana\arango\db\helpers\resolveUpsertReturn;

resolveUpsertReturn( [] , UpsertType::REPLACE ) ;
// 'NEW'

resolveUpsertReturn( [ AQL::RETURN => Clause::WITH_STATUS ] , UpsertType::UPDATE ) ;
// "{ doc: NEW , type: OLD ? 'update' : 'insert' }"
since
1.6.0
author

Marc Alcaraz

Return values
mixed

The RETURN expression, expanded for WITH_STATUS and unchanged otherwise.

On this page

Search results