Marks fork as 2.0.0.

This commit is contained in:
Pierre Lannoy 2024-03-30 16:44:38 +01:00
commit 8d8de4a2b0
Signed by: Pierre Lannoy
GPG key ID: D27231EF87D53F31
81 changed files with 1921 additions and 3954 deletions

View file

@ -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

View file

@ -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

View file

@ -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.
[![Latest Stable Version](http://poser.pugx.org/arendsen/fluxquerybuilder/v)](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.
[![License](http://poser.pugx.org/arendsen/fluxquerybuilder/license)](https://packagist.org/packages/arendsen/fluxquerybuilder)
[![PHP Version Require](http://poser.pugx.org/arendsen/fluxquerybuilder/require/php)](https://packagist.org/packages/arendsen/fluxquerybuilder)
[![Tests](https://github.com/davidarendsen/fluxquerybuilder/actions/workflows/php.yml/badge.svg)](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).

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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

View file

@ -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)
``` ```

View file

@ -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")
``` ```

View file

@ -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',

View file

@ -33,7 +33,7 @@
### Example ### Example
```php ```php
use Arendsen\FluxQueryBuilder\Type\MathType; use Hosterra\FluxBuilder\Type\MathType;
``` ```
```php ```php

View file

@ -1,22 +1,19 @@
<?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(
@ -26,89 +23,71 @@ trait Basics
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->addToQuery(
new Filter($keyValue)
);
return $this;
}
public function addKeyFilter(KeyFilter $keyFilter): QueryBuilderInterface
{
$this->setRequirements(); $this->setRequirements();
$this->addToQuery( $this->addToQuery(
new Filter( $keyFilter ) new Filter( $keyFilter )
); );
return $this; return $this;
} }
public function addFieldFilter(array $fields): QueryBuilderInterface public function addFieldFilter( array $fields ): QueryBuilderInterface {
{
$this->setRequirements(); $this->setRequirements();
$this->addToQuery( $this->addToQuery(
new Filter( $fields ) new Filter( $fields )
); );
return $this; return $this;
} }
public function addRange(DateTime $start, ?DateTime $stop = null): QueryBuilderInterface public function addRange( DateTime $start, ?DateTime $stop = null ): QueryBuilderInterface {
{
$this->setRequirements(); $this->setRequirements();
$this->addToQuery( $this->addToQuery(
new Range( $start, $stop ) new Range( $start, $stop )
); );
return $this; return $this;
} }
public function addRangeStart(DateTime $start): QueryBuilderInterface public function addRangeStart( DateTime $start ): QueryBuilderInterface {
{
$this->addRange( $start ); $this->addRange( $start );
return $this; return $this;
} }
public function addRangeInBetween(DateTime $start, DateTime $stop): QueryBuilderInterface public function addRangeInBetween( DateTime $start, DateTime $stop ): QueryBuilderInterface {
{
$this->addRange( $start, $stop ); $this->addRange( $start, $stop );
return $this; return $this;
} }
public function addRawFunction(string $input): QueryBuilderInterface public function addRawFunction( string $input ): QueryBuilderInterface {
{
$this->addToQuery( $this->addToQuery(
new RawFunction( $input ) new RawFunction( $input )
); );
return $this; return $this;
} }
private function setRequirements() private function setRequirements() {
{
$this->requiredFluxQueryParts = [ $this->requiredFluxQueryParts = [
From::class, From::class,
Range::class, Range::class,

View file

@ -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;
} }

View file

@ -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;
} }
} }

View file

@ -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 {
{
} }

View file

@ -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 {
{
} }

View file

@ -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 {
{
} }

View file

@ -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 );
} }
} }

View file

@ -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 ) );
} }
} }

View file

@ -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,174 +31,162 @@ 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!' );
} }

View file

@ -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!');
}
}
}

View file

@ -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;
} }
} }

View file

@ -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;
} }
} }

View file

@ -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,15 +24,13 @@ 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,
@ -46,6 +43,7 @@ class AggregateWindow extends Base
'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 . ') ';
} }
} }

View file

@ -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 ) );
} }
} }

View file

@ -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 . ') ';
} }
} }

View file

@ -1,23 +1,20 @@
<?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
] ) ); ] ) );

View file

@ -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,14 +16,12 @@ 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

View file

@ -1,33 +1,29 @@
<?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 ) ) {

View file

@ -1,23 +1,20 @@
<?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
] ) ); ] ) );

View file

@ -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 ) . ') ';
} }
} }

View file

@ -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,14 +15,12 @@ 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,

View file

@ -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 . '") ';
} }
} }

View file

@ -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 . ') ';
} }
} }

View file

@ -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 . ' })) ';
} }
} }

View file

@ -1,23 +1,20 @@
<?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
] ) ); ] ) );

View file

@ -1,24 +1,21 @@
<?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

View file

@ -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 . '") ';
} }
} }

View file

@ -1,23 +1,20 @@
<?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
] ) ); ] ) );

View file

@ -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,14 +17,12 @@ 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!' );
} }

View file

@ -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 . ' ';
} }
} }

View file

@ -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,14 +15,12 @@ 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 ) . ') ';
} }

View file

@ -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,14 +15,12 @@ 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 ) . ') ';
} }

View file

@ -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 . '") ';
} }
} }

View file

@ -1,23 +1,20 @@
<?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
] ) ); ] ) );

View file

@ -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,14 +17,12 @@ 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,
@ -37,6 +34,7 @@ class Window extends Base
'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 . ') ';
} }
} }

View file

@ -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,8 +28,7 @@ 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 ) {
@ -38,8 +38,7 @@ class QueryBuilder implements QueryBuilderInterface
} }
} }
public function build(): string public function build(): string {
{
$this->checkRequired(); $this->checkRequired();
$query = ''; $query = '';
@ -51,8 +50,7 @@ class QueryBuilder implements QueryBuilderInterface
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!' );

View file

@ -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;
} }
} }

View file

@ -1,32 +1,30 @@
<?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 . '"';

View file

@ -1,24 +1,21 @@
<?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 );
@ -30,18 +27,15 @@ class ArrayType implements TypeInterface
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 ) ? ']' : '';
} }
} }

View file

@ -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';
} }
} }

View file

@ -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;
} }
} }

View file

@ -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;
} }
} }

View file

@ -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,13 +13,11 @@ 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;

View file

@ -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,30 +15,27 @@ 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 );

View file

@ -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;
} }
} }

View file

@ -1,23 +1,20 @@
<?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 );
@ -29,8 +26,7 @@ class RecordType implements TypeInterface
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 . ': ' : '';
} }
} }

View file

@ -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' ) . ')';
} }
} }

View file

@ -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;
} }

View file

@ -5,13 +5,11 @@ 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' ) $keyFilter = KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
->andEqualTo( '_field', 'user' ) ->andEqualTo( '_field', 'user' )
->or( 'count', '>=', '1' ) ->or( 'count', '>=', '1' )
@ -24,8 +22,7 @@ final class KeyFilterExpressionTest extends TestCase
$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' )

View file

@ -4,14 +4,12 @@ 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) ';
@ -19,8 +17,7 @@ final class AggregateWindowFunctionTest extends TestCase
$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"' ),

View file

@ -4,13 +4,11 @@ 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() ';
@ -18,8 +16,7 @@ final class CountFunctionTest extends TestCase
$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") ';

View file

@ -4,13 +4,11 @@ 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") ';

View file

@ -4,28 +4,14 @@ 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") ';
$this->assertEquals($expression->__toString(), $query);
}
public function testFieldFilter()
{
$expression = new Filter( [ 'user', 'field2', 'field3' ] ); $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") ';
@ -33,8 +19,7 @@ final class FilterFunctionTest extends TestCase
$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' )

View file

@ -4,13 +4,11 @@ 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() ';
@ -18,8 +16,7 @@ final class FirstFunctionTest extends TestCase
$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") ';

View file

@ -4,23 +4,20 @@ 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' => [
[ [

View file

@ -4,13 +4,11 @@ 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") ';

View file

@ -4,13 +4,11 @@ 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") ';
@ -18,8 +16,7 @@ final class LastFunctionTest extends TestCase
$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") ';

View file

@ -4,13 +4,11 @@ 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) ';
@ -18,8 +16,7 @@ final class LimitFunctionTest extends TestCase
$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) ';

View file

@ -4,15 +4,13 @@ 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 })) ';
@ -20,8 +18,7 @@ final class MapFunctionTest extends TestCase
$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 })) ';
@ -29,8 +26,7 @@ final class MapFunctionTest extends TestCase
$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',

View file

@ -4,13 +4,11 @@ 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() ';
@ -18,8 +16,7 @@ final class MaxFunctionTest extends TestCase
$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") ';

View file

@ -4,13 +4,11 @@ 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() ';
@ -18,8 +16,7 @@ final class MeanFunctionTest extends TestCase
$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") ';

View file

@ -4,13 +4,11 @@ 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() ';
@ -18,8 +16,7 @@ final class MinFunctionTest extends TestCase
$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") ';

View file

@ -5,13 +5,11 @@ 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' )
); );
@ -21,8 +19,7 @@ final class RangeFunctionTest extends TestCase
$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' )
@ -33,8 +30,7 @@ final class RangeFunctionTest extends TestCase
$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' )

View file

@ -4,14 +4,12 @@ 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}) ';

View file

@ -4,13 +4,11 @@ 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) ';

View file

@ -4,13 +4,11 @@ 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") ';

View file

@ -4,13 +4,11 @@ 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() ';
@ -18,8 +16,7 @@ final class UniqueunctionTest extends TestCase
$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") ';

View file

@ -4,13 +4,11 @@ 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) ';
@ -18,8 +16,7 @@ final class WindowFunctionTest extends TestCase
$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',

View file

@ -7,19 +7,17 @@ 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' ) )
@ -33,8 +31,7 @@ final class QueryBuilderTest extends TestCase
$this->assertEquals( $expectedQuery, $queryBuilder->build() ); $this->assertEquals( $expectedQuery, $queryBuilder->build() );
} }
public function newTestsProvider(): array public function newTestsProvider(): array {
{
return [ return [
'addAggregateWindow' => [ 'addAggregateWindow' => [
'addAggregateWindow', 'addAggregateWindow',
@ -152,8 +149,7 @@ 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();
@ -171,23 +167,27 @@ final class QueryBuilderTest extends TestCase
$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();
@ -198,8 +198,7 @@ final class QueryBuilderTest extends TestCase
$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' ) )
@ -222,16 +221,15 @@ final class QueryBuilderTest extends TestCase
$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' );
@ -241,8 +239,7 @@ final class QueryBuilderTest extends TestCase
} }
} }
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;

View file

@ -5,28 +5,25 @@ 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' ),