Oihana PHP Arango

aqlUpsertExpression.php

Table of Contents

Functions

aqlUpsertExpression()  : string
Builds the leading clause of an AQL `UPSERT` operation.

Functions

aqlUpsertExpression()

Builds the leading clause of an AQL `UPSERT` operation.

aqlUpsertExpression([array<string|int, mixed> $init = [] ]) : string

The ArangoDB syntax accepts the lookup as either a search expression or a filter expression — never both:

UPSERT [ searchExpression | FILTER filterExpression ]

Accordingly, exactly one of the two $init keys must be supplied:

  • AQL::SEARCH — an object literal matched by equality, rendered as UPSERT { … } (see aqlExpression()).
  • AQL::FILTER — a more flexible filter expression, rendered as UPSERT FILTER … (see aqlFilter()).

Supplying neither, or both at the same time, throws an InvalidArgumentException.

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

Associative array with exactly one of:

  • AQL::SEARCH : array|string — the search document.
  • AQL::FILTER : array|string — the filter expression.
Tags
throws
InvalidArgumentException

If neither FILTER nor SEARCH is defined, or if both are defined at the same time.

UnsupportedOperationException
example

Search form (object literal matched by equality):

use oihana\arango\db\enums\AQL;
use function oihana\arango\db\helpers\aqlUpsertExpression;

echo aqlUpsertExpression([ AQL::SEARCH => [ [ 'foo' , 'bar' ] ] ]);
// UPSERT {foo:'bar'}

Filter form (flexible lookup condition):

echo aqlUpsertExpression([ AQL::FILTER => [ [ 'foo' , 'bar' ] ] ]);
// UPSERT FILTER foo && bar

Invalid — neither key supplied:

aqlUpsertExpression([]);
// InvalidArgumentException: Either FILTER or SEARCH option is required.

Invalid — both keys supplied (mutually exclusive):

aqlUpsertExpression([ AQL::FILTER => …, AQL::SEARCH => … ]);
// InvalidArgumentException: FILTER and SEARCH cannot be defined at the same time.
since
1.0.0
author

Marc Alcaraz

Return values
string

The UPSERT … clause.

On this page

Search results