Marks fork as 2.0.0.
This commit is contained in:
parent
d93a6b5c09
commit
8d8de4a2b0
81 changed files with 1921 additions and 3954 deletions
45
.github/workflows/php.yml
vendored
45
.github/workflows/php.yml
vendored
|
|
@ -1,45 +0,0 @@
|
||||||
name: Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ main ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-18.04
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: "Set up PHP"
|
|
||||||
uses: "shivammathur/setup-php@v2"
|
|
||||||
with:
|
|
||||||
php-version: "7.2"
|
|
||||||
coverage: "none"
|
|
||||||
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Validate composer.json and composer.lock
|
|
||||||
run: composer validate --strict
|
|
||||||
|
|
||||||
- name: Cache Composer packages
|
|
||||||
id: composer-cache
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: vendor
|
|
||||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-php-
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: composer install --prefer-dist --no-progress
|
|
||||||
|
|
||||||
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
|
|
||||||
# Docs: https://getcomposer.org/doc/articles/scripts.md
|
|
||||||
|
|
||||||
- name: Run test suite
|
|
||||||
run: composer run-script test
|
|
||||||
|
|
||||||
- name: Check coding style according to PSR-12
|
|
||||||
run: composer run-script check
|
|
||||||
4
LICENSE
4
LICENSE
|
|
@ -1,6 +1,8 @@
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2022 - 2023 David Arendsen
|
Copyright (c)
|
||||||
|
* 2022 - 2023 David Arendsen
|
||||||
|
* 2024 Hosterra / Pierre Lannoy
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|
|
||||||
25
README.md
25
README.md
|
|
@ -1,20 +1,14 @@
|
||||||
# Flux Query Builder
|
# Flux Query Builder
|
||||||
|
|
||||||
With this query builder you can build queries for Flux. Flux is a powerful open source query language created by the makers of InfluxDB. See https://www.influxdata.com/products/flux/
|
Flux Query Builder is a package to build [Flux](https://www.influxdata.com/products/flux/) queries in PHP.
|
||||||
|
|
||||||
[](https://packagist.org/packages/arendsen/fluxquerybuilder)
|
>Note: this package is a fork of the David Arendsen [fluxquerybuilder](https://github.com/davidarendsen/fluxquerybuilder) package; original credits go to him.
|
||||||
[](https://packagist.org/packages/arendsen/fluxquerybuilder)
|
|
||||||
[](https://packagist.org/packages/arendsen/fluxquerybuilder)
|
|
||||||
|
|
||||||
[](https://github.com/davidarendsen/fluxquerybuilder/actions/workflows/php.yml)
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
The documentation of this project is available in the [docs folder](docs/00-index.md).
|
The documentation of this project is available in the [docs folder](docs/00-index.md).
|
||||||
|
|
||||||
Go directly to our [Getting started page](docs/01-getting-started.md)
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
You're welcome to contribute to this project, but please add tests and follow the coding style.
|
You're welcome to contribute to this project, but please add tests.
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
To execute the testing suite:
|
To execute the testing suite:
|
||||||
|
|
@ -22,16 +16,3 @@ To execute the testing suite:
|
||||||
```
|
```
|
||||||
composer test
|
composer test
|
||||||
```
|
```
|
||||||
|
|
||||||
### Coding style
|
|
||||||
|
|
||||||
Run the following commands to check and fix the coding style. We're using the PSR12 standard.
|
|
||||||
|
|
||||||
```
|
|
||||||
composer check
|
|
||||||
composer format
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This software is released under the [MIT license](LICENSE).
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "hosterra/fluxbuilder",
|
"name": "hosterra/fluxbuilder",
|
||||||
"description": "A package to build Flux queries in PHP.",
|
"description": "A package to build Flux queries with PHP.",
|
||||||
"keywords": [ "influxdb", "flux" ],
|
"keywords": [ "influxdb", "flux" ],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Arendsen\\FluxQueryBuilder\\": "src/",
|
"Hosterra\\FluxBuilder\\": "src/",
|
||||||
"Tests\\": "tests/"
|
"Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.2"
|
"php": ">=8.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^8",
|
"phpunit/phpunit": "^8",
|
||||||
|
|
|
||||||
1490
composer.lock
generated
1490
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,22 +0,0 @@
|
||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
code:
|
|
||||||
image: busybox
|
|
||||||
command: /bin/true
|
|
||||||
container_name: fluxquerybuilder
|
|
||||||
networks:
|
|
||||||
- api
|
|
||||||
|
|
||||||
php:
|
|
||||||
build: ./docker/php
|
|
||||||
container_name: fluxquerybuilder_php
|
|
||||||
volumes:
|
|
||||||
- ./:/var/www
|
|
||||||
networks:
|
|
||||||
- api
|
|
||||||
|
|
||||||
|
|
||||||
networks:
|
|
||||||
api:
|
|
||||||
driver: bridge
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
FROM php:7.2-cli
|
|
||||||
COPY . /var/www
|
|
||||||
WORKDIR /var/www
|
|
||||||
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y \
|
|
||||||
curl \
|
|
||||||
git \
|
|
||||||
gnupg \
|
|
||||||
unzip
|
|
||||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
Install the package with composer:
|
Install the package with composer:
|
||||||
```
|
```
|
||||||
composer require arendsen/fluxquerybuilder
|
composer require hosterra/fluxbuilder
|
||||||
```
|
```
|
||||||
|
|
||||||
The most basic Flux query can be made with the following code. It has filters for fields and tags.
|
The most basic Flux query can be made with the following code. It has filters for fields and tags.
|
||||||
|
|
@ -12,8 +12,8 @@ The most basic Flux query can be made with the following code. It has filters fo
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
use Hosterra\FluxBuilder\QueryBuilder;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||||
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
$queryBuilder->fromBucket('test_bucket')
|
$queryBuilder->fromBucket('test_bucket')
|
||||||
|
|
@ -35,12 +35,8 @@ Which will result in the following Flux query:
|
||||||
from(bucket: "test_bucket")
|
from(bucket: "test_bucket")
|
||||||
|> range(start: time(v: 2022-12-28T13:21:11Z))
|
|> range(start: time(v: 2022-12-28T13:21:11Z))
|
||||||
|> filter(fn: (r) => r._measurement == "test_measurement")
|
|> filter(fn: (r) => r._measurement == "test_measurement")
|
||||||
|> filter(fn: (r) =>
|
|> filter(fn: (r) => r._field == "username" or r._field == "email" )
|
||||||
r._field == "username" or r._field == "email"
|
|> filter(fn: (r) => r.username == "David" and r.email == "david@example.com" )
|
||||||
)
|
|
||||||
|> filter(fn: (r) =>
|
|
||||||
r.username == "David" and r.email == "david@example.com"
|
|
||||||
)
|
|
||||||
|> limit(n: 50, offset: 100)
|
|> limit(n: 50, offset: 100)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,6 @@ Since InfluxDB2 they introduced this new Flux query language. Coming from a SQL
|
||||||
```js
|
```js
|
||||||
from(bucket: "example-bucket")
|
from(bucket: "example-bucket")
|
||||||
|> range(start: -1h)
|
|> range(start: -1h)
|
||||||
|> filter(fn: (r) =>
|
|> filter(fn: (r) => r._measurement == "example-measurement" and r.tag == "example-tag" )
|
||||||
r._measurement == "example-measurement"
|
|
||||||
and r.tag == "example-tag"
|
|
||||||
)
|
|
||||||
|> filter(fn: (r) => r._field == "example-field")
|
|> filter(fn: (r) => r._field == "example-field")
|
||||||
```
|
```
|
||||||
|
|
@ -92,7 +92,7 @@ This will result in the following Flux function part:
|
||||||
### Advanced example
|
### Advanced example
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
use Hosterra\FluxBuilder\Type\FnType;
|
||||||
|
|
||||||
->addAggregateWindow(
|
->addAggregateWindow(
|
||||||
'20s',
|
'20s',
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```php
|
```php
|
||||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
use Hosterra\FluxBuilder\Type\MathType;
|
||||||
```
|
```
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|
|
||||||
|
|
@ -1,114 +1,93 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Builder;
|
namespace Hosterra\FluxBuilder\Builder;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
use Hosterra\FluxBuilder\QueryBuilder;
|
||||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
use Hosterra\FluxBuilder\Functions\Filter;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
use Hosterra\FluxBuilder\Functions\From;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\From;
|
use Hosterra\FluxBuilder\Functions\Measurement;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Measurement;
|
use Hosterra\FluxBuilder\Functions\Range;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Range;
|
use Hosterra\FluxBuilder\Functions\RawFunction;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\RawFunction;
|
|
||||||
|
|
||||||
trait Basics
|
trait Basics {
|
||||||
{
|
public function from( array $from ): QueryBuilderInterface {
|
||||||
public function from(array $from): QueryBuilderInterface
|
|
||||||
{
|
|
||||||
$this->setRequirements();
|
$this->setRequirements();
|
||||||
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new From($from)
|
new From( $from )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromBucket(string $bucket): QueryBuilderInterface
|
public function fromBucket( string $bucket ): QueryBuilderInterface {
|
||||||
{
|
return $this->from( [ 'bucket' => $bucket ] );
|
||||||
return $this->from(['bucket' => $bucket]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromMeasurement(string $measurement): QueryBuilderInterface
|
public function fromMeasurement( string $measurement ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->setRequirements();
|
$this->setRequirements();
|
||||||
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Measurement($measurement)
|
new Measurement( $measurement )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function addKeyFilter( KeyFilter $keyFilter ): QueryBuilderInterface {
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param KeyValue $keyValue
|
|
||||||
* @return QueryBuilder
|
|
||||||
*/
|
|
||||||
public function addFilter(KeyValue $keyValue): QueryBuilderInterface
|
|
||||||
{
|
|
||||||
$this->setRequirements();
|
$this->setRequirements();
|
||||||
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Filter($keyValue)
|
new Filter( $keyFilter )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addKeyFilter(KeyFilter $keyFilter): QueryBuilderInterface
|
public function addFieldFilter( array $fields ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->setRequirements();
|
$this->setRequirements();
|
||||||
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Filter($keyFilter)
|
new Filter( $fields )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFieldFilter(array $fields): QueryBuilderInterface
|
public function addRange( DateTime $start, ?DateTime $stop = null ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->setRequirements();
|
$this->setRequirements();
|
||||||
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Filter($fields)
|
new Range( $start, $stop )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRange(DateTime $start, ?DateTime $stop = null): QueryBuilderInterface
|
public function addRangeStart( DateTime $start ): QueryBuilderInterface {
|
||||||
{
|
$this->addRange( $start );
|
||||||
$this->setRequirements();
|
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRangeInBetween( DateTime $start, DateTime $stop ): QueryBuilderInterface {
|
||||||
|
$this->addRange( $start, $stop );
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRawFunction( string $input ): QueryBuilderInterface {
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Range($start, $stop)
|
new RawFunction( $input )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRangeStart(DateTime $start): QueryBuilderInterface
|
private function setRequirements() {
|
||||||
{
|
|
||||||
$this->addRange($start);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addRangeInBetween(DateTime $start, DateTime $stop): QueryBuilderInterface
|
|
||||||
{
|
|
||||||
$this->addRange($start, $stop);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addRawFunction(string $input): QueryBuilderInterface
|
|
||||||
{
|
|
||||||
$this->addToQuery(
|
|
||||||
new RawFunction($input)
|
|
||||||
);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setRequirements()
|
|
||||||
{
|
|
||||||
$this->requiredFluxQueryParts = [
|
$this->requiredFluxQueryParts = [
|
||||||
From::class,
|
From::class,
|
||||||
Range::class,
|
Range::class,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Builder;
|
namespace Hosterra\FluxBuilder\Builder;
|
||||||
|
|
||||||
interface QueryBuilderInterface
|
interface QueryBuilderInterface {
|
||||||
{
|
|
||||||
public function build(): string;
|
public function build(): string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,167 +1,166 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Builder;
|
namespace Hosterra\FluxBuilder\Builder;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
use Hosterra\FluxBuilder\Functions\AggregateWindow;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Bottom;
|
use Hosterra\FluxBuilder\Functions\Bottom;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
use Hosterra\FluxBuilder\Functions\Count;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
use Hosterra\FluxBuilder\Functions\Duplicate;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
use Hosterra\FluxBuilder\Functions\First;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
use Hosterra\FluxBuilder\Functions\Group;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
use Hosterra\FluxBuilder\Functions\Last;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
use Hosterra\FluxBuilder\Functions\Limit;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
use Hosterra\FluxBuilder\Functions\Map;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Max;
|
use Hosterra\FluxBuilder\Functions\Max;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Mean;
|
use Hosterra\FluxBuilder\Functions\Mean;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Min;
|
use Hosterra\FluxBuilder\Functions\Min;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
use Hosterra\FluxBuilder\Functions\Reduce;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
use Hosterra\FluxBuilder\Functions\Sort;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Sum;
|
use Hosterra\FluxBuilder\Functions\Sum;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Unique;
|
use Hosterra\FluxBuilder\Functions\Unique;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Window;
|
use Hosterra\FluxBuilder\Functions\Window;
|
||||||
|
|
||||||
trait Universe
|
trait Universe {
|
||||||
{
|
public function addAggregateWindow( $every, $fn, array $options = [] ): QueryBuilderInterface {
|
||||||
public function addAggregateWindow($every, $fn, array $options = []): QueryBuilderInterface
|
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new AggregateWindow($every, $fn, $options)
|
new AggregateWindow( $every, $fn, $options )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addBottom(int $n, array $columns = []): QueryBuilderInterface
|
public function addBottom( int $n, array $columns = [] ): QueryBuilderInterface {
|
||||||
{
|
$this->addToQuery( new Bottom( $n, $columns ) );
|
||||||
$this->addToQuery(new Bottom($n, $columns));
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addCount(?string $column = null): QueryBuilderInterface
|
public function addCount( ?string $column = null ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Count($column)
|
new Count( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addDuplicate(string $column, string $as): QueryBuilderInterface
|
public function addDuplicate( string $column, string $as ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Duplicate($column, $as)
|
new Duplicate( $column, $as )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFirst(?string $column = null): QueryBuilderInterface
|
public function addFirst( ?string $column = null ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new First($column)
|
new First( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addGroup(array $columns, $mode = 'by'): QueryBuilderInterface
|
public function addGroup( array $columns, $mode = 'by' ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Group($columns, $mode)
|
new Group( $columns, $mode )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addLast(string $column = '_value'): QueryBuilderInterface
|
public function addLast( string $column = '_value' ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Last($column)
|
new Last( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addLimit(int $limit, int $offset = 0): QueryBuilderInterface
|
public function addLimit( int $limit, int $offset = 0 ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Limit($limit, $offset)
|
new Limit( $limit, $offset )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMap($query): QueryBuilderInterface
|
public function addMap( $query ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Map($query)
|
new Map( $query )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMax(?string $column = null): QueryBuilderInterface
|
public function addMax( ?string $column = null ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Max($column)
|
new Max( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMean(?string $column = ''): QueryBuilderInterface
|
public function addMean( ?string $column = '' ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Mean($column)
|
new Mean( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addMin(?string $column = null): QueryBuilderInterface
|
public function addMin( ?string $column = null ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Min($column)
|
new Min( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addReduce(array $settings, array $identity): QueryBuilderInterface
|
public function addReduce( array $settings, array $identity ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Reduce($settings, $identity)
|
new Reduce( $settings, $identity )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSort(array $columns = ['_value'], bool $desc = false): QueryBuilderInterface
|
public function addSort( array $columns = [ '_value' ], bool $desc = false ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Sort($columns, $desc)
|
new Sort( $columns, $desc )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSum(string $column): QueryBuilderInterface
|
public function addSum( string $column ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Sum($column)
|
new Sum( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addUnique(?string $column = null): QueryBuilderInterface
|
public function addUnique( ?string $column = null ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Unique($column)
|
new Unique( $column )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addUnWindow(): QueryBuilderInterface
|
public function addUnWindow(): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Window('inf')
|
new Window( 'inf' )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addWindow($every, array $options = []): QueryBuilderInterface
|
public function addWindow( $every, array $options = [] ): QueryBuilderInterface {
|
||||||
{
|
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
new Window($every, $options)
|
new Window( $every, $options )
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
namespace Hosterra\FluxBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class ExpressionNotImplementedException extends Exception
|
class ExpressionNotImplementedException extends Exception {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
namespace Hosterra\FluxBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class FunctionInvalidInputException extends Exception
|
class FunctionInvalidInputException extends Exception {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
namespace Hosterra\FluxBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class FunctionNotImplementedException extends Exception
|
class FunctionNotImplementedException extends Exception {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
namespace Hosterra\FluxBuilder\Exception;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class FunctionRequiredSettingMissingException extends Exception
|
class FunctionRequiredSettingMissingException extends Exception {
|
||||||
{
|
public function __construct( string $functionName, string $message ) {
|
||||||
public function __construct(string $functionName, string $message)
|
parent::__construct( 'Function ' . $functionName . ' - ' . $message );
|
||||||
{
|
|
||||||
parent::__construct('Function ' . $functionName . ' - ' . $message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
namespace Hosterra\FluxBuilder\Expression;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Exception\ExpressionNotImplementedException;
|
use Hosterra\FluxBuilder\Exception\ExpressionNotImplementedException;
|
||||||
|
|
||||||
abstract class Base
|
abstract class Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @throws ExpressionNotImplementedException
|
* @throws ExpressionNotImplementedException
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
throw new ExpressionNotImplementedException( '__toString', get_class( $this ) );
|
||||||
throw new ExpressionNotImplementedException('__toString', get_class($this));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
namespace Hosterra\FluxBuilder\Expression;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class KeyFilter extends Base
|
class KeyFilter extends Base {
|
||||||
{
|
|
||||||
public const EQUAL_TO = '==';
|
public const EQUAL_TO = '==';
|
||||||
public const NOT_EQUAL_TO = '!=';
|
public const NOT_EQUAL_TO = '!=';
|
||||||
public const GREATER_THAN = '>';
|
public const GREATER_THAN = '>';
|
||||||
|
|
@ -32,176 +31,164 @@ class KeyFilter extends Base
|
||||||
*/
|
*/
|
||||||
private $expressions;
|
private $expressions;
|
||||||
|
|
||||||
private function __construct(string $key, string $operator, $value)
|
private function __construct( string $key, string $operator, $value ) {
|
||||||
{
|
$this->checkOperator( $operator );
|
||||||
$this->checkOperator($operator);
|
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type( $value );
|
||||||
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function set(string $key, string $operator, $value): KeyFilter
|
public static function set( string $key, string $operator, $value ): KeyFilter {
|
||||||
{
|
return new self( $key, $operator, $value );
|
||||||
return new self($key, $operator, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setEqualTo(string $key, string $value): KeyFilter
|
public static function setEqualTo( string $key, string $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::EQUAL_TO, $value );
|
||||||
return self::set($key, self::EQUAL_TO, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setNotEqualTo(string $key, string $value): KeyFilter
|
public static function setNotEqualTo( string $key, string $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::NOT_EQUAL_TO, $value );
|
||||||
return self::set($key, self::NOT_EQUAL_TO, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setGreaterThan(string $key, int $value): KeyFilter
|
public static function setGreaterThan( string $key, int $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::GREATER_THAN, $value );
|
||||||
return self::set($key, self::GREATER_THAN, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setGreaterOrEqualTo(string $key, int $value): KeyFilter
|
public static function setGreaterOrEqualTo( string $key, int $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::GREATER_EQUAL_TO, $value );
|
||||||
return self::set($key, self::GREATER_EQUAL_TO, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setLessThan(string $key, int $value): KeyFilter
|
public static function setLessThan( string $key, int $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::LESS_THAN, $value );
|
||||||
return self::set($key, self::LESS_THAN, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setLessOrEqualTo(string $key, int $value): KeyFilter
|
public static function setLessOrEqualTo( string $key, int $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::LESS_EQUAL_TO, $value );
|
||||||
return self::set($key, self::LESS_EQUAL_TO, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setEqualToRegex(string $key, string $value): KeyFilter
|
public static function setEqualToRegex( string $key, string $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::EQUAL_TO_REGEX, $value );
|
||||||
return self::set($key, self::EQUAL_TO_REGEX, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setNotEqualToRegex(string $key, string $value): KeyFilter
|
public static function setNotEqualToRegex( string $key, string $value ): KeyFilter {
|
||||||
{
|
return self::set( $key, self::NOT_EQUAL_TO_REGEX, $value );
|
||||||
return self::set($key, self::NOT_EQUAL_TO_REGEX, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function and(string $key, string $operator, $value): KeyFilter
|
public function and( string $key, string $operator, $value ): KeyFilter {
|
||||||
{
|
$this->checkOperator( $operator );
|
||||||
$this->checkOperator($operator);
|
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type( $value );
|
||||||
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andEqualTo(string $key, string $value): KeyFilter
|
public function andEqualTo( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::EQUAL_TO, $value );
|
||||||
$this->and($key, self::EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andNotEqualTo(string $key, string $value): KeyFilter
|
public function andNotEqualTo( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::NOT_EQUAL_TO, $value );
|
||||||
$this->and($key, self::NOT_EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andGreaterThan(string $key, int $value): KeyFilter
|
public function andGreaterThan( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::GREATER_THAN, $value );
|
||||||
$this->and($key, self::GREATER_THAN, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andGreaterOrEqualTo(string $key, int $value): KeyFilter
|
public function andGreaterOrEqualTo( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::GREATER_EQUAL_TO, $value );
|
||||||
$this->and($key, self::GREATER_EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andLessThan(string $key, int $value): KeyFilter
|
public function andLessThan( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::LESS_THAN, $value );
|
||||||
$this->and($key, self::LESS_THAN, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andLessOrEqualTo(string $key, int $value): KeyFilter
|
public function andLessOrEqualTo( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::LESS_EQUAL_TO, $value );
|
||||||
$this->and($key, self::LESS_EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andEqualToRegex(string $key, string $value): KeyFilter
|
public function andEqualToRegex( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::EQUAL_TO_REGEX, $value );
|
||||||
$this->and($key, self::EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function andNotEqualToRegex(string $key, string $value): KeyFilter
|
public function andNotEqualToRegex( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->and( $key, self::NOT_EQUAL_TO_REGEX, $value );
|
||||||
$this->and($key, self::NOT_EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function or(string $key, string $operator, $value): KeyFilter
|
public function or( string $key, string $operator, $value ): KeyFilter {
|
||||||
{
|
$this->checkOperator( $operator );
|
||||||
$this->checkOperator($operator);
|
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type( $value );
|
||||||
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orEqualTo(string $key, string $value): KeyFilter
|
public function orEqualTo( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::EQUAL_TO, $value );
|
||||||
$this->or($key, self::EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orNotEqualTo(string $key, string $value): KeyFilter
|
public function orNotEqualTo( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::NOT_EQUAL_TO, $value );
|
||||||
$this->or($key, self::NOT_EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orGreaterThan(string $key, int $value): KeyFilter
|
public function orGreaterThan( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::GREATER_THAN, $value );
|
||||||
$this->or($key, self::GREATER_THAN, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orGreaterOrEqualTo(string $key, int $value): KeyFilter
|
public function orGreaterOrEqualTo( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::GREATER_EQUAL_TO, $value );
|
||||||
$this->or($key, self::GREATER_EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orLessThan(string $key, int $value): KeyFilter
|
public function orLessThan( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::LESS_THAN, $value );
|
||||||
$this->or($key, self::LESS_THAN, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orLessOrEqualTo(string $key, int $value): KeyFilter
|
public function orLessOrEqualTo( string $key, int $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::LESS_EQUAL_TO, $value );
|
||||||
$this->or($key, self::LESS_EQUAL_TO, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orEqualToRegex(string $key, string $value): KeyFilter
|
public function orEqualToRegex( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::EQUAL_TO_REGEX, $value );
|
||||||
$this->or($key, self::EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orNotEqualToRegex(string $key, string $value): KeyFilter
|
public function orNotEqualToRegex( string $key, string $value ): KeyFilter {
|
||||||
{
|
$this->or( $key, self::NOT_EQUAL_TO_REGEX, $value );
|
||||||
$this->or($key, self::NOT_EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return implode( ' ', $this->expressions );
|
||||||
return implode(' ', $this->expressions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkOperator(string $operator)
|
protected function checkOperator( string $operator ) {
|
||||||
{
|
if ( ! in_array( $operator, self::COMPARISON_OPERATORS ) ) {
|
||||||
if (!in_array($operator, self::COMPARISON_OPERATORS)) {
|
throw new Exception( 'Operator "' . $operator . '" is not supported!' );
|
||||||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,210 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
class KeyValue extends Base
|
|
||||||
{
|
|
||||||
public const EQUAL_TO = '==';
|
|
||||||
public const NOT_EQUAL_TO = '!=';
|
|
||||||
public const GREATER_THAN = '>';
|
|
||||||
public const GREATER_EQUAL_TO = '>=';
|
|
||||||
public const LESS_THAN = '<';
|
|
||||||
public const LESS_EQUAL_TO = '<=';
|
|
||||||
public const EQUAL_TO_REGEX = '=~';
|
|
||||||
public const NOT_EQUAL_TO_REGEX = '!~';
|
|
||||||
|
|
||||||
public const COMPARISON_OPERATORS = [
|
|
||||||
self::EQUAL_TO,
|
|
||||||
self::NOT_EQUAL_TO,
|
|
||||||
self::GREATER_THAN,
|
|
||||||
self::GREATER_EQUAL_TO,
|
|
||||||
self::LESS_THAN,
|
|
||||||
self::LESS_EQUAL_TO,
|
|
||||||
self::EQUAL_TO_REGEX,
|
|
||||||
self::NOT_EQUAL_TO_REGEX,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array $expressions
|
|
||||||
*/
|
|
||||||
private $expressions;
|
|
||||||
|
|
||||||
private function __construct(string $key, string $operator, $value)
|
|
||||||
{
|
|
||||||
$this->checkOperator($operator);
|
|
||||||
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function set(string $key, string $operator, $value): KeyValue
|
|
||||||
{
|
|
||||||
return new self($key, $operator, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setEqualTo(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::EQUAL_TO, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setNotEqualTo(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::NOT_EQUAL_TO, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setGreaterThan(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::GREATER_THAN, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setGreaterOrEqualTo(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::GREATER_EQUAL_TO, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setLessThan(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::LESS_THAN, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setLessOrEqualTo(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::LESS_EQUAL_TO, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setEqualToRegex(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::EQUAL_TO_REGEX, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setNotEqualToRegex(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
return self::set($key, self::NOT_EQUAL_TO_REGEX, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function and(string $key, string $operator, $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->checkOperator($operator);
|
|
||||||
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andEqualTo(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andNotEqualTo(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::NOT_EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andGreaterThan(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::GREATER_THAN, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andGreaterOrEqualTo(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::GREATER_EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andLessThan(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::LESS_THAN, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andLessOrEqualTo(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::LESS_EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andEqualToRegex(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function andNotEqualToRegex(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->and($key, self::NOT_EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function or(string $key, string $operator, $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->checkOperator($operator);
|
|
||||||
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type($value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orEqualTo(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orNotEqualTo(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::NOT_EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orGreaterThan(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::GREATER_THAN, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orGreaterOrEqualTo(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::GREATER_EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orLessThan(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::LESS_THAN, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orLessOrEqualTo(string $key, int $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::LESS_EQUAL_TO, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orEqualToRegex(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function orNotEqualToRegex(string $key, string $value): KeyValue
|
|
||||||
{
|
|
||||||
$this->or($key, self::NOT_EQUAL_TO_REGEX, $value);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return implode(' ', $this->expressions);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function checkOperator(string $operator)
|
|
||||||
{
|
|
||||||
if (!in_array($operator, self::COMPARISON_OPERATORS)) {
|
|
||||||
throw new Exception('Operator "' . $operator . '" is not supported!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
namespace Hosterra\FluxBuilder\Expression;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type\FieldRecordType;
|
use Hosterra\FluxBuilder\Type\FieldRecordType;
|
||||||
|
|
||||||
class Map extends Base
|
class Map extends Base {
|
||||||
{
|
|
||||||
private static $string;
|
private static $string;
|
||||||
|
|
||||||
public static function with(string $name, string $content): Map
|
public static function with( string $name, string $content ): Map {
|
||||||
{
|
|
||||||
$object = new self();
|
$object = new self();
|
||||||
$object::$string = 'r with ' . $name . ': ' . $content;
|
$object::$string = 'r with ' . $name . ': ' . $content;
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function columns(array $columns)
|
public static function columns( array $columns ) {
|
||||||
{
|
|
||||||
$object = new self();
|
$object = new self();
|
||||||
$object::$string = new FieldRecordType($columns);
|
$object::$string = new FieldRecordType( $columns );
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
|
||||||
return self::$string;
|
return self::$string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
namespace Hosterra\FluxBuilder\Expression;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Selection extends Base
|
class Selection extends Base {
|
||||||
{
|
|
||||||
private $string;
|
private $string;
|
||||||
|
|
||||||
private function __construct(string $string)
|
private function __construct( string $string ) {
|
||||||
{
|
|
||||||
$this->string = $string;
|
$this->string = $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function if(string $value): Selection
|
public static function if( string $value ): Selection {
|
||||||
{
|
return new self( 'if ' . $value );
|
||||||
return new self('if ' . $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function then($then): Selection
|
public function then( $then ): Selection {
|
||||||
{
|
$this->string .= ' then ' . new Type( $then );
|
||||||
$this->string .= ' then ' . new Type($then);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function else($else): Selection
|
public function else( $else ): Selection {
|
||||||
{
|
$this->string .= ' else ' . new Type( $else );
|
||||||
$this->string .= ' else ' . new Type($else);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
|
||||||
return $this->string;
|
return $this->string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\CustomType;
|
use Hosterra\FluxBuilder\Type\CustomType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\DurationType;
|
use Hosterra\FluxBuilder\Type\DurationType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
use Hosterra\FluxBuilder\Type\FnType;
|
||||||
|
|
||||||
class AggregateWindow extends Base
|
class AggregateWindow extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $every
|
* @var string $every
|
||||||
*/
|
*/
|
||||||
|
|
@ -25,27 +24,26 @@ class AggregateWindow extends Base
|
||||||
*/
|
*/
|
||||||
private $options;
|
private $options;
|
||||||
|
|
||||||
public function __construct($every, $fn, array $options = [])
|
public function __construct( $every, $fn, array $options = [] ) {
|
||||||
{
|
|
||||||
$this->every = $every;
|
$this->every = $every;
|
||||||
$this->fn = $fn;
|
$this->fn = $fn;
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$input = new ArrayType( array_filter( [
|
||||||
$input = new ArrayType(array_filter([
|
'every' => new DurationType( $this->every ),
|
||||||
'every' => new DurationType($this->every),
|
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
|
||||||
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
|
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
|
||||||
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
|
'fn' => new CustomType( $this->fn ),
|
||||||
'fn' => new CustomType($this->fn),
|
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
|
||||||
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
|
'column' => isset( $this->options['column'] ) ? new Type( $this->options['column'] ) : null,
|
||||||
'column' => isset($this->options['column']) ? new Type($this->options['column']) : null,
|
'timeSrc' => isset( $this->options['timeSrc'] ) ? new Type( $this->options['timeSrc'] ) : null,
|
||||||
'timeSrc' => isset($this->options['timeSrc']) ? new Type($this->options['timeSrc']) : null,
|
'timeDst' => isset( $this->options['timeDst'] ) ? new Type( $this->options['timeDst'] ) : null,
|
||||||
'timeDst' => isset($this->options['timeDst']) ? new Type($this->options['timeDst']) : null,
|
'createEmpty' => isset( $this->options['createEmpty'] ) && ! $this->options['createEmpty'] ?
|
||||||
'createEmpty' => isset($this->options['createEmpty']) && !$this->options['createEmpty'] ?
|
new Type( $this->options['createEmpty'] ) : null,
|
||||||
new Type($this->options['createEmpty']) : null,
|
] ) );
|
||||||
]));
|
|
||||||
return '|> aggregateWindow(' . $input . ') ';
|
return '|> aggregateWindow(' . $input . ') ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Exception\FunctionNotImplementedException;
|
use Hosterra\FluxBuilder\Exception\FunctionNotImplementedException;
|
||||||
|
|
||||||
abstract class Base
|
abstract class Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @throws FunctionNotImplementedException
|
* @throws FunctionNotImplementedException
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
throw new FunctionNotImplementedException( '__toString', get_class( $this ) );
|
||||||
throw new FunctionNotImplementedException('__toString', get_class($this));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||||
|
|
||||||
class Bottom extends Base
|
class Bottom extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var int $n
|
* @var int $n
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,18 +15,17 @@ class Bottom extends Base
|
||||||
*/
|
*/
|
||||||
private $columns;
|
private $columns;
|
||||||
|
|
||||||
public function __construct($n, array $columns = [])
|
public function __construct( $n, array $columns = [] ) {
|
||||||
{
|
|
||||||
$this->n = $n;
|
$this->n = $n;
|
||||||
$this->columns = $columns;
|
$this->columns = $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$input = new ArrayType( array_filter( [
|
||||||
$input = new ArrayType(array_filter([
|
|
||||||
'n' => $this->n,
|
'n' => $this->n,
|
||||||
'columns' => $this->columns ?: null,
|
'columns' => $this->columns ?: null,
|
||||||
]));
|
] ) );
|
||||||
|
|
||||||
return '|> bottom(' . $input . ') ';
|
return '|> bottom(' . $input . ') ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Count extends Base
|
class Count extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string|null $column
|
* @var string|null $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(?string $column = null)
|
public function __construct( ?string $column = null ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$params = new Type( array_filter( [
|
||||||
$params = new Type(array_filter([
|
|
||||||
'column' => $this->column
|
'column' => $this->column
|
||||||
]));
|
] ) );
|
||||||
|
|
||||||
return '|> count(' . $params . ') ';
|
return '|> count(' . $params . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||||
|
|
||||||
class Duplicate extends Base
|
class Duplicate extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $column
|
* @var string $column
|
||||||
*/
|
*/
|
||||||
|
|
@ -17,18 +16,16 @@ class Duplicate extends Base
|
||||||
*/
|
*/
|
||||||
private $as;
|
private $as;
|
||||||
|
|
||||||
public function __construct(string $column, string $as)
|
public function __construct( string $column, string $as ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
$this->as = $as;
|
$this->as = $as;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$input = new ArrayType( [
|
||||||
$input = new ArrayType([
|
|
||||||
'column' => $this->column,
|
'column' => $this->column,
|
||||||
'as' => $this->as
|
'as' => $this->as
|
||||||
]);
|
] );
|
||||||
|
|
||||||
return '|> duplicate(' . $input . ') ';
|
return '|> duplicate(' . $input . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,47 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Exception\FunctionInvalidInputException;
|
use Hosterra\FluxBuilder\Exception\FunctionInvalidInputException;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
|
||||||
|
|
||||||
class Filter extends Base
|
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||||
{
|
|
||||||
|
class Filter extends Base {
|
||||||
/**
|
/**
|
||||||
* @var mixed $filter
|
* @var mixed $filter
|
||||||
*/
|
*/
|
||||||
private $filter;
|
private $filter;
|
||||||
|
|
||||||
public function __construct($filter)
|
public function __construct( $filter ) {
|
||||||
{
|
|
||||||
$this->filter = $filter;
|
$this->filter = $filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
|
||||||
return '|> filter(fn: (r) => ' . $this->format() . ') ';
|
return '|> filter(fn: (r) => ' . $this->format() . ') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws FunctionInvalidInputException
|
* @throws FunctionInvalidInputException
|
||||||
*/
|
*/
|
||||||
protected function format(): string
|
protected function format(): string {
|
||||||
{
|
if ( $this->filter instanceof KeyValue || $this->filter instanceof KeyFilter ) {
|
||||||
if ($this->filter instanceof KeyValue || $this->filter instanceof KeyFilter) {
|
|
||||||
return $this->filter->__toString();
|
return $this->filter->__toString();
|
||||||
} elseif (is_array($this->filter)) {
|
} elseif ( is_array( $this->filter ) ) {
|
||||||
$filterCounter = 0;
|
$filterCounter = 0;
|
||||||
$filterString = '';
|
$filterString = '';
|
||||||
foreach ($this->filter as $filter) {
|
foreach ( $this->filter as $filter ) {
|
||||||
if ($filterCounter > 0) {
|
if ( $filterCounter > 0 ) {
|
||||||
$filterString .= ' or ';
|
$filterString .= ' or ';
|
||||||
}
|
}
|
||||||
|
|
||||||
$filterString .= 'r._field == "' . $filter . '"';
|
$filterString .= 'r._field == "' . $filter . '"';
|
||||||
|
|
||||||
$filterCounter++;
|
$filterCounter ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $filterString;
|
return $filterString;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FunctionInvalidInputException('Filter input is incorrect.');
|
throw new FunctionInvalidInputException( 'Filter input is incorrect.' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class First extends Base
|
class First extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string|null $column
|
* @var string|null $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(?string $column = null)
|
public function __construct( ?string $column = null ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$params = new Type( array_filter( [
|
||||||
$params = new Type(array_filter([
|
|
||||||
'column' => $this->column
|
'column' => $this->column
|
||||||
]));
|
] ) );
|
||||||
|
|
||||||
return '|> first(' . $params . ') ';
|
return '|> first(' . $params . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class From extends Base
|
class From extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $settings
|
* @var array $settings
|
||||||
*/
|
*/
|
||||||
private $settings;
|
private $settings;
|
||||||
|
|
||||||
public function __construct(array $settings)
|
public function __construct( array $settings ) {
|
||||||
{
|
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return 'from(' . new Type( $this->settings ) . ') ';
|
||||||
return 'from(' . new Type($this->settings) . ') ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Group extends Base
|
class Group extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $columns
|
* @var array $columns
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,18 +15,16 @@ class Group extends Base
|
||||||
*/
|
*/
|
||||||
private $mode;
|
private $mode;
|
||||||
|
|
||||||
public function __construct(array $columns, string $mode = 'by')
|
public function __construct( array $columns, string $mode = 'by' ) {
|
||||||
{
|
|
||||||
$this->columns = $columns;
|
$this->columns = $columns;
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$array = new Type( [
|
||||||
$array = new Type([
|
|
||||||
'columns' => $this->columns,
|
'columns' => $this->columns,
|
||||||
'mode' => $this->mode,
|
'mode' => $this->mode,
|
||||||
]);
|
] );
|
||||||
|
|
||||||
return '|> group(' . $array . ') ';
|
return '|> group(' . $array . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
class Last extends Base
|
class Last extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var int $column
|
* @var int $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(string $column = '_value')
|
public function __construct( string $column = '_value' ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return '|> last(column: "' . (string) $this->column . '") ';
|
||||||
return '|> last(column: "' . (string)$this->column . '") ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
class Limit extends Base
|
class Limit extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var int $limit
|
* @var int $limit
|
||||||
*/
|
*/
|
||||||
|
|
@ -14,14 +13,12 @@ class Limit extends Base
|
||||||
*/
|
*/
|
||||||
private $offset;
|
private $offset;
|
||||||
|
|
||||||
public function __construct(int $limit, int $offset = 0)
|
public function __construct( int $limit, int $offset = 0 ) {
|
||||||
{
|
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
$this->offset = $offset;
|
$this->offset = $offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return '|> limit(n: ' . (string) $this->limit . ', offset: ' . (string) $this->offset . ') ';
|
||||||
return '|> limit(n: ' . (string)$this->limit . ', offset: ' . (string)$this->offset . ') ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
|
use Hosterra\FluxBuilder\Expression\Map as MapExpression;
|
||||||
|
|
||||||
class Map extends Base
|
class Map extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var mixed $query
|
* @var mixed $query
|
||||||
*/
|
*/
|
||||||
private $query;
|
private $query;
|
||||||
|
|
||||||
public function __construct($query)
|
public function __construct( $query ) {
|
||||||
{
|
|
||||||
$this->query = $query;
|
$this->query = $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
|
||||||
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Max extends Base
|
class Max extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string|null $column
|
* @var string|null $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(?string $column = null)
|
public function __construct( ?string $column = null ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$params = new Type( array_filter( [
|
||||||
$params = new Type(array_filter([
|
|
||||||
'column' => $this->column
|
'column' => $this->column
|
||||||
]));
|
] ) );
|
||||||
|
|
||||||
return '|> max(' . $params . ') ';
|
return '|> max(' . $params . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||||
|
|
||||||
class Mean extends Base
|
class Mean extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $column
|
* @var string $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(string $column = '_value')
|
public function __construct( string $column = '_value' ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$input = new ArrayType( array_filter( [
|
||||||
$input = new ArrayType(array_filter([
|
'column' => ! empty( $this->column ) && $this->column !== '_value' ?
|
||||||
'column' => !empty($this->column) && $this->column !== '_value' ?
|
new Type( $this->column ) : null
|
||||||
new Type($this->column) : null
|
] ) );
|
||||||
]));
|
|
||||||
|
|
||||||
return '|> mean(' . $input . ') ';
|
return '|> mean(' . $input . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
class Measurement extends Base
|
class Measurement extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $measurement
|
* @var string $measurement
|
||||||
*/
|
*/
|
||||||
private $measurement;
|
private $measurement;
|
||||||
|
|
||||||
public function __construct(string $measurement)
|
public function __construct( string $measurement ) {
|
||||||
{
|
|
||||||
$this->measurement = $measurement;
|
$this->measurement = $measurement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return '|> filter(fn: (r) => r._measurement == "' . (string) $this->measurement . '") ';
|
||||||
return '|> filter(fn: (r) => r._measurement == "' . (string)$this->measurement . '") ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Min extends Base
|
class Min extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string|null $column
|
* @var string|null $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(?string $column = null)
|
public function __construct( ?string $column = null ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$params = new Type( array_filter( [
|
||||||
$params = new Type(array_filter([
|
|
||||||
'column' => $this->column
|
'column' => $this->column
|
||||||
]));
|
] ) );
|
||||||
|
|
||||||
return '|> min(' . $params . ') ';
|
return '|> min(' . $params . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Exception\FunctionRequiredSettingMissingException;
|
use Hosterra\FluxBuilder\Exception\FunctionRequiredSettingMissingException;
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class Range extends Base
|
class Range extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var mixed $start
|
* @var mixed $start
|
||||||
*/
|
*/
|
||||||
|
|
@ -18,20 +17,18 @@ class Range extends Base
|
||||||
*/
|
*/
|
||||||
private $stop;
|
private $stop;
|
||||||
|
|
||||||
public function __construct(DateTime $start, ?DateTime $stop = null)
|
public function __construct( DateTime $start, ?DateTime $stop = null ) {
|
||||||
{
|
$this->start = new Type( $start );
|
||||||
$this->start = new Type($start);
|
$this->stop = $stop ? new Type( $stop ) : null;
|
||||||
$this->stop = $stop ? new Type($stop) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
if ( ! $this->start ) {
|
||||||
if (!$this->start) {
|
throw new FunctionRequiredSettingMissingException( 'Range', 'Start setting is required!' );
|
||||||
throw new FunctionRequiredSettingMissingException('Range', 'Start setting is required!');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$settingsString = 'start: ' . $this->start;
|
$settingsString = 'start: ' . $this->start;
|
||||||
if ($this->stop) {
|
if ( $this->stop ) {
|
||||||
$settingsString .= ', stop: ' . $this->stop;
|
$settingsString .= ', stop: ' . $this->stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
class RawFunction extends Base
|
class RawFunction extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $input
|
* @var string $input
|
||||||
*/
|
*/
|
||||||
private $input;
|
private $input;
|
||||||
|
|
||||||
public function __construct(string $input)
|
public function __construct( string $input ) {
|
||||||
{
|
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
|
||||||
return $this->input . ' ';
|
return $this->input . ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type\RecordType;
|
use Hosterra\FluxBuilder\Type\RecordType;
|
||||||
|
|
||||||
class Reduce extends Base
|
class Reduce extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $settings
|
* @var array $settings
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,15 +15,13 @@ class Reduce extends Base
|
||||||
*/
|
*/
|
||||||
private $identity;
|
private $identity;
|
||||||
|
|
||||||
public function __construct(array $settings, array $identity)
|
public function __construct( array $settings, array $identity ) {
|
||||||
{
|
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->identity = $identity;
|
$this->identity = $identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return '|> reduce(fn: (r, accumulator) => (' . new RecordType( $this->settings ) . '), ' .
|
||||||
return '|> reduce(fn: (r, accumulator) => (' . new RecordType($this->settings) . '), ' .
|
'identity: ' . new RecordType( $this->identity ) . ') ';
|
||||||
'identity: ' . new RecordType($this->identity) . ') ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Sort extends Base
|
class Sort extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $columns
|
* @var array $columns
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,15 +15,13 @@ class Sort extends Base
|
||||||
*/
|
*/
|
||||||
private $desc;
|
private $desc;
|
||||||
|
|
||||||
public function __construct(array $columns = ['_value'], bool $desc = false)
|
public function __construct( array $columns = [ '_value' ], bool $desc = false ) {
|
||||||
{
|
|
||||||
$this->columns = $columns;
|
$this->columns = $columns;
|
||||||
$this->desc = $desc;
|
$this->desc = $desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return '|> sort(columns: [' . new Type( $this->columns ) .
|
||||||
return '|> sort(columns: [' . new Type($this->columns) .
|
'], desc: ' . new Type( $this->desc ) . ') ';
|
||||||
'], desc: ' . new Type($this->desc) . ') ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
class Sum extends Base
|
class Sum extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $column
|
* @var string $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(string $column)
|
public function __construct( string $column ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
return '|> sum(column: "' . (string) $this->column . '") ';
|
||||||
return '|> sum(column: "' . (string)$this->column . '") ';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class Unique extends Base
|
class Unique extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string|null $column
|
* @var string|null $column
|
||||||
*/
|
*/
|
||||||
private $column;
|
private $column;
|
||||||
|
|
||||||
public function __construct(?string $column = null)
|
public function __construct( ?string $column = null ) {
|
||||||
{
|
|
||||||
$this->column = $column;
|
$this->column = $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$params = new Type( array_filter( [
|
||||||
$params = new Type(array_filter([
|
|
||||||
'column' => $this->column
|
'column' => $this->column
|
||||||
]));
|
] ) );
|
||||||
|
|
||||||
return '|> unique(' . $params . ') ';
|
return '|> unique(' . $params . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
namespace Hosterra\FluxBuilder\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\DurationType;
|
use Hosterra\FluxBuilder\Type\DurationType;
|
||||||
|
|
||||||
class Window extends Base
|
class Window extends Base {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var string $every
|
* @var string $every
|
||||||
*/
|
*/
|
||||||
|
|
@ -18,25 +17,24 @@ class Window extends Base
|
||||||
*/
|
*/
|
||||||
private $options;
|
private $options;
|
||||||
|
|
||||||
public function __construct($every, array $options = [])
|
public function __construct( $every, array $options = [] ) {
|
||||||
{
|
|
||||||
$this->every = $every;
|
$this->every = $every;
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString() {
|
||||||
{
|
$input = new ArrayType( array_filter( [
|
||||||
$input = new ArrayType(array_filter([
|
'every' => new DurationType( $this->every ),
|
||||||
'every' => new DurationType($this->every),
|
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
|
||||||
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
|
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
|
||||||
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
|
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
|
||||||
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
|
'timeColumn' => isset( $this->options['timeColumn'] ) ? new Type( $this->options['timeColumn'] ) : null,
|
||||||
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
|
'startColumn' => isset( $this->options['startColumn'] ) ? new Type( $this->options['startColumn'] ) : null,
|
||||||
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
|
'stopColumn' => isset( $this->options['stopColumn'] ) ? new Type( $this->options['stopColumn'] ) : null,
|
||||||
'stopColumn' => isset($this->options['stopColumn']) ? new Type($this->options['stopColumn']) : null,
|
'createEmpty' => isset( $this->options['createEmpty'] ) && $this->options['createEmpty'] ?
|
||||||
'createEmpty' => isset($this->options['createEmpty']) && $this->options['createEmpty'] ?
|
new Type( $this->options['createEmpty'] ) : null,
|
||||||
new Type($this->options['createEmpty']) : null,
|
] ) );
|
||||||
]));
|
|
||||||
return '|> window(' . $input . ') ';
|
return '|> window(' . $input . ') ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder;
|
namespace Hosterra\FluxBuilder;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
|
||||||
use Arendsen\FluxQueryBuilder\Builder\Basics;
|
use Hosterra\FluxBuilder\Builder\Basics;
|
||||||
use Arendsen\FluxQueryBuilder\Builder\Universe;
|
use Hosterra\FluxBuilder\Builder\Universe;
|
||||||
|
|
||||||
class QueryBuilder implements QueryBuilderInterface
|
class QueryBuilder implements QueryBuilderInterface {
|
||||||
{
|
|
||||||
|
const VERSION = '2.0.0';
|
||||||
use Basics;
|
use Basics;
|
||||||
use Universe;
|
use Universe;
|
||||||
|
|
||||||
|
|
@ -27,37 +28,34 @@ class QueryBuilder implements QueryBuilderInterface
|
||||||
*/
|
*/
|
||||||
private $requiredData = [];
|
private $requiredData = [];
|
||||||
|
|
||||||
protected function addToQuery($query)
|
protected function addToQuery( $query ) {
|
||||||
{
|
|
||||||
$this->fluxQueryParts[] = $query;
|
$this->fluxQueryParts[] = $query;
|
||||||
|
|
||||||
foreach ($this->requiredFluxQueryParts as $input) {
|
foreach ( $this->requiredFluxQueryParts as $input ) {
|
||||||
if ($query instanceof $input) {
|
if ( $query instanceof $input ) {
|
||||||
$this->requiredData[] = $query;
|
$this->requiredData[] = $query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function build(): string
|
public function build(): string {
|
||||||
{
|
|
||||||
$this->checkRequired();
|
$this->checkRequired();
|
||||||
|
|
||||||
$query = '';
|
$query = '';
|
||||||
|
|
||||||
foreach ($this->fluxQueryParts as $part) {
|
foreach ( $this->fluxQueryParts as $part ) {
|
||||||
$query .= $part;
|
$query .= $part;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkRequired()
|
protected function checkRequired() {
|
||||||
{
|
foreach ( $this->requiredFluxQueryParts as $key => $input ) {
|
||||||
foreach ($this->requiredFluxQueryParts as $key => $input) {
|
if ( isset( $this->requiredData[ $key ] ) && ! $this->requiredData[ $key ] instanceof $input ) {
|
||||||
if (isset($this->requiredData[$key]) && !$this->requiredData[$key] instanceof $input) {
|
throw new Exception( 'You need to put the "' . $input . '" part of the query in the correct order!' );
|
||||||
throw new Exception('You need to put the "' . $input . '" part of the query in the correct order!');
|
} elseif ( ! isset( $this->requiredData[ $key ] ) ) {
|
||||||
} elseif (!isset($this->requiredData[$key])) {
|
throw new Exception( 'You need to define the "' . $input . '" part of the query!' );
|
||||||
throw new Exception('You need to define the "' . $input . '" part of the query!');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder;
|
namespace Hosterra\FluxBuilder;
|
||||||
|
|
||||||
class Settings
|
class Settings {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $settings
|
* @var array $settings
|
||||||
*/
|
*/
|
||||||
protected $settings;
|
protected $settings;
|
||||||
|
|
||||||
public function __construct(array $settings = [])
|
public function __construct( array $settings = [] ) {
|
||||||
{
|
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function set(array $settings = [])
|
public static function set( array $settings = [] ) {
|
||||||
{
|
return new self( $settings );
|
||||||
return new self($settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(string $key)
|
public function get( string $key ) {
|
||||||
{
|
return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : null;
|
||||||
return isset($this->settings[$key]) ? $this->settings[$key] : null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
src/Type.php
32
src/Type.php
|
|
@ -1,43 +1,41 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder;
|
namespace Hosterra\FluxBuilder;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type\TypeInterface;
|
use Hosterra\FluxBuilder\Type\TypeInterface;
|
||||||
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
use Hosterra\FluxBuilder\Type\ArrayType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\BooleanType;
|
use Hosterra\FluxBuilder\Type\BooleanType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\TimeType;
|
use Hosterra\FluxBuilder\Type\TimeType;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class Type
|
class Type {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var mixed $value
|
* @var mixed $value
|
||||||
*/
|
*/
|
||||||
protected $value;
|
protected $value;
|
||||||
|
|
||||||
public function __construct($value)
|
public function __construct( $value ) {
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
switch ( gettype( $this->value ) ) {
|
||||||
switch (gettype($this->value)) {
|
|
||||||
case 'object':
|
case 'object':
|
||||||
if ($this->value instanceof DateTime) {
|
if ( $this->value instanceof DateTime ) {
|
||||||
return new TimeType($this->value);
|
return new TimeType( $this->value );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->value->__toString();
|
return $this->value->__toString();
|
||||||
case 'string':
|
case 'string':
|
||||||
return '"' . $this->value . '"';
|
return '"' . $this->value . '"';
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return new BooleanType($this->value);
|
return new BooleanType( $this->value );
|
||||||
case 'array':
|
case 'array':
|
||||||
return new ArrayType($this->value);
|
return new ArrayType( $this->value );
|
||||||
case 'NULL':
|
case 'NULL':
|
||||||
return 'null';
|
return 'null';
|
||||||
default:
|
default:
|
||||||
return (string)$this->value;
|
return (string) $this->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,41 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Settings;
|
use Hosterra\FluxBuilder\Settings;
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class ArrayType implements TypeInterface
|
class ArrayType implements TypeInterface {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $value
|
* @var array $value
|
||||||
*/
|
*/
|
||||||
protected $value;
|
protected $value;
|
||||||
|
|
||||||
public function __construct(array $value)
|
public function __construct( array $value ) {
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
array_walk( $this->value, function ( &$value, $key ) {
|
||||||
array_walk($this->value, function (&$value, $key) {
|
if ( $this->isAssociativeArray( $key ) ) {
|
||||||
if ($this->isAssociativeArray($key)) {
|
$value = $key . ': ' . $this->getPrefix( $value ) . new Type( $value ) . $this->getSuffix( $value );
|
||||||
$value = $key . ': ' . $this->getPrefix($value) . new Type($value) . $this->getSuffix($value);
|
|
||||||
} else {
|
} else {
|
||||||
$value = $this->getPrefix($value) . new Type($value) . $this->getSuffix($value);
|
$value = $this->getPrefix( $value ) . new Type( $value ) . $this->getSuffix( $value );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
return implode(', ', $this->value);
|
return implode( ', ', $this->value );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isAssociativeArray($key): bool
|
protected function isAssociativeArray( $key ): bool {
|
||||||
{
|
return is_string( $key );
|
||||||
return is_string($key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPrefix($value): string
|
protected function getPrefix( $value ): string {
|
||||||
{
|
return is_array( $value ) ? '[' : '';
|
||||||
return is_array($value) ? '[' : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSuffix($value): string
|
protected function getSuffix( $value ): string {
|
||||||
{
|
return is_array( $value ) ? ']' : '';
|
||||||
return is_array($value) ? ']' : '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class BooleanType implements TypeInterface
|
class BooleanType implements TypeInterface {
|
||||||
{
|
public function __construct( $value ) {
|
||||||
public function __construct($value)
|
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
|
||||||
return $this->value ? 'true' : 'false';
|
return $this->value ? 'true' : 'false';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class CustomType implements TypeInterface
|
class CustomType implements TypeInterface {
|
||||||
{
|
public function __construct( string $value ) {
|
||||||
public function __construct(string $value)
|
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class DurationType implements TypeInterface
|
class DurationType implements TypeInterface {
|
||||||
{
|
public function __construct( string $value ) {
|
||||||
public function __construct(string $value)
|
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Settings;
|
use Hosterra\FluxBuilder\Settings;
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class FieldRecordType implements TypeInterface
|
class FieldRecordType implements TypeInterface {
|
||||||
{
|
|
||||||
public const SETTING_IS_RECORD = 'isRecord';
|
public const SETTING_IS_RECORD = 'isRecord';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -14,19 +13,17 @@ class FieldRecordType implements TypeInterface
|
||||||
*/
|
*/
|
||||||
private $value;
|
private $value;
|
||||||
|
|
||||||
public function __construct(array $value)
|
public function __construct( array $value ) {
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
array_walk( $this->value, function ( &$value, $key ) {
|
||||||
array_walk($this->value, function (&$value, $key) {
|
if ( is_string( $key ) ) {
|
||||||
if (is_string($key)) {
|
|
||||||
$value = $key . ': ' . $value;
|
$value = $key . ': ' . $value;
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
return '{' . implode(', ', $this->value) . '}';
|
return '{' . implode( ', ', $this->value ) . '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class FnType implements TypeInterface
|
class FnType implements TypeInterface {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $params
|
* @var array $params
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,36 +15,33 @@ class FnType implements TypeInterface
|
||||||
*/
|
*/
|
||||||
protected $content;
|
protected $content;
|
||||||
|
|
||||||
private function __construct(array $params)
|
private function __construct( array $params ) {
|
||||||
{
|
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function params(array $params)
|
public static function params( array $params ) {
|
||||||
{
|
return new self( $params );
|
||||||
return new self($params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withBody(string $content)
|
public function withBody( string $content ) {
|
||||||
{
|
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withBlock(string $content)
|
public function withBlock( string $content ) {
|
||||||
{
|
|
||||||
$this->content = '{ ' . $content . ' }';
|
$this->content = '{ ' . $content . ' }';
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
array_walk( $this->params, function ( &$value, $key ) {
|
||||||
array_walk($this->params, function (&$value, $key) {
|
if ( is_string( $key ) ) {
|
||||||
if (is_string($key)) {
|
$value = $key . ' = ' . new Type( $value );
|
||||||
$value = $key . ' = ' . new Type($value);
|
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
return '(' . implode(', ', $this->params) . ') => ' . $this->content;
|
return '(' . implode( ', ', $this->params ) . ') => ' . $this->content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class MathType implements TypeInterface
|
class MathType implements TypeInterface {
|
||||||
{
|
public function __construct( string $value ) {
|
||||||
public function __construct(string $value)
|
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
class RecordType implements TypeInterface
|
class RecordType implements TypeInterface {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @var array $value
|
* @var array $value
|
||||||
*/
|
*/
|
||||||
private $value;
|
private $value;
|
||||||
|
|
||||||
public function __construct(array $value)
|
public function __construct( array $value ) {
|
||||||
{
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
array_walk( $this->value, function ( &$value, $key ) {
|
||||||
array_walk($this->value, function (&$value, $key) {
|
if ( is_array( $value ) ) {
|
||||||
if (is_array($value)) {
|
$value = $this->getPrefix( $key ) . new RecordType( $value );
|
||||||
$value = $this->getPrefix($key) . new RecordType($value);
|
|
||||||
} else {
|
} else {
|
||||||
$value = $this->getPrefix($key) . new Type($value);
|
$value = $this->getPrefix( $key ) . new Type( $value );
|
||||||
}
|
}
|
||||||
});
|
} );
|
||||||
|
|
||||||
return '{' . implode(', ', $this->value) . '}';
|
return '{' . implode( ', ', $this->value ) . '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrefix($key): string
|
private function getPrefix( $key ): string {
|
||||||
{
|
return is_string( $key ) ? $key . ': ' : '';
|
||||||
return is_string($key) ? $key . ': ' : '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class TimeType implements TypeInterface
|
class TimeType implements TypeInterface {
|
||||||
{
|
public function __construct( DateTime $dateTime ) {
|
||||||
public function __construct(DateTime $dateTime)
|
|
||||||
{
|
|
||||||
$this->dateTime = $dateTime;
|
$this->dateTime = $dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string {
|
||||||
{
|
return 'time(v: ' . $this->dateTime->format( 'Y-m-d\TH:i:s\Z' ) . ')';
|
||||||
return 'time(v: ' . $this->dateTime->format('Y-m-d\TH:i:s\Z') . ')';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Arendsen\FluxQueryBuilder\Type;
|
namespace Hosterra\FluxBuilder\Type;
|
||||||
|
|
||||||
interface TypeInterface
|
interface TypeInterface {
|
||||||
{
|
|
||||||
public function __toString(): string;
|
public function __toString(): string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Expression;
|
namespace Tests\Expression;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class KeyFilterExpressionTest extends TestCase
|
final class KeyFilterExpressionTest extends TestCase {
|
||||||
{
|
public function testSimpleKeyvalue() {
|
||||||
public function testSimpleKeyvalue()
|
$keyFilter = KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
|
||||||
{
|
->andEqualTo( '_field', 'user' )
|
||||||
$keyFilter = KeyFilter::setEqualTo('_measurement', 'test_measurement')
|
->or( 'count', '>=', '1' )
|
||||||
->andEqualTo('_field', 'user')
|
->and( 'user', KeyFilter::EQUAL_TO, 'my_username' )
|
||||||
->or('count', '>=', '1')
|
->orNotEqualTo( 'test', 'world' );
|
||||||
->and('user', KeyFilter::EQUAL_TO, 'my_username')
|
|
||||||
->orNotEqualTo('test', 'world');
|
|
||||||
|
|
||||||
$query = 'r._measurement == "test_measurement" and r._field == "user" or ' .
|
$query = 'r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||||
'r.count >= "1" and r.user == "my_username" or r.test != "world"';
|
'r.count >= "1" and r.user == "my_username" or r.test != "world"';
|
||||||
|
|
||||||
$this->assertEquals($keyFilter->__toString(), $query);
|
$this->assertEquals( $keyFilter->__toString(), $query );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidOperator()
|
public function testInvalidOperator() {
|
||||||
{
|
$this->expectException( Exception::class );
|
||||||
$this->expectException(Exception::class);
|
|
||||||
|
|
||||||
KeyFilter::set('_measurement', '9dkda9e', 'test_measurement')
|
KeyFilter::set( '_measurement', '9dkda9e', 'test_measurement' )
|
||||||
->andEqualTo('_field', 'user')
|
->andEqualTo( '_field', 'user' )
|
||||||
->or('_field', '==', 'field2')
|
->or( '_field', '==', 'field2' )
|
||||||
->andEqualTo('user', 'my_username');
|
->andEqualTo( 'user', 'my_username' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
use Hosterra\FluxBuilder\Functions\AggregateWindow;
|
||||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
use Hosterra\FluxBuilder\Type\FnType;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class AggregateWindowFunctionTest extends TestCase
|
final class AggregateWindowFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleWindow() {
|
||||||
public function testSimpleWindow()
|
$expression = new AggregateWindow( '20s', 'mean' );
|
||||||
{
|
|
||||||
$expression = new AggregateWindow('20s', 'mean');
|
|
||||||
|
|
||||||
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
|
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAllParameters()
|
public function testAllParameters() {
|
||||||
{
|
|
||||||
$expression = new AggregateWindow(
|
$expression = new AggregateWindow(
|
||||||
'20s',
|
'20s',
|
||||||
FnType::params(['r'])->withBody('r._field == "test"'),
|
FnType::params( [ 'r' ] )->withBody( 'r._field == "test"' ),
|
||||||
[
|
[
|
||||||
'period' => 'every',
|
'period' => 'every',
|
||||||
'offset' => '0s',
|
'offset' => '0s',
|
||||||
|
|
@ -38,6 +35,6 @@ final class AggregateWindowFunctionTest extends TestCase
|
||||||
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test", ' .
|
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test", ' .
|
||||||
'location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
|
'location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
use Hosterra\FluxBuilder\Functions\Count;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class CountFunctionTest extends TestCase
|
final class CountFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleCount() {
|
||||||
public function testSimpleCount()
|
|
||||||
{
|
|
||||||
$expression = new Count();
|
$expression = new Count();
|
||||||
|
|
||||||
$query = '|> count() ';
|
$query = '|> count() ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCountWithColumn()
|
public function testCountWithColumn() {
|
||||||
{
|
$expression = new Count( '_value' );
|
||||||
$expression = new Count('_value');
|
|
||||||
|
|
||||||
$query = '|> count(column: "_value") ';
|
$query = '|> count(column: "_value") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
use Hosterra\FluxBuilder\Functions\Duplicate;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class DuplicateFunctionTest extends TestCase
|
final class DuplicateFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleDuplicate() {
|
||||||
public function testSimpleDuplicate()
|
$expression = new Duplicate( 'tag', 'tag_dup' );
|
||||||
{
|
|
||||||
$expression = new Duplicate('tag', 'tag_dup');
|
|
||||||
|
|
||||||
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
use Hosterra\FluxBuilder\Functions\Filter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FilterFunctionTest extends TestCase
|
final class FilterFunctionTest extends TestCase {
|
||||||
{
|
|
||||||
public function testSimpleFilter()
|
|
||||||
{
|
|
||||||
$expression = new Filter(KeyValue::setEqualTo('_measurement', 'test_measurement')
|
|
||||||
->andEqualTo('_field', 'user')
|
|
||||||
->orEqualTo('_field', 'field2')
|
|
||||||
->andEqualTo('user', 'my_username'));
|
|
||||||
|
|
||||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
public function testFieldFilter() {
|
||||||
'r._field == "field2" and r.user == "my_username") ';
|
$expression = new Filter( [ 'user', 'field2', 'field3' ] );
|
||||||
|
|
||||||
$this->assertEquals($expression->__toString(), $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFieldFilter()
|
|
||||||
{
|
|
||||||
$expression = new Filter(['user', 'field2', 'field3']);
|
|
||||||
|
|
||||||
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
|
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
|
||||||
|
|
||||||
$this->assertEquals($expression->__toString(), $query);
|
$this->assertEquals( $expression->__toString(), $query );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testKeyFilter()
|
public function testKeyFilter() {
|
||||||
{
|
$expression = new Filter( KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
|
||||||
$expression = new Filter(KeyFilter::setEqualTo('_measurement', 'test_measurement')
|
->andEqualTo( '_field', 'user' )
|
||||||
->andEqualTo('_field', 'user')
|
->orEqualTo( '_field', 'field2' )
|
||||||
->orEqualTo('_field', 'field2')
|
->andEqualTo( 'user', 'my_username' ) );
|
||||||
->andEqualTo('user', 'my_username'));
|
|
||||||
|
|
||||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||||
'r._field == "field2" and r.user == "my_username") ';
|
'r._field == "field2" and r.user == "my_username") ';
|
||||||
|
|
||||||
$this->assertEquals($expression->__toString(), $query);
|
$this->assertEquals( $expression->__toString(), $query );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
use Hosterra\FluxBuilder\Functions\First;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FirstFunctionTest extends TestCase
|
final class FirstFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleFirst() {
|
||||||
public function testSimpleFirst()
|
|
||||||
{
|
|
||||||
$expression = new First();
|
$expression = new First();
|
||||||
|
|
||||||
$query = '|> first() ';
|
$query = '|> first() ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFirstWithColumn()
|
public function testFirstWithColumn() {
|
||||||
{
|
$expression = new First( 'something' );
|
||||||
$expression = new First('something');
|
|
||||||
|
|
||||||
$query = '|> first(column: "something") ';
|
$query = '|> first(column: "something") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\From;
|
use Hosterra\FluxBuilder\Functions\From;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FromFunctionTest extends TestCase
|
final class FromFunctionTest extends TestCase {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider somethingProvider
|
* @dataProvider somethingProvider
|
||||||
*/
|
*/
|
||||||
public function testSomething($settings, $query)
|
public function testSomething( $settings, $query ) {
|
||||||
{
|
$expression = new From( $settings );
|
||||||
$expression = new From($settings);
|
|
||||||
|
|
||||||
$this->assertEquals($expression->__toString(), $query);
|
$this->assertEquals( $expression->__toString(), $query );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function somethingProvider(): array
|
public function somethingProvider(): array {
|
||||||
{
|
|
||||||
return [
|
return [
|
||||||
'from bucket' => [
|
'from bucket' => [
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
use Hosterra\FluxBuilder\Functions\Group;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class GroupFunctionTest extends TestCase
|
final class GroupFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleGroup() {
|
||||||
public function testSimpleGroup()
|
$expression = new Group( [ 'foo', 'bar' ], 'by' );
|
||||||
{
|
|
||||||
$expression = new Group(['foo', 'bar'], 'by');
|
|
||||||
|
|
||||||
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
|
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
use Hosterra\FluxBuilder\Functions\Last;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class LastFunctionTest extends TestCase
|
final class LastFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleLast() {
|
||||||
public function testSimpleLast()
|
|
||||||
{
|
|
||||||
$expression = new Last();
|
$expression = new Last();
|
||||||
|
|
||||||
$query = '|> last(column: "_value") ';
|
$query = '|> last(column: "_value") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLastWithValue()
|
public function testLastWithValue() {
|
||||||
{
|
$expression = new Last( 'something' );
|
||||||
$expression = new Last('something');
|
|
||||||
|
|
||||||
$query = '|> last(column: "something") ';
|
$query = '|> last(column: "something") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
use Hosterra\FluxBuilder\Functions\Limit;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class LimitFunctionTest extends TestCase
|
final class LimitFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleLimit() {
|
||||||
public function testSimpleLimit()
|
$expression = new Limit( 1 );
|
||||||
{
|
|
||||||
$expression = new Limit(1);
|
|
||||||
|
|
||||||
$query = '|> limit(n: 1, offset: 0) ';
|
$query = '|> limit(n: 1, offset: 0) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLimitWithOffset()
|
public function testLimitWithOffset() {
|
||||||
{
|
$expression = new Limit( 10, 2 );
|
||||||
$expression = new Limit(10, 2);
|
|
||||||
|
|
||||||
$query = '|> limit(n: 10, offset: 2) ';
|
$query = '|> limit(n: 10, offset: 2) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
use Hosterra\FluxBuilder\Functions\Map;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
|
use Hosterra\FluxBuilder\Expression\Map as MapExpression;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\Selection as SelectionExpression;
|
use Hosterra\FluxBuilder\Expression\Selection as SelectionExpression;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class MapFunctionTest extends TestCase
|
final class MapFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleMap() {
|
||||||
public function testSimpleMap()
|
$expression = new Map( 'r with name: r.user' );
|
||||||
{
|
|
||||||
$expression = new Map('r with name: r.user');
|
|
||||||
|
|
||||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithMapObject()
|
public function testWithMapObject() {
|
||||||
{
|
$expression = new Map( MapExpression::with( 'name', 'r.user' ) );
|
||||||
$expression = new Map(MapExpression::with('name', 'r.user'));
|
|
||||||
|
|
||||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRecordMapObject()
|
public function testRecordMapObject() {
|
||||||
{
|
$expression = new Map( MapExpression::columns( [
|
||||||
$expression = new Map(MapExpression::columns([
|
|
||||||
'time' => 'r._time',
|
'time' => 'r._time',
|
||||||
'source' => 'r.tag',
|
'source' => 'r.tag',
|
||||||
'alert' => SelectionExpression::if('r._value > 10')->then(true)->else(false)->__toString(),
|
'alert' => SelectionExpression::if( 'r._value > 10' )->then( true )->else( false )->__toString(),
|
||||||
'test' => SelectionExpression::if('r._value > 10')->then('yes')->else('no')->__toString()
|
'test' => SelectionExpression::if( 'r._value > 10' )->then( 'yes' )->else( 'no' )->__toString()
|
||||||
])->__toString());
|
] )->__toString() );
|
||||||
|
|
||||||
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
|
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
|
||||||
'alert: if r._value > 10 then true else false, ' .
|
'alert: if r._value > 10 then true else false, ' .
|
||||||
'test: if r._value > 10 then "yes" else "no"} })) ';
|
'test: if r._value > 10 then "yes" else "no"} })) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Max;
|
use Hosterra\FluxBuilder\Functions\Max;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class MaxFunctionTest extends TestCase
|
final class MaxFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleMax() {
|
||||||
public function testSimpleMax()
|
|
||||||
{
|
|
||||||
$expression = new Max();
|
$expression = new Max();
|
||||||
|
|
||||||
$query = '|> max() ';
|
$query = '|> max() ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMaxWithColumn()
|
public function testMaxWithColumn() {
|
||||||
{
|
$expression = new Max( 'something' );
|
||||||
$expression = new Max('something');
|
|
||||||
|
|
||||||
$query = '|> max(column: "something") ';
|
$query = '|> max(column: "something") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Mean;
|
use Hosterra\FluxBuilder\Functions\Mean;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class MeanFunctionTest extends TestCase
|
final class MeanFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleMean() {
|
||||||
public function testSimpleMean()
|
|
||||||
{
|
|
||||||
$expression = new Mean();
|
$expression = new Mean();
|
||||||
|
|
||||||
$query = '|> mean() ';
|
$query = '|> mean() ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithParameterColumn()
|
public function testWithParameterColumn() {
|
||||||
{
|
$expression = new Mean( 'test' );
|
||||||
$expression = new Mean('test');
|
|
||||||
|
|
||||||
$query = '|> mean(column: "test") ';
|
$query = '|> mean(column: "test") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Min;
|
use Hosterra\FluxBuilder\Functions\Min;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class MinFunctionTest extends TestCase
|
final class MinFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleMin() {
|
||||||
public function testSimpleMin()
|
|
||||||
{
|
|
||||||
$expression = new Min();
|
$expression = new Min();
|
||||||
|
|
||||||
$query = '|> min() ';
|
$query = '|> min() ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMinWithColumn()
|
public function testMinWithColumn() {
|
||||||
{
|
$expression = new Min( 'something' );
|
||||||
$expression = new Min('something');
|
|
||||||
|
|
||||||
$query = '|> min(column: "something") ';
|
$query = '|> min(column: "something") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,47 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Range;
|
use Hosterra\FluxBuilder\Functions\Range;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class RangeFunctionTest extends TestCase
|
final class RangeFunctionTest extends TestCase {
|
||||||
{
|
public function testOnlyStartOption() {
|
||||||
public function testOnlyStartOption()
|
|
||||||
{
|
|
||||||
$expression = new Range(
|
$expression = new Range(
|
||||||
new DateTime('2022-08-12 18:00:00')
|
new DateTime( '2022-08-12 18:00:00' )
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
|
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithStopOption()
|
public function testWithStopOption() {
|
||||||
{
|
|
||||||
$expression = new Range(
|
$expression = new Range(
|
||||||
new DateTime('2022-08-12 18:00:00'),
|
new DateTime( '2022-08-12 18:00:00' ),
|
||||||
new DateTime('2022-08-12 20:00:00')
|
new DateTime( '2022-08-12 20:00:00' )
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
|
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRangeInBetween()
|
public function testRangeInBetween() {
|
||||||
{
|
|
||||||
$expression = new Range(
|
$expression = new Range(
|
||||||
new DateTime('2022-08-12 17:31:00'),
|
new DateTime( '2022-08-12 17:31:00' ),
|
||||||
new DateTime('2022-08-12 18:31:00')
|
new DateTime( '2022-08-12 18:31:00' )
|
||||||
);
|
);
|
||||||
|
|
||||||
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
|
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
|
||||||
|
|
||||||
$this->assertEquals($expected, $expression->__toString());
|
$this->assertEquals( $expected, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
use Hosterra\FluxBuilder\Functions\Reduce;
|
||||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
use Hosterra\FluxBuilder\Type\MathType;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class ReduceFunctionTest extends TestCase
|
final class ReduceFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleReduce() {
|
||||||
public function testSimpleReduce()
|
$expression = new Reduce( [ 'sum' => new MathType( 'r._value + accumulator.sum' ) ], [ 'sum' => 0 ] );
|
||||||
{
|
|
||||||
$expression = new Reduce(['sum' => new MathType('r._value + accumulator.sum')], ['sum' => 0]);
|
|
||||||
|
|
||||||
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
|
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
use Hosterra\FluxBuilder\Functions\Sort;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class SortFunctionTest extends TestCase
|
final class SortFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleSort() {
|
||||||
public function testSimpleSort()
|
$expression = new Sort( [ 'foo', 'bar' ], true );
|
||||||
{
|
|
||||||
$expression = new Sort(['foo', 'bar'], true);
|
|
||||||
|
|
||||||
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
|
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Sum;
|
use Hosterra\FluxBuilder\Functions\Sum;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class SumFunctionTest extends TestCase
|
final class SumFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleSum() {
|
||||||
public function testSimpleSum()
|
$expression = new Sum( '_value' );
|
||||||
{
|
|
||||||
$expression = new Sum('_value');
|
|
||||||
|
|
||||||
$query = '|> sum(column: "_value") ';
|
$query = '|> sum(column: "_value") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Unique;
|
use Hosterra\FluxBuilder\Functions\Unique;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class UniqueunctionTest extends TestCase
|
final class UniqueunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleUnique() {
|
||||||
public function testSimpleUnique()
|
|
||||||
{
|
|
||||||
$expression = new Unique();
|
$expression = new Unique();
|
||||||
|
|
||||||
$query = '|> unique() ';
|
$query = '|> unique() ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUniqueWithColumn()
|
public function testUniqueWithColumn() {
|
||||||
{
|
$expression = new Unique( 'something' );
|
||||||
$expression = new Unique('something');
|
|
||||||
|
|
||||||
$query = '|> unique(column: "something") ';
|
$query = '|> unique(column: "something") ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Functions;
|
namespace Tests\Functions;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Window;
|
use Hosterra\FluxBuilder\Functions\Window;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class WindowFunctionTest extends TestCase
|
final class WindowFunctionTest extends TestCase {
|
||||||
{
|
public function testSimpleWindow() {
|
||||||
public function testSimpleWindow()
|
$expression = new Window( '20s' );
|
||||||
{
|
|
||||||
$expression = new Window('20s');
|
|
||||||
|
|
||||||
$query = '|> window(every: 20s) ';
|
$query = '|> window(every: 20s) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAllParameters()
|
public function testAllParameters() {
|
||||||
{
|
$expression = new Window( '20s', [
|
||||||
$expression = new Window('20s', [
|
|
||||||
'period' => 'every',
|
'period' => 'every',
|
||||||
'offset' => '0s',
|
'offset' => '0s',
|
||||||
'location' => 'location',
|
'location' => 'location',
|
||||||
|
|
@ -28,11 +25,11 @@ final class WindowFunctionTest extends TestCase
|
||||||
'startColumn' => '_start',
|
'startColumn' => '_start',
|
||||||
'stopColumn' => '_stop',
|
'stopColumn' => '_stop',
|
||||||
'createEmpty' => true
|
'createEmpty' => true
|
||||||
]);
|
] );
|
||||||
|
|
||||||
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
||||||
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
||||||
|
|
||||||
$this->assertEquals($query, $expression->__toString());
|
$this->assertEquals( $query, $expression->__toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,99 +1,96 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
|
||||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
|
||||||
|
|
||||||
final class QueryBuilderTest extends TestCase
|
use PHPUnit\Framework\TestCase;
|
||||||
{
|
use Hosterra\FluxBuilder\QueryBuilder;
|
||||||
|
use Hosterra\FluxBuilder\Type\MathType;
|
||||||
|
|
||||||
|
final class QueryBuilderTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* @dataProvider newTestsProvider
|
* @dataProvider newTestsProvider
|
||||||
*/
|
*/
|
||||||
public function testBasicQuery(string $methodName, array $params = [], string $expected = '')
|
public function testBasicQuery( string $methodName, array $params = [], string $expected = '' ) {
|
||||||
{
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
$queryBuilder->fromBucket('test_bucket')
|
$queryBuilder->fromBucket( 'test_bucket' )
|
||||||
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
|
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) )
|
||||||
->fromMeasurement('test_measurement');
|
->fromMeasurement( 'test_measurement' );
|
||||||
|
|
||||||
call_user_func_array([$queryBuilder, $methodName], $params);
|
call_user_func_array( [ $queryBuilder, $methodName ], $params );
|
||||||
|
|
||||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
||||||
'|> filter(fn: (r) => r._measurement == "test_measurement") ' . $expected;
|
'|> filter(fn: (r) => r._measurement == "test_measurement") ' . $expected;
|
||||||
|
|
||||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
$this->assertEquals( $expectedQuery, $queryBuilder->build() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newTestsProvider(): array
|
public function newTestsProvider(): array {
|
||||||
{
|
|
||||||
return [
|
return [
|
||||||
'addAggregateWindow' => [
|
'addAggregateWindow' => [
|
||||||
'addAggregateWindow',
|
'addAggregateWindow',
|
||||||
['20s', 'mean', ['timeDst' => '_time']],
|
[ '20s', 'mean', [ 'timeDst' => '_time' ] ],
|
||||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||||
],
|
],
|
||||||
'addBottom' => [
|
'addBottom' => [
|
||||||
'addBottom',
|
'addBottom',
|
||||||
[2, ['_value']],
|
[ 2, [ '_value' ] ],
|
||||||
'|> bottom(n: 2, columns: ["_value"]) '
|
'|> bottom(n: 2, columns: ["_value"]) '
|
||||||
],
|
],
|
||||||
'addCount' => [
|
'addCount' => [
|
||||||
'addCount',
|
'addCount',
|
||||||
['_value'],
|
[ '_value' ],
|
||||||
'|> count(column: "_value") '
|
'|> count(column: "_value") '
|
||||||
],
|
],
|
||||||
'addDuplicate' => [
|
'addDuplicate' => [
|
||||||
'addDuplicate',
|
'addDuplicate',
|
||||||
['old_name', 'new_name'],
|
[ 'old_name', 'new_name' ],
|
||||||
'|> duplicate(column: "old_name", as: "new_name") '
|
'|> duplicate(column: "old_name", as: "new_name") '
|
||||||
],
|
],
|
||||||
'addFilter' => [
|
'addFilter' => [
|
||||||
'addFilter',
|
'addFilter',
|
||||||
[KeyValue::setGreaterOrEqualTo('count', 2)->andGreaterOrEqualTo('count2', 3)],
|
[ KeyValue::setGreaterOrEqualTo( 'count', 2 )->andGreaterOrEqualTo( 'count2', 3 ) ],
|
||||||
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) '
|
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) '
|
||||||
],
|
],
|
||||||
'addKeyFilter' => [
|
'addKeyFilter' => [
|
||||||
'addKeyFilter',
|
'addKeyFilter',
|
||||||
[KeyFilter::setEqualTo('user', 'username')],
|
[ KeyFilter::setEqualTo( 'user', 'username' ) ],
|
||||||
'|> filter(fn: (r) => r.user == "username") '
|
'|> filter(fn: (r) => r.user == "username") '
|
||||||
],
|
],
|
||||||
'addFieldFilter' => [
|
'addFieldFilter' => [
|
||||||
'addFieldFilter',
|
'addFieldFilter',
|
||||||
[['email', 'username']],
|
[ [ 'email', 'username' ] ],
|
||||||
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
|
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
|
||||||
],
|
],
|
||||||
'addFirst' => [
|
'addFirst' => [
|
||||||
'addFirst',
|
'addFirst',
|
||||||
['something'],
|
[ 'something' ],
|
||||||
'|> first(column: "something") '
|
'|> first(column: "something") '
|
||||||
],
|
],
|
||||||
'addGroup' => [
|
'addGroup' => [
|
||||||
'addGroup',
|
'addGroup',
|
||||||
[['_field', 'ip']],
|
[ [ '_field', 'ip' ] ],
|
||||||
'|> group(columns: ["_field", "ip"], mode: "by") '
|
'|> group(columns: ["_field", "ip"], mode: "by") '
|
||||||
],
|
],
|
||||||
'addLast' => [
|
'addLast' => [
|
||||||
'addLast',
|
'addLast',
|
||||||
['something'],
|
[ 'something' ],
|
||||||
'|> last(column: "something") '
|
'|> last(column: "something") '
|
||||||
],
|
],
|
||||||
'addLimit' => [
|
'addLimit' => [
|
||||||
'addLimit',
|
'addLimit',
|
||||||
[20, 40],
|
[ 20, 40 ],
|
||||||
'|> limit(n: 20, offset: 40) '
|
'|> limit(n: 20, offset: 40) '
|
||||||
],
|
],
|
||||||
'addMap' => [
|
'addMap' => [
|
||||||
'addMap',
|
'addMap',
|
||||||
['r with name: r.user'],
|
[ 'r with name: r.user' ],
|
||||||
'|> map(fn: (r) => ({ r with name: r.user })) '
|
'|> map(fn: (r) => ({ r with name: r.user })) '
|
||||||
],
|
],
|
||||||
'addMax' => [
|
'addMax' => [
|
||||||
|
|
@ -103,37 +100,37 @@ final class QueryBuilderTest extends TestCase
|
||||||
],
|
],
|
||||||
'addMean' => [
|
'addMean' => [
|
||||||
'addMean',
|
'addMean',
|
||||||
['something'],
|
[ 'something' ],
|
||||||
'|> mean(column: "something") '
|
'|> mean(column: "something") '
|
||||||
],
|
],
|
||||||
'addMin' => [
|
'addMin' => [
|
||||||
'addMin',
|
'addMin',
|
||||||
['something'],
|
[ 'something' ],
|
||||||
'|> min(column: "something") '
|
'|> min(column: "something") '
|
||||||
],
|
],
|
||||||
'addRawFunction' => [
|
'addRawFunction' => [
|
||||||
'addRawFunction',
|
'addRawFunction',
|
||||||
['|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time")'],
|
[ '|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time")' ],
|
||||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||||
],
|
],
|
||||||
'addReduce' => [
|
'addReduce' => [
|
||||||
'addReduce',
|
'addReduce',
|
||||||
[['count' => new MathType('accumulator.count + 1')], ['count' => 0]],
|
[ [ 'count' => new MathType( 'accumulator.count + 1' ) ], [ 'count' => 0 ] ],
|
||||||
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) '
|
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) '
|
||||||
],
|
],
|
||||||
'addSort' => [
|
'addSort' => [
|
||||||
'addSort',
|
'addSort',
|
||||||
[['column1', 'column2'], true],
|
[ [ 'column1', 'column2' ], true ],
|
||||||
'|> sort(columns: ["column1", "column2"], desc: true) '
|
'|> sort(columns: ["column1", "column2"], desc: true) '
|
||||||
],
|
],
|
||||||
'addSum' => [
|
'addSum' => [
|
||||||
'addSum',
|
'addSum',
|
||||||
['something'],
|
[ 'something' ],
|
||||||
'|> sum(column: "something") '
|
'|> sum(column: "something") '
|
||||||
],
|
],
|
||||||
'addUnique' => [
|
'addUnique' => [
|
||||||
'addUnique',
|
'addUnique',
|
||||||
['something'],
|
[ 'something' ],
|
||||||
'|> unique(column: "something") '
|
'|> unique(column: "something") '
|
||||||
],
|
],
|
||||||
'addUnwindow' => [
|
'addUnwindow' => [
|
||||||
|
|
@ -143,7 +140,7 @@ final class QueryBuilderTest extends TestCase
|
||||||
],
|
],
|
||||||
'addWindow' => [
|
'addWindow' => [
|
||||||
'addWindow',
|
'addWindow',
|
||||||
['20s', ['timeColumn' => '_time']],
|
[ '20s', [ 'timeColumn' => '_time' ] ],
|
||||||
'|> window(every: 20s, timeColumn: "_time") '
|
'|> window(every: 20s, timeColumn: "_time") '
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
@ -152,64 +149,66 @@ final class QueryBuilderTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider throwsExceptionWithoutRequiredDataProvider
|
* @dataProvider throwsExceptionWithoutRequiredDataProvider
|
||||||
*/
|
*/
|
||||||
public function testThrowsExceptionWithoutRequiredData($from, $measurement, $range)
|
public function testThrowsExceptionWithoutRequiredData( $from, $measurement, $range ) {
|
||||||
{
|
$this->expectException( Exception::class );
|
||||||
$this->expectException(Exception::class);
|
|
||||||
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
|
|
||||||
if ($from) {
|
if ( $from ) {
|
||||||
$queryBuilder->from($from);
|
$queryBuilder->from( $from );
|
||||||
}
|
}
|
||||||
if ($range) {
|
if ( $range ) {
|
||||||
$queryBuilder->addRangeStart($range['start']);
|
$queryBuilder->addRangeStart( $range['start'] );
|
||||||
}
|
}
|
||||||
if ($measurement) {
|
if ( $measurement ) {
|
||||||
$queryBuilder->fromMeasurement($measurement);
|
$queryBuilder->fromMeasurement( $measurement );
|
||||||
}
|
}
|
||||||
|
|
||||||
$queryBuilder->build();
|
$queryBuilder->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function throwsExceptionWithoutRequiredDataProvider(): array
|
public function throwsExceptionWithoutRequiredDataProvider(): array {
|
||||||
{
|
|
||||||
return [
|
return [
|
||||||
'without from data' => [
|
'without from data' => [
|
||||||
null, 'test_measurement', ['start' => new DateTime('2022-08-12 20:05:00')],
|
null,
|
||||||
|
'test_measurement',
|
||||||
|
[ 'start' => new DateTime( '2022-08-12 20:05:00' ) ],
|
||||||
],
|
],
|
||||||
'without measurement data' => [
|
'without measurement data' => [
|
||||||
['from' => 'test_bucket'], null, ['start' => new DateTime('2022-08-12 20:05:00')],
|
[ 'from' => 'test_bucket' ],
|
||||||
|
null,
|
||||||
|
[ 'start' => new DateTime( '2022-08-12 20:05:00' ) ],
|
||||||
],
|
],
|
||||||
'without range data' => [
|
'without range data' => [
|
||||||
['from' => 'test_bucket'], 'test_measurement', null,
|
[ 'from' => 'test_bucket' ],
|
||||||
|
'test_measurement',
|
||||||
|
null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThrowsExceptionWhenIncorrectOrder()
|
public function testThrowsExceptionWhenIncorrectOrder() {
|
||||||
{
|
$this->expectException( Exception::class );
|
||||||
$this->expectException(Exception::class);
|
|
||||||
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
$queryBuilder->from(['bucket' => 'test_bucket'])
|
$queryBuilder->from( [ 'bucket' => 'test_bucket' ] )
|
||||||
->fromMeasurement('test_measurement')
|
->fromMeasurement( 'test_measurement' )
|
||||||
->addRangeStart(new DateTime('2022-08-12 20:05:00'));
|
->addRangeStart( new DateTime( '2022-08-12 20:05:00' ) );
|
||||||
|
|
||||||
$queryBuilder->build();
|
$queryBuilder->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryWithWindow()
|
public function testQueryWithWindow() {
|
||||||
{
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
$queryBuilder->fromBucket('test_bucket')
|
$queryBuilder->fromBucket( 'test_bucket' )
|
||||||
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
|
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) )
|
||||||
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
|
->addReduce( [ 'count' => new MathType( 'accumulator.count + 1' ) ], [ 'count' => 0 ] )
|
||||||
->addWindow('20s')
|
->addWindow( '20s' )
|
||||||
->addMean()
|
->addMean()
|
||||||
->addDuplicate('tag', 'tag_dup')
|
->addDuplicate( 'tag', 'tag_dup' )
|
||||||
->fromMeasurement('test_measurement')
|
->fromMeasurement( 'test_measurement' )
|
||||||
->addFilter(KeyValue::setGreaterOrEqualTo('count', 2)->andGreaterOrEqualTo('count2', 3))
|
->addFilter( KeyValue::setGreaterOrEqualTo( 'count', 2 )->andGreaterOrEqualTo( 'count2', 3 ) )
|
||||||
->addKeyFilter(KeyFilter::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2))
|
->addKeyFilter( KeyFilter::setGreaterOrEqualTo( 'count', 1 )->andGreaterOrEqualTo( 'count2', 2 ) )
|
||||||
->addUnWindow();
|
->addUnWindow();
|
||||||
|
|
||||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
||||||
|
|
@ -219,38 +218,36 @@ final class QueryBuilderTest extends TestCase
|
||||||
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) ' .
|
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) ' .
|
||||||
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
|
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
|
||||||
|
|
||||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
$this->assertEquals( $expectedQuery, $queryBuilder->build() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCorrectInstancesAreCreated()
|
public function testCorrectInstancesAreCreated() {
|
||||||
{
|
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
$queryBuilder->fromBucket('test_bucket')
|
$queryBuilder->fromBucket( 'test_bucket' )
|
||||||
->addRangeStart(new DateTime('2022-08-12 17:31:00'));
|
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) );
|
||||||
|
|
||||||
$instances = [
|
$instances = [
|
||||||
\Arendsen\FluxQueryBuilder\Functions\From::class,
|
\Hosterra\FluxBuilder\Functions\From::class,
|
||||||
\Arendsen\FluxQueryBuilder\Functions\Range::class,
|
\Hosterra\FluxBuilder\Functions\Range::class,
|
||||||
\Arendsen\FluxQueryBuilder\Functions\Measurement::class,
|
\Hosterra\FluxBuilder\Functions\Measurement::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
$requiredFluxQueryParts = $this->getClassProperty($queryBuilder, 'requiredFluxQueryParts');
|
$requiredFluxQueryParts = $this->getClassProperty( $queryBuilder, 'requiredFluxQueryParts' );
|
||||||
|
|
||||||
foreach ($requiredFluxQueryParts as $keyPart => $part) {
|
foreach ( $requiredFluxQueryParts as $keyPart => $part ) {
|
||||||
$this->assertEquals($instances[$keyPart], $part);
|
$this->assertEquals( $instances[ $keyPart ], $part );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getClassProperty($object, string $property): array
|
private function getClassProperty( $object, string $property ): array {
|
||||||
{
|
$propertyReader = function & ( $object, $property ) {
|
||||||
$propertyReader = function & ($object, $property) {
|
$value = &Closure::bind( function & () use ( $property ) {
|
||||||
$value = & Closure::bind(function & () use ($property) {
|
|
||||||
return $this->$property;
|
return $this->$property;
|
||||||
}, $object, $object)->__invoke();
|
}, $object, $object )->__invoke();
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
};
|
};
|
||||||
|
|
||||||
return $propertyReader($object, $property);
|
return $propertyReader( $object, $property );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,32 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types=1 );
|
||||||
|
|
||||||
namespace Tests\Type;
|
namespace Tests\Type;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Hosterra\FluxBuilder\Type;
|
||||||
use Arendsen\FluxQueryBuilder\Type\CustomType;
|
use Hosterra\FluxBuilder\Type\CustomType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\DurationType;
|
use Hosterra\FluxBuilder\Type\DurationType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
use Hosterra\FluxBuilder\Type\FnType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
use Hosterra\FluxBuilder\Type\MathType;
|
||||||
use Arendsen\FluxQueryBuilder\Type\RecordType;
|
use Hosterra\FluxBuilder\Type\RecordType;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FactoryTypeTest extends TestCase
|
final class FactoryTypeTest extends TestCase {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getFluxStringProvider
|
* @dataProvider getFluxStringProvider
|
||||||
*/
|
*/
|
||||||
public function testGetFluxString($value, $expected)
|
public function testGetFluxString( $value, $expected ) {
|
||||||
{
|
$type = new Type( $value );
|
||||||
$type = new Type($value);
|
|
||||||
|
|
||||||
$this->assertEquals($expected, $type->__toString());
|
$this->assertEquals( $expected, $type->__toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFluxStringProvider()
|
public function getFluxStringProvider() {
|
||||||
{
|
|
||||||
return [
|
return [
|
||||||
'DateTime' => [
|
'DateTime' => [
|
||||||
new DateTime('2022-08-15 23:09:00'),
|
new DateTime( '2022-08-15 23:09:00' ),
|
||||||
'time(v: 2022-08-15T23:09:00Z)',
|
'time(v: 2022-08-15T23:09:00Z)',
|
||||||
],
|
],
|
||||||
'String' => [
|
'String' => [
|
||||||
|
|
@ -49,47 +46,47 @@ final class FactoryTypeTest extends TestCase
|
||||||
'false'
|
'false'
|
||||||
],
|
],
|
||||||
'Array' => [
|
'Array' => [
|
||||||
['hello', 'world'],
|
[ 'hello', 'world' ],
|
||||||
'"hello", "world"'
|
'"hello", "world"'
|
||||||
],
|
],
|
||||||
'Dictionary' => [
|
'Dictionary' => [
|
||||||
['hello' => 'world', 'foo' => 'bar'],
|
[ 'hello' => 'world', 'foo' => 'bar' ],
|
||||||
'hello: "world", foo: "bar"'
|
'hello: "world", foo: "bar"'
|
||||||
],
|
],
|
||||||
'Array Multidimensional' => [
|
'Array Multidimensional' => [
|
||||||
['hello' => ['test', 'foo']],
|
[ 'hello' => [ 'test', 'foo' ] ],
|
||||||
'hello: ["test", "foo"]'
|
'hello: ["test", "foo"]'
|
||||||
],
|
],
|
||||||
'Array Multidimensional 2' => [
|
'Array Multidimensional 2' => [
|
||||||
['hello' => ['test' => 'bar', 'foo' => 'hi']],
|
[ 'hello' => [ 'test' => 'bar', 'foo' => 'hi' ] ],
|
||||||
'hello: [test: "bar", foo: "hi"]'
|
'hello: [test: "bar", foo: "hi"]'
|
||||||
],
|
],
|
||||||
'RecordType' => [
|
'RecordType' => [
|
||||||
new RecordType(['foo' => 'bar', 'nested' => ['hello' => 'world']]),
|
new RecordType( [ 'foo' => 'bar', 'nested' => [ 'hello' => 'world' ] ] ),
|
||||||
'{foo: "bar", nested: {hello: "world"}}'
|
'{foo: "bar", nested: {hello: "world"}}'
|
||||||
],
|
],
|
||||||
'DurationType' => [
|
'DurationType' => [
|
||||||
new DurationType('5h'),
|
new DurationType( '5h' ),
|
||||||
'5h',
|
'5h',
|
||||||
],
|
],
|
||||||
'MathType' => [
|
'MathType' => [
|
||||||
new MathType('r.count + 1'),
|
new MathType( 'r.count + 1' ),
|
||||||
'r.count + 1'
|
'r.count + 1'
|
||||||
],
|
],
|
||||||
'CustomType' => [
|
'CustomType' => [
|
||||||
new CustomType('this can be anything'),
|
new CustomType( 'this can be anything' ),
|
||||||
'this can be anything'
|
'this can be anything'
|
||||||
],
|
],
|
||||||
'FnType with only content' => [
|
'FnType with only content' => [
|
||||||
FnType::params([])->withBlock('r with _value: r._value * r._value'),
|
FnType::params( [] )->withBlock( 'r with _value: r._value * r._value' ),
|
||||||
'() => { r with _value: r._value * r._value }'
|
'() => { r with _value: r._value * r._value }'
|
||||||
],
|
],
|
||||||
'FnType with params and a body' => [
|
'FnType with params and a body' => [
|
||||||
FnType::params(['r'])->withBody('r with _value: r._value * r._value'),
|
FnType::params( [ 'r' ] )->withBody( 'r with _value: r._value * r._value' ),
|
||||||
'(r) => r with _value: r._value * r._value'
|
'(r) => r with _value: r._value * r._value'
|
||||||
],
|
],
|
||||||
'FnType with params and a block' => [
|
'FnType with params and a block' => [
|
||||||
FnType::params(['r', 'a'])->withBlock('return r with _value: r._value * r._value'),
|
FnType::params( [ 'r', 'a' ] )->withBlock( 'return r with _value: r._value * r._value' ),
|
||||||
'(r, a) => { return r with _value: r._value * r._value }'
|
'(r, a) => { return r with _value: r._value * r._value }'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue