Add addLast() function
This commit is contained in:
parent
2257e4f9cd
commit
3d32bdb45d
6 changed files with 100 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
.idea
|
||||
composer.phar
|
||||
/vendor/
|
||||
.phpunit.result.cache
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ or [fromBucket()](functions/fromBucket.md)
|
|||
or [addRangeInBetween()](functions/addRangeInBetween.md)
|
||||
* [addReduce()](functions/addReduce.md)
|
||||
* [addSum()](functions/addSum.md)
|
||||
* [addLast()](functions/addLast.md)
|
||||
|
||||
Anything missing here? You can use this method to add anything to the query:
|
||||
* [addRawFunction()](functions/addRawFunction.md)
|
||||
39
docs/functions/addLast.md
Normal file
39
docs/functions/addLast.md
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Flux Query Builder Docs
|
||||
|
||||
## Functions » addLast()
|
||||
|
||||
### Parameters:
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Required</th>
|
||||
<th>Data type</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>column</td>
|
||||
<td>No</td>
|
||||
<td>string</td>
|
||||
<td>Column to use to verify the existence of a value. Default is "_value".</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```php
|
||||
->addLast('something')
|
||||
```
|
||||
|
||||
This will result in the following Flux function part:
|
||||
|
||||
```
|
||||
|> last(column: "something")
|
||||
```
|
||||
|
||||
### Extra resources
|
||||
|
||||
* [Flux documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/last/)
|
||||
|
|
@ -5,6 +5,7 @@ namespace Arendsen\FluxQueryBuilder\Builder;
|
|||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
||||
|
|
@ -103,4 +104,12 @@ trait Universe
|
|||
);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addLast(string $column = '_value'): QueryBuilderInterface
|
||||
{
|
||||
$this->addToQuery(
|
||||
new Last($column)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
21
src/Functions/Last.php
Normal file
21
src/Functions/Last.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
class Last extends Base
|
||||
{
|
||||
/**
|
||||
* @var int $column
|
||||
*/
|
||||
private $column;
|
||||
|
||||
public function __construct(string $column = '_value')
|
||||
{
|
||||
$this->column = $column;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> last(column: ' . (string)$this->column . ') ';
|
||||
}
|
||||
}
|
||||
29
tests/Functions/LastFunctionTest.php
Normal file
29
tests/Functions/LastFunctionTest.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LastFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleLast()
|
||||
{
|
||||
$expression = new Last();
|
||||
|
||||
$query = '|> last(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
|
||||
public function testLastWithValue()
|
||||
{
|
||||
$expression = new Last('something');
|
||||
|
||||
$query = '|> last(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue