Oihana PHP Arango

aqlRepsert.php

Table of Contents

Functions

aqlRepsert()  : string
Prepare a REPSERT query to replace an existing document or insert a new one if it does not exist.

Functions

aqlRepsert()

Prepare a REPSERT query to replace an existing document or insert a new one if it does not exist.

aqlRepsert([array<string|int, mixed> $init = [] ]) : string
UPSERT [ searchExpression | FILTER filterExpression ]
INSERT insertExpression
REPLACE replaceExpression
IN collection

Options in $init:

  • collection: string|null, name of the collection.
  • filter: array|string|null, optional filter expression.
  • search: array|string|null, the search document.
  • insert: array|string|null, the document to insert if no match is found.
  • replace: array|string|null, the document to replace if a match is found.
  • options: array|QueryOptions|string|JsonSerializable|null, optional upsert options.
  • return: optional expression to define the RETURN clause. Default is Clause::NEW. You can also use Clause::WITH_STATUS to return both the document and the type of operation.
Parameters
$init : array<string|int, mixed> = []

Configuration options for the REPSERT query.

Tags
throws
ReflectionException
UnsupportedOperationException
example
$query = aqlRepsert
([
    'search'  => [['foo', 'bar']],
    'insert'  => [['foo', 'bar']],
    'replace' => [['foo', 'baz']],
]);
// Returns: "UPSERT {foo:'bar'} INSERT {foo:'bar'} REPLACE {foo:'baz'} IN @@collection RETURN NEW"
see
https://docs.arangodb.com/stable/aql/high-level-operations/upsert
since
1.0.0
author

Marc Alcaraz

Return values
string

The generated AQL UPSERT query.

On this page

Search results