Add addCount, addFirst, addMax, and addMin functions
Signed-off-by: David Arendsen <darendsen@gamepoint.com>
This commit is contained in:
parent
b7e0b21c8f
commit
fc99922700
15 changed files with 463 additions and 23 deletions
29
tests/Functions/CountFunctionTest.php
Normal file
29
tests/Functions/CountFunctionTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CountFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleCount()
|
||||
{
|
||||
$expression = new Count();
|
||||
|
||||
$query = '|> count() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
|
||||
public function testCountWithColumn()
|
||||
{
|
||||
$expression = new Count('_value');
|
||||
|
||||
$query = '|> count(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
}
|
||||
29
tests/Functions/FirstFunctionTest.php
Normal file
29
tests/Functions/FirstFunctionTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FirstFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleFirst()
|
||||
{
|
||||
$expression = new First();
|
||||
|
||||
$query = '|> first() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
|
||||
public function testFirstWithColumn()
|
||||
{
|
||||
$expression = new First('something');
|
||||
|
||||
$query = '|> first(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
}
|
||||
29
tests/Functions/MaxFunctionTest.php
Normal file
29
tests/Functions/MaxFunctionTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Max;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MaxFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMax()
|
||||
{
|
||||
$expression = new Max();
|
||||
|
||||
$query = '|> max() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
|
||||
public function testMaxWithColumn()
|
||||
{
|
||||
$expression = new Max('something');
|
||||
|
||||
$query = '|> max(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
}
|
||||
29
tests/Functions/MinFunctionTest.php
Normal file
29
tests/Functions/MinFunctionTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Min;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MinFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMin()
|
||||
{
|
||||
$expression = new Min();
|
||||
|
||||
$query = '|> min() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
|
||||
public function testMinWithColumn()
|
||||
{
|
||||
$expression = new Min('something');
|
||||
|
||||
$query = '|> min(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,11 @@ final class QueryBuilderTest extends TestCase
|
|||
['20s', 'mean', ['timeDst' => '_time']],
|
||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||
],
|
||||
'addCount' => [
|
||||
'addCount',
|
||||
['_value'],
|
||||
'|> count(column: "_value") '
|
||||
],
|
||||
'addDuplicate' => [
|
||||
'addDuplicate',
|
||||
['old_name', 'new_name'],
|
||||
|
|
@ -61,6 +66,11 @@ final class QueryBuilderTest extends TestCase
|
|||
[['email', 'username']],
|
||||
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
|
||||
],
|
||||
'addFirst' => [
|
||||
'addFirst',
|
||||
['something'],
|
||||
'|> first(column: "something") '
|
||||
],
|
||||
'addGroup' => [
|
||||
'addGroup',
|
||||
[['_field', 'ip']],
|
||||
|
|
@ -81,10 +91,20 @@ final class QueryBuilderTest extends TestCase
|
|||
['r with name: r.user'],
|
||||
'|> map(fn: (r) => ({ r with name: r.user })) '
|
||||
],
|
||||
'addMax' => [
|
||||
'addMax',
|
||||
[],
|
||||
'|> max() '
|
||||
],
|
||||
'addMean' => [
|
||||
'addMean',
|
||||
[],
|
||||
'|> mean() '
|
||||
['something'],
|
||||
'|> mean(column: "something") '
|
||||
],
|
||||
'addMin' => [
|
||||
'addMin',
|
||||
['something'],
|
||||
'|> min(column: "something") '
|
||||
],
|
||||
'addRawFunction' => [
|
||||
'addRawFunction',
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue