Skip to content

Commit

Permalink
Added WINDOW documentation
Browse files Browse the repository at this point in the history
Fixed merge function: variable/reference/Expression arguments are allowed again.
  • Loading branch information
LaravelFreelancerNL committed Oct 19, 2021
1 parent d540417 commit f0748f8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
25 changes: 25 additions & 0 deletions docs/api/query-clauses.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ FOR user IN users

[ArangoDB AGGREGATE documentation](https://www.arangodb.com/docs/stable/aql/operations-collect.html#aggregation)

## WINDOW
```
window(
array|object $offsets,
string|QueryBuilder|Expression $rangeValue = null
)
```
Aggregate adjacent documents or value ranges with a sliding window
to calculate running totals, rolling averages, and other statistical properties

**Example 1:**
```php
$qb->window(['preceding' => 5, 'following' => 10])
```
Resulting AQL: `... WINDOW { "preceding": 5, "following": 10 } ...`

**Example 2: using range-based aggregation**
```php
$qb->window(['preceding' => 5, 'following' => 10], 't.time')
```
Resulting AQL: `... WINDOW t.time WITH { "preceding": 5, "following": 10 } ...`

[ArangoDB WINDOW documentation](https://www.arangodb.com/docs/stable/aql/operations-window.html)


## Other clauses

### OPTIONS
Expand Down
4 changes: 2 additions & 2 deletions src/AQL/HasDocumentFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public function matches(
*
* @link https://www.arangodb.com/docs/stable/aql/functions-document.html#merge
*
* @param array<mixed> $documents
* @param array<mixed>|string|Expression $documents
* @return FunctionExpression
*/
public function merge(array ...$documents): FunctionExpression
public function merge(string|array|Expression ...$documents): FunctionExpression
{
return new FunctionExpression('MERGE', $documents);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/AQL/DocumentFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ public function testMerge()
self::assertEquals('RETURN MERGE({"user1":{"name":"Janet"}}, {"user2":{"name":"Tom"}})', $qb->get()->query);
}

public function testMergeVariable()
{
$qb = new QueryBuilder();

$qb->for('u', 'users')
->return(
$qb->merge(
'u',
[
'user1' => ['name' => 'Janet']
],
[
'user2' => ['name' => 'Tom']
]
)
);

self::assertEquals(
'FOR u IN users RETURN MERGE(u, {"user1":{"name":"Janet"}}, {"user2":{"name":"Tom"}})',
$qb->get()->query
);
}

public function testMergeWithArrayOfDocuments()
{
$qb = new QueryBuilder();
Expand Down

0 comments on commit f0748f8

Please sign in to comment.