Oihana PHP Arango

helpers

Table of Contents

Functions

dropFieldQuery()  : string
Builds the AQL that removes a top-level attribute from every document of a collection.
renameFieldQuery()  : string
Builds the AQL that renames a top-level attribute on every document of a collection — the `up()` of a field rename.
setDefaultQuery()  : string
Builds the AQL that backfills a default value on every document where a field is missing or `null` — the typical "new column" backfill.

Functions

dropFieldQuery()

Builds the AQL that removes a top-level attribute from every document of a collection.

dropFieldQuery(string $collection, string $field) : string

Emits FOR doc IN <collection> FILTER HAS(doc, "<field>") UPDATE doc WITH { <field>: null } IN <collection> OPTIONS { keepNull: false }keepNull: false strips the attribute instead of storing null.

Pure: returns the query string, runs nothing.

Parameters
$collection : string

The collection name.

$field : string

The attribute to remove.

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
string

The ready-to-run AQL query.

renameFieldQuery()

Builds the AQL that renames a top-level attribute on every document of a collection — the `up()` of a field rename.

renameFieldQuery(string $collection, string $from, string $to) : string

Emits FOR doc IN <collection> FILTER HAS(doc, "<from>") UPDATE doc WITH { <to>: doc.<from>, <from>: null } IN <collection> OPTIONS { keepNull: false } — the new attribute takes the old value, the old one is dropped (keepNull: false removes it rather than storing null).

Pure: returns the query string, runs nothing. A Migration executes it (see Migration::renameField()).

Parameters
$collection : string

The collection name.

$from : string

The current attribute name.

$to : string

The new attribute name.

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
string

The ready-to-run AQL query.

setDefaultQuery()

Builds the AQL that backfills a default value on every document where a field is missing or `null` — the typical "new column" backfill.

setDefaultQuery(string $collection, string $field, mixed $value) : string

Emits FOR doc IN <collection> FILTER doc.<field> == null UPDATE doc WITH { <field>: <value> } IN <collection>. The value is JSON-encoded, so a string, number, boolean, array or object literal all work.

Pure: returns the query string, runs nothing.

Parameters
$collection : string

The collection name.

$field : string

The attribute to backfill.

$value : mixed

The default value (emitted as a JSON literal).

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0
Return values
string

The ready-to-run AQL query.

On this page

Search results