Oihana PHP Arango

functions

Table of Contents

Namespaces

arrays
bit
dates
documents
geo
numerics
search
strings

Functions

checkDocument()  : string
Returns true if document is a valid document object, i.e. a document without any duplicate attribute names.
collectionCount()  : string
Determine the amount of documents in a collection. LENGTH() is preferred.
currentDatabase()  : string
Returns the name of the current database.
currentUser()  : string
Return the name of the current user.
decodeRev()  : string
Decompose the specified revision string into its components. The resulting object has a date and a count attribute. This function is supposed to be called with the _rev attribute value of a database document as argument.
document()  : string
Dynamically look up one or multiple documents from any collections, either using a collection name and one or more document keys, or one or more document identifiers.
firstDocument()  : string
Return the first alternative that is a document, and null if none of the alternatives is a document.
firstList()  : string
Return the first alternative that is an array, and null if none of the alternatives is an array.
isArray()  : string
Builds an AQL expression that checks whether a given value is an array (list or object array).
isBool()  : string
Builds an AQL expression that checks whether a given value is a boolean.
isDateString()  : string
Builds an AQL expression that checks whether a value is a valid date string.
isKey()  : string
Builds an AQL expression that checks whether a value is a valid document key.
isNull()  : string
Builds an AQL expression that checks whether a value is `null`.
isNumber()  : string
Builds an AQL expression that checks whether a value is a number.
isObject()  : string
Builds an AQL expression that checks whether a value is an object/document.
isString()  : string
Builds an AQL expression that checks whether a value is a string.
length()  : string
Determine the amount of documents in a collection.
notNull()  : string
Builds an AQL expression return the first element that is not null, and null if all alternatives are null themselves.
toArray()  : string
Converts a value of any type into an array.
toBool()  : string
Converts a value of any type into a boolean.
toNumber()  : string
Converts a value of any type into a numeric value.
toString()  : string
Converts a value of any type into a string.
typeName()  : string
Returns the data type name of the given value in AQL.

Functions

checkDocument()

Returns true if document is a valid document object, i.e. a document without any duplicate attribute names.

checkDocument(mixed $document) : string

Will return false for any non-objects/non-documents or documents with duplicate attribute names.

This helper wraps the ArangoDB AQL function CHECK_DOCUMENT().

Example AQL output:

CHECK_DOCUMENT(doc)
Parameters
$document : mixed
Tags
example
use function oihana\arango\db\functions\firstDocument;

$expr = checkDocument('doc');
// Produces: 'CHECK_DOCUMENT(doc)'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#check_document
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'CHECK_DOCUMENT(doc)').

collectionCount()

Determine the amount of documents in a collection. LENGTH() is preferred.

collectionCount(mixed $collection) : string

This helper wraps the ArangoDB AQL function COLLECTION_COUNT().

Example AQL output:

COLLECTION_COUNT(coll)
Parameters
$collection : mixed
Tags
example
use function oihana\arango\db\functions\collectionCount;

$expr = collectionCount('coll');
// Produces: 'COLLECTION_COUNT(coll)'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#collection_count
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'COLLECTION_COUNT(coll)').

currentDatabase()

Returns the name of the current database.

currentDatabase() : string

The current database is the database name that was specified in the URL path of the request (or defaults to _system database).

Returns databaseName (string): the current database name

This helper wraps the ArangoDB AQL function CURRENT_DATABASE().

Example AQL output:

CURRENT_DATABASE()
Tags
example
use function oihana\arango\db\functions\collectionCount;

$expr = currentDatabase();
// Produces: 'CURRENT_DATABASE()'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#current_database
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'CURRENT_DATABASE()').

currentUser()

Return the name of the current user.

currentUser() : string

TThe current user is the user account name that was specified in the Authorization HTTP header of the request. It will only be populated if authentication on the server is turned on, and if the query was executed inside a request context. Otherwise, the return value of this function will be null.

Returns userName (string|null): the current user name, or null if authentication is disabled

This helper wraps the ArangoDB AQL function CURRENT_USER().

Example AQL output:

CURRENT_USER()
Tags
example
use function oihana\arango\db\functions\currentUser;

$expr = currentUser();
// Produces: 'CURRENT_USER()'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#current_user
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'CURRENT_USER()').

decodeRev()

Decompose the specified revision string into its components. The resulting object has a date and a count attribute. This function is supposed to be called with the _rev attribute value of a database document as argument.

decodeRev(string|null $value) : string

revision (string): revision ID string returns details (object|null): object with two attributes date (string in ISO 8601 format) and count (integer number), or null If the input revision ID is not a string or cannot be processed, the function issues a warning and returns null.

Parameters
$value : string|null
Tags
example
use function oihana\arango\db\functions\decodeRev;

$expr = decodeRev( '"_YU0HOEG---"' );
// Produces: 'DECODE_REV("_YU0HOEG---")'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#decode_rev
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'DECODE_REV(user.email)').

document()

Dynamically look up one or multiple documents from any collections, either using a collection name and one or more document keys, or one or more document identifiers.

document(mixed ...$values) : string

The collections do not need to be known at query compile time, they can be computed at runtime.

This helper wraps the ArangoDB AQL function DOCUMENT().

Example AQL output:

RETURN DOCUMENT( persons, "persons/alice" )
Parameters
$values : mixed
Tags
example
use function oihana\arango\db\functions\document;

$expr = document( 'persons', '"alice"' );
// Produces: 'DOCUMENT(persons,"alice")'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#document
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'NOT_NULL(user.email)').

firstDocument()

Return the first alternative that is a document, and null if none of the alternatives is a document.

firstDocument(mixed ...$alternative) : string

This helper wraps the ArangoDB AQL function FIRST_DOCUMENT().

Example AQL output:

FIRST_DOCUMENT(null, null, "foo", "bar") // "foo"
Parameters
$alternative : mixed

input of arbitrary type

Tags
example
use function oihana\arango\db\functions\firstDocument;

$expr = firstDocument('null,doc,'hello');
// Produces: 'FIRST_DOCUMENT(null,doc,'hello')'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#first_document
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'FIRST_DOCUMENT(alternative,....)').

firstList()

Return the first alternative that is an array, and null if none of the alternatives is an array.

firstList(mixed ...$alternative) : string

This helper wraps the ArangoDB AQL function FIRST_LIST().

Example AQL output:

FIRST_LIST(null, null, ["foo"], "bar") // ["foo"]
Parameters
$alternative : mixed

input of arbitrary type

Tags
example
use function oihana\arango\db\functions\firstList;

$expr = firstList('null,doc,["hello"]);
// Produces: 'FIRST_LIST(null,doc,["hello"])'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#first_list
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'FIRST_LIST(alternative,....)').

isArray()

Builds an AQL expression that checks whether a given value is an array (list or object array).

isArray(string $value) : string

This helper wraps the ArangoDB AQL function IS_ARRAY() and returns a string representation of the corresponding expression.

The AQL function IS_ARRAY(value) evaluates to true if the provided value is an array (either a list or an object array), and false otherwise.

Example output:

IS_ARRAY(doc.tags)
Parameters
$value : string

The AQL field or expression to check (e.g. 'doc.tags').

Tags
example
use function oihana\arango\db\functions\isArray;

$expr = isArray('doc.tags');
// Produces: 'IS_ARRAY(doc.tags)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_array
since
1.0.0
author

Marc Alcaraz

Return values
string

The AQL expression as a string (e.g. 'IS_ARRAY(doc.tags)').

isBool()

Builds an AQL expression that checks whether a given value is a boolean.

isBool(string $value) : string

This helper wraps the ArangoDB AQL function IS_BOOL() and returns a string representation of that expression.

The AQL function IS_BOOL(value) returns true if the provided value is a boolean (true or false), and false otherwise.

Example output:

IS_BOOL(doc.isActive)
Parameters
$value : string

The AQL field or expression to check (e.g. 'doc.isActive').

Tags
example
use function oihana\arango\db\functions\isBool;

$expr = isBool('doc.isActive');
// Produces: 'IS_BOOL(doc.isActive)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_datestring
since
1.0.0
author

Marc Alcaraz

Return values
string

The AQL expression as a string (e.g. 'IS_BOOL(doc.isActive)').

isDateString()

Builds an AQL expression that checks whether a value is a valid date string.

isDateString(string $value) : string

This helper wraps the ArangoDB AQL function IS_DATESTRING(), which tests if the given value is a string that can be used in a date function.

The function returns true for properly formatted date strings (e.g. "2015", "2015-10", "2015-10-07T15:32:10Z") even if the actual date value is invalid (e.g. "2015-02-31").

Example AQL output:

IS_DATESTRING(doc.createdAt)
Parameters
$value : string

The AQL field or expression to check (e.g. 'doc.createdAt').

Tags
example
use function oihana\arango\db\functions\isDateString;

$expr = isDateString('doc.createdAt');
// Produces: 'IS_DATESTRING(doc.createdAt)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_datestring
since
1.0.0
author

Marc Alcaraz

Return values
string

The AQL expression as a string (e.g. 'IS_DATESTRING(doc.createdAt)').

isKey()

Builds an AQL expression that checks whether a value is a valid document key.

isKey(string $value) : string

This helper wraps the ArangoDB AQL function IS_KEY(), which tests if the given value is a string that can be used as the _key attribute of a document.

The function returns true if the string matches ArangoDB’s key format rules:

  • Contains only letters, digits, and the characters _, -, :, or @.
  • Does not contain /, whitespace, or control characters.
  • Must not be empty.

Example AQL output:

IS_KEY(user._key)
Parameters
$value : string

The AQL field or string expression to check (e.g. 'user._key').

Tags
example
use function oihana\arango\db\functions\isKey;

$expr = isKey('user._key');
// Produces: 'IS_KEY(user._key)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_key
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'IS_KEY(user._key)').

isNull()

Builds an AQL expression that checks whether a value is `null`.

isNull(string $value) : string

This helper wraps the ArangoDB AQL function IS_NULL(), which returns true if the given value is null, and false otherwise.

Example AQL output:

IS_NULL(user.email)
Parameters
$value : string

The AQL field or expression to check (e.g. 'user.email').

Tags
example
use function oihana\arango\db\functions\isNull;

$expr = isNull('user.email');
// Produces: 'IS_NULL(user.email)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_null
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'IS_NULL(user.email)').

isNumber()

Builds an AQL expression that checks whether a value is a number.

isNumber(string $value) : string

This helper wraps the ArangoDB AQL function IS_NUMBER(), which returns true if the given value is a numeric type, and false otherwise.

Example AQL output:

IS_NUMBER(doc.age)
Parameters
$value : string

The AQL field or expression to check (e.g. 'doc.age').

Tags
example
use function oihana\arango\db\functions\isNumber;

$expr = isNumber('doc.age');
// Produces: 'IS_NUMBER(doc.age)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_number
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'IS_NUMBER(doc.age)').

isObject()

Builds an AQL expression that checks whether a value is an object/document.

isObject(string $value) : string

This helper wraps the ArangoDB AQL function IS_OBJECT(), which returns true if the provided value is an object (e.g., a document in AQL), and false otherwise.

Example AQL output:

IS_OBJECT(doc.user)
Parameters
$value : string

The AQL field or expression to check (e.g., 'doc.user').

Tags
example
use function oihana\arango\db\functions\isObject;

$expr = isObject('doc.user');
// Produces: 'IS_OBJECT(doc.user)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_object
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'IS_OBJECT(doc.user)').

isString()

Builds an AQL expression that checks whether a value is a string.

isString(string $value) : string

This helper wraps the ArangoDB AQL function IS_STRING(), which returns true if the provided value is a string, and false otherwise.

Example AQL output:

IS_STRING(doc.title)
Parameters
$value : string

The AQL field or expression to check (e.g., 'doc.title').

Tags
example
use function oihana\arango\db\functions\isString;

$expr = isString('doc.title');
// Produces: 'IS_STRING(doc.title)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#is_string
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'IS_STRING(doc.title)').

length()

Determine the amount of documents in a collection.

length(mixed $collection) : string

This helper wraps the ArangoDB AQL function LENGTH().

Example AQL output:

LENGTH(coll)
Parameters
$collection : mixed
Tags
example
use function oihana\arango\db\functions\length;

$expr = length('coll');
// Produces: 'LENGTH(coll)'

LENGTH() can also determine the number of elements in an array, the number of attribute keys of an object / document and the character length of a string.

see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#length
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'LENGTH(coll)').

notNull()

Builds an AQL expression return the first element that is not null, and null if all alternatives are null themselves.

notNull(mixed ...$alternative) : string

It is also known as COALESCE() in SQL.

This helper wraps the ArangoDB AQL function NOT_NULL().

Example AQL output:

RETURN NOT_NULL(null, null, "foo", "bar") // "foo"
Parameters
$alternative : mixed

input of arbitrary type

Tags
example
use function oihana\arango\db\functions\notNull;

$expr = notNull('user.email');
// Produces: 'NOT_NULL(user.email)'
see
https://docs.arangodb.com/stable/aql/functions/miscellaneous/#not_null
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g. 'NOT_NULL(user.email)').

toArray()

Converts a value of any type into an array.

toArray(mixed $value) : string

This helper wraps the ArangoDB AQL function TO_ARRAY(), which casts the provided value to an array. If the value is already an array, it is returned as is; otherwise, it will be wrapped in a single-element array.

Example AQL usage:

TO_ARRAY(doc.tags)   // returns doc.tags as an array
TO_ARRAY("single")   // returns ["single"]
Parameters
$value : mixed

The AQL field or expression to convert to an array.

Tags
example
use function oihana\arango\db\functions\toArray;

$expr = toArray('doc.items');
// Produces: 'TO_ARRAY(doc.items)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#to_array
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TO_ARRAY(doc.items)').

toBool()

Converts a value of any type into a boolean.

toBool(mixed $value) : string

This helper wraps the ArangoDB AQL function TO_BOOL(), which casts the provided value to a boolean. The conversion rules follow AQL semantics:

  • Non-zero numbers and non-empty strings evaluate to true.
  • Zero, empty strings, null, and empty arrays evaluate to false.

Example AQL usage:

TO_BOOL(doc.isActive)   // converts doc.isActive to boolean
TO_BOOL("")             // returns false
TO_BOOL(1)              // returns true
Parameters
$value : mixed

The AQL field or expression to convert to boolean.

Tags
example
use function oihana\arango\db\functions\toBool;

$expr = toBool('doc.isActive');
// Produces: 'TO_BOOL(doc.isActive)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#to_bool
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TO_BOOL(doc.isActive)').

toNumber()

Converts a value of any type into a numeric value.

toNumber(mixed $value) : string

This helper wraps the ArangoDB AQL function TO_NUMBER(), which casts the provided value to a number. Conversion rules follow AQL semantics:

  • Strings containing numeric representations are converted to numbers.
  • Boolean true becomes 1, false becomes 0.
  • null is converted to 0.

Example AQL usage:

TO_NUMBER("42")       // returns 42
TO_NUMBER(doc.count)  // converts the doc.count field to a number
TO_NUMBER(true)       // returns 1
TO_NUMBER(null)       // returns 0
Parameters
$value : mixed

The AQL field or expression to convert to a number.

Tags
example
use function oihana\arango\db\functions\toNumber;

$expr = toNumber('doc.age');
// Produces: 'TO_NUMBER(doc.age)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#to_number
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TO_NUMBER(doc.age)').

toString()

Converts a value of any type into a string.

toString(mixed $value) : string

This helper wraps the ArangoDB AQL function TO_STRING(), which casts the provided value to a string. Conversion rules follow AQL semantics:

  • Numbers are converted to their string representation.
  • Boolean true becomes 'true', false becomes 'false'.
  • null is converted to an empty string ''.

Example AQL usage:

TO_STRING(42)        // returns "42"
TO_STRING(doc.name)  // converts the doc.name field to a string
TO_STRING(true)      // returns "true"
TO_STRING(null)      // returns ""
Parameters
$value : mixed

The AQL field or expression to convert to a string.

Tags
example
use function oihana\arango\db\functions\toString;

$expr = toString('doc.age');
// Produces: 'TO_STRING(doc.age)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#to_string
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TO_STRING(doc.age)').

typeName()

Returns the data type name of the given value in AQL.

typeName(mixed $value) : string

This helper wraps the ArangoDB AQL function TYPENAME(), which returns a string representing the type of the provided value.

Possible return values:

  • "null"
  • "bool"
  • "number"
  • "string"
  • "array"
  • "object"

Example AQL output:

TYPENAME(doc.age)  // "number"
Parameters
$value : mixed

The AQL field or expression to evaluate.

Tags
example
use function oihana\arango\db\functions\typeName;

$expr = typeName('doc.age');
// Produces: 'TYPENAME(doc.age)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#typename
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TYPENAME(doc.age)').

On this page

Search results