Oihana PHP Arango

aqlDocument.php

Table of Contents

Functions

aqlDocument()  : string
Generate a document expression for ArangoDB AQL.

Functions

aqlDocument()

Generate a document expression for ArangoDB AQL.

aqlDocument([object|array<string|int, mixed>|string|null $keyValues = [] ][, array<string|int, mixed> $options = [] ]) : string

Accepts:

  • associative arrays: ['key' => value, ...]
  • indexed arrays of [key, value] pairs: [['key', value], ...]
  • objects: converted to associative arrays
  • strings: returned as-is inside braces
  • null: returns '}'

Options can be passed as an associative array:

  • 'useSpace' : bool, add spaces around braces and after commas
  • 'rawValues' : array, keys whose values should be treated as raw AQL expressions
  • 'rawKeys' : array, keys which should be kept raw (their values are not wrapped or converted)
Parameters
$keyValues : object|array<string|int, mixed>|string|null = []

Array of key-value pairs, associative array, object, string, or null

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

Optional settings: ['useSpace'=>bool, 'rawValues'=>array, 'rawKeys'=>array]

Tags
throws
InvalidArgumentException

If array structure is invalid

UnsupportedOperationException

If a value type is unsupported.

example

Simple associative array

echo document([ '_from'=>'u._id', '_to'=>'p._id' ]);
// {_from:u._id,_to:p._id}

Add spaces around braces and commas

echo document([ '_from'=>'u._id', '_to'=>'p._id' ], ['useSpace'=>true]);
// { _from:u._id, _to:p._id }

Using raw values for AQL expressions

echo document([ '_key'=>"CONCAT('test', i)", 'name'=>"test", 'foobar'=>true ],
['useSpace'=>true, 'rawValues'=>['_key']]);
// { _key: CONCAT('test', i), name:'test', foobar:true }

Forcing keys to be raw

echo document([ 'custom'=> 'something' ], ['rawKeys'=>['custom']]);
// {custom:something}

Nested associative array

echo document(['user'=>['name'=>'Eka','age'=>47],'active'=>true]);
// {user:{name:'Eka',age:47},active:true}

Indexed arrays (lists)

echo document(['tags'=>['php','js'],'scores'=>[10,20,30]]);
// {tags:['php','js'],scores:[10,20,30]}

Object input

$obj = (object)['name'=>'Eka','age'=>47];
echo document($obj);
// {name:'Eka',age:47}

Preformatted string

echo document("foo:'bar'");
// {foo:'bar'}

Null or empty

echo document(null);
// }
echo document([], ['useSpace'=>true]);
// { }
author

Marc Alcaraz

since
1.0.0
Return values
string

JS-like object expression for AQL

On this page

Search results