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)
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
this software and associated documentation files (the "Software"), to deal in

View file

@ -1,20 +1,14 @@
# 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)
[![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)
>Note: this package is a fork of the David Arendsen [fluxquerybuilder](https://github.com/davidarendsen/fluxquerybuilder) package; original credits go to him.
## Documentation
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
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
To execute the testing suite:
@ -22,16 +16,3 @@ To execute the testing suite:
```
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",
"description": "A package to build Flux queries in PHP.",
"description": "A package to build Flux queries with PHP.",
"keywords": [ "influxdb", "flux" ],
"license": "MIT",
"autoload": {
"psr-4": {
"Arendsen\\FluxQueryBuilder\\": "src/",
"Hosterra\\FluxBuilder\\": "src/",
"Tests\\": "tests/"
}
},
"require": {
"php": ">=7.2"
"php": ">=8.2"
},
"require-dev": {
"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:
```
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.
@ -12,8 +12,8 @@ The most basic Flux query can be made with the following code. It has filters fo
```php
<?php
use Arendsen\FluxQueryBuilder\QueryBuilder;
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
use Hosterra\FluxBuilder\QueryBuilder;
use Hosterra\FluxBuilder\Expression\KeyFilter;
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket('test_bucket')
@ -35,12 +35,8 @@ Which will result in the following Flux query:
from(bucket: "test_bucket")
|> range(start: time(v: 2022-12-28T13:21:11Z))
|> filter(fn: (r) => r._measurement == "test_measurement")
|> filter(fn: (r) =>
r._field == "username" or r._field == "email"
)
|> filter(fn: (r) =>
r.username == "David" and r.email == "david@example.com"
)
|> filter(fn: (r) => r._field == "username" or r._field == "email" )
|> filter(fn: (r) => r.username == "David" and r.email == "david@example.com" )
|> 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
from(bucket: "example-bucket")
|> range(start: -1h)
|> filter(fn: (r) =>
r._measurement == "example-measurement"
and r.tag == "example-tag"
)
|> filter(fn: (r) => r._measurement == "example-measurement" and r.tag == "example-tag" )
|> filter(fn: (r) => r._field == "example-field")
```

View file

@ -92,7 +92,7 @@ This will result in the following Flux function part:
### Advanced example
```php
use Arendsen\FluxQueryBuilder\Type\FnType;
use Hosterra\FluxBuilder\Type\FnType;
->addAggregateWindow(
'20s',

View file

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

View file

@ -1,118 +1,97 @@
<?php
namespace Arendsen\FluxQueryBuilder\Builder;
namespace Hosterra\FluxBuilder\Builder;
use DateTime;
use Arendsen\FluxQueryBuilder\QueryBuilder;
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
use Arendsen\FluxQueryBuilder\Functions\Filter;
use Arendsen\FluxQueryBuilder\Functions\From;
use Arendsen\FluxQueryBuilder\Functions\Measurement;
use Arendsen\FluxQueryBuilder\Functions\Range;
use Arendsen\FluxQueryBuilder\Functions\RawFunction;
use Hosterra\FluxBuilder\QueryBuilder;
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
use Hosterra\FluxBuilder\Expression\KeyFilter;
use Hosterra\FluxBuilder\Functions\Filter;
use Hosterra\FluxBuilder\Functions\From;
use Hosterra\FluxBuilder\Functions\Measurement;
use Hosterra\FluxBuilder\Functions\Range;
use Hosterra\FluxBuilder\Functions\RawFunction;
trait Basics
{
public function from(array $from): QueryBuilderInterface
{
$this->setRequirements();
trait Basics {
public function from( array $from ): QueryBuilderInterface {
$this->setRequirements();
$this->addToQuery(
new From($from)
);
$this->addToQuery(
new From( $from )
);
return $this;
}
return $this;
}
public function fromBucket(string $bucket): QueryBuilderInterface
{
return $this->from(['bucket' => $bucket]);
}
public function fromBucket( string $bucket ): QueryBuilderInterface {
return $this->from( [ 'bucket' => $bucket ] );
}
public function fromMeasurement(string $measurement): QueryBuilderInterface
{
$this->setRequirements();
public function fromMeasurement( string $measurement ): QueryBuilderInterface {
$this->setRequirements();
$this->addToQuery(
new Measurement($measurement)
);
return $this;
}
$this->addToQuery(
new Measurement( $measurement )
);
/**
* @deprecated
*
* @param KeyValue $keyValue
* @return QueryBuilder
*/
public function addFilter(KeyValue $keyValue): QueryBuilderInterface
{
$this->setRequirements();
return $this;
}
$this->addToQuery(
new Filter($keyValue)
);
return $this;
}
public function addKeyFilter( KeyFilter $keyFilter ): QueryBuilderInterface {
$this->setRequirements();
public function addKeyFilter(KeyFilter $keyFilter): QueryBuilderInterface
{
$this->setRequirements();
$this->addToQuery(
new Filter( $keyFilter )
);
$this->addToQuery(
new Filter($keyFilter)
);
return $this;
}
return $this;
}
public function addFieldFilter(array $fields): QueryBuilderInterface
{
$this->setRequirements();
public function addFieldFilter( array $fields ): QueryBuilderInterface {
$this->setRequirements();
$this->addToQuery(
new Filter($fields)
);
return $this;
}
$this->addToQuery(
new Filter( $fields )
);
public function addRange(DateTime $start, ?DateTime $stop = null): QueryBuilderInterface
{
$this->setRequirements();
return $this;
}
$this->addToQuery(
new Range($start, $stop)
);
return $this;
}
public function addRange( DateTime $start, ?DateTime $stop = null ): QueryBuilderInterface {
$this->setRequirements();
public function addRangeStart(DateTime $start): QueryBuilderInterface
{
$this->addRange($start);
return $this;
}
$this->addToQuery(
new Range( $start, $stop )
);
public function addRangeInBetween(DateTime $start, DateTime $stop): QueryBuilderInterface
{
$this->addRange($start, $stop);
return $this;
}
return $this;
}
public function addRawFunction(string $input): QueryBuilderInterface
{
$this->addToQuery(
new RawFunction($input)
);
return $this;
}
public function addRangeStart( DateTime $start ): QueryBuilderInterface {
$this->addRange( $start );
private function setRequirements()
{
$this->requiredFluxQueryParts = [
From::class,
Range::class,
Measurement::class,
];
}
return $this;
}
public function addRangeInBetween( DateTime $start, DateTime $stop ): QueryBuilderInterface {
$this->addRange( $start, $stop );
return $this;
}
public function addRawFunction( string $input ): QueryBuilderInterface {
$this->addToQuery(
new RawFunction( $input )
);
return $this;
}
private function setRequirements() {
$this->requiredFluxQueryParts = [
From::class,
Range::class,
Measurement::class,
];
}
}

View file

@ -1,8 +1,7 @@
<?php
namespace Arendsen\FluxQueryBuilder\Builder;
namespace Hosterra\FluxBuilder\Builder;
interface QueryBuilderInterface
{
public function build(): string;
interface QueryBuilderInterface {
public function build(): string;
}

View file

@ -1,167 +1,166 @@
<?php
namespace Arendsen\FluxQueryBuilder\Builder;
namespace Hosterra\FluxBuilder\Builder;
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
use Arendsen\FluxQueryBuilder\Functions\Bottom;
use Arendsen\FluxQueryBuilder\Functions\Count;
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
use Arendsen\FluxQueryBuilder\Functions\First;
use Arendsen\FluxQueryBuilder\Functions\Group;
use Arendsen\FluxQueryBuilder\Functions\Last;
use Arendsen\FluxQueryBuilder\Functions\Limit;
use Arendsen\FluxQueryBuilder\Functions\Map;
use Arendsen\FluxQueryBuilder\Functions\Max;
use Arendsen\FluxQueryBuilder\Functions\Mean;
use Arendsen\FluxQueryBuilder\Functions\Min;
use Arendsen\FluxQueryBuilder\Functions\Reduce;
use Arendsen\FluxQueryBuilder\Functions\Sort;
use Arendsen\FluxQueryBuilder\Functions\Sum;
use Arendsen\FluxQueryBuilder\Functions\Unique;
use Arendsen\FluxQueryBuilder\Functions\Window;
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
use Hosterra\FluxBuilder\Functions\AggregateWindow;
use Hosterra\FluxBuilder\Functions\Bottom;
use Hosterra\FluxBuilder\Functions\Count;
use Hosterra\FluxBuilder\Functions\Duplicate;
use Hosterra\FluxBuilder\Functions\First;
use Hosterra\FluxBuilder\Functions\Group;
use Hosterra\FluxBuilder\Functions\Last;
use Hosterra\FluxBuilder\Functions\Limit;
use Hosterra\FluxBuilder\Functions\Map;
use Hosterra\FluxBuilder\Functions\Max;
use Hosterra\FluxBuilder\Functions\Mean;
use Hosterra\FluxBuilder\Functions\Min;
use Hosterra\FluxBuilder\Functions\Reduce;
use Hosterra\FluxBuilder\Functions\Sort;
use Hosterra\FluxBuilder\Functions\Sum;
use Hosterra\FluxBuilder\Functions\Unique;
use Hosterra\FluxBuilder\Functions\Window;
trait Universe
{
public function addAggregateWindow($every, $fn, array $options = []): QueryBuilderInterface
{
$this->addToQuery(
new AggregateWindow($every, $fn, $options)
);
return $this;
}
trait Universe {
public function addAggregateWindow( $every, $fn, array $options = [] ): QueryBuilderInterface {
$this->addToQuery(
new AggregateWindow( $every, $fn, $options )
);
public function addBottom(int $n, array $columns = []): QueryBuilderInterface
{
$this->addToQuery(new Bottom($n, $columns));
return $this;
}
return $this;
}
public function addCount(?string $column = null): QueryBuilderInterface
{
$this->addToQuery(
new Count($column)
);
return $this;
}
public function addBottom( int $n, array $columns = [] ): QueryBuilderInterface {
$this->addToQuery( new Bottom( $n, $columns ) );
public function addDuplicate(string $column, string $as): QueryBuilderInterface
{
$this->addToQuery(
new Duplicate($column, $as)
);
return $this;
}
return $this;
}
public function addFirst(?string $column = null): QueryBuilderInterface
{
$this->addToQuery(
new First($column)
);
return $this;
}
public function addCount( ?string $column = null ): QueryBuilderInterface {
$this->addToQuery(
new Count( $column )
);
public function addGroup(array $columns, $mode = 'by'): QueryBuilderInterface
{
$this->addToQuery(
new Group($columns, $mode)
);
return $this;
}
return $this;
}
public function addLast(string $column = '_value'): QueryBuilderInterface
{
$this->addToQuery(
new Last($column)
);
return $this;
}
public function addDuplicate( string $column, string $as ): QueryBuilderInterface {
$this->addToQuery(
new Duplicate( $column, $as )
);
public function addLimit(int $limit, int $offset = 0): QueryBuilderInterface
{
$this->addToQuery(
new Limit($limit, $offset)
);
return $this;
}
return $this;
}
public function addMap($query): QueryBuilderInterface
{
$this->addToQuery(
new Map($query)
);
return $this;
}
public function addFirst( ?string $column = null ): QueryBuilderInterface {
$this->addToQuery(
new First( $column )
);
public function addMax(?string $column = null): QueryBuilderInterface
{
$this->addToQuery(
new Max($column)
);
return $this;
}
return $this;
}
public function addMean(?string $column = ''): QueryBuilderInterface
{
$this->addToQuery(
new Mean($column)
);
return $this;
}
public function addGroup( array $columns, $mode = 'by' ): QueryBuilderInterface {
$this->addToQuery(
new Group( $columns, $mode )
);
public function addMin(?string $column = null): QueryBuilderInterface
{
$this->addToQuery(
new Min($column)
);
return $this;
}
return $this;
}
public function addReduce(array $settings, array $identity): QueryBuilderInterface
{
$this->addToQuery(
new Reduce($settings, $identity)
);
return $this;
}
public function addLast( string $column = '_value' ): QueryBuilderInterface {
$this->addToQuery(
new Last( $column )
);
public function addSort(array $columns = ['_value'], bool $desc = false): QueryBuilderInterface
{
$this->addToQuery(
new Sort($columns, $desc)
);
return $this;
}
return $this;
}
public function addSum(string $column): QueryBuilderInterface
{
$this->addToQuery(
new Sum($column)
);
return $this;
}
public function addLimit( int $limit, int $offset = 0 ): QueryBuilderInterface {
$this->addToQuery(
new Limit( $limit, $offset )
);
public function addUnique(?string $column = null): QueryBuilderInterface
{
$this->addToQuery(
new Unique($column)
);
return $this;
}
return $this;
}
public function addUnWindow(): QueryBuilderInterface
{
$this->addToQuery(
new Window('inf')
);
return $this;
}
public function addMap( $query ): QueryBuilderInterface {
$this->addToQuery(
new Map( $query )
);
public function addWindow($every, array $options = []): QueryBuilderInterface
{
$this->addToQuery(
new Window($every, $options)
);
return $this;
}
return $this;
}
public function addMax( ?string $column = null ): QueryBuilderInterface {
$this->addToQuery(
new Max( $column )
);
return $this;
}
public function addMean( ?string $column = '' ): QueryBuilderInterface {
$this->addToQuery(
new Mean( $column )
);
return $this;
}
public function addMin( ?string $column = null ): QueryBuilderInterface {
$this->addToQuery(
new Min( $column )
);
return $this;
}
public function addReduce( array $settings, array $identity ): QueryBuilderInterface {
$this->addToQuery(
new Reduce( $settings, $identity )
);
return $this;
}
public function addSort( array $columns = [ '_value' ], bool $desc = false ): QueryBuilderInterface {
$this->addToQuery(
new Sort( $columns, $desc )
);
return $this;
}
public function addSum( string $column ): QueryBuilderInterface {
$this->addToQuery(
new Sum( $column )
);
return $this;
}
public function addUnique( ?string $column = null ): QueryBuilderInterface {
$this->addToQuery(
new Unique( $column )
);
return $this;
}
public function addUnWindow(): QueryBuilderInterface {
$this->addToQuery(
new Window( 'inf' )
);
return $this;
}
public function addWindow( $every, array $options = [] ): QueryBuilderInterface {
$this->addToQuery(
new Window( $every, $options )
);
return $this;
}
}

View file

@ -1,9 +1,8 @@
<?php
namespace Arendsen\FluxQueryBuilder\Exception;
namespace Hosterra\FluxBuilder\Exception;
use Exception;
class ExpressionNotImplementedException extends Exception
{
class ExpressionNotImplementedException extends Exception {
}

View file

@ -1,9 +1,8 @@
<?php
namespace Arendsen\FluxQueryBuilder\Exception;
namespace Hosterra\FluxBuilder\Exception;
use Exception;
class FunctionInvalidInputException extends Exception
{
class FunctionInvalidInputException extends Exception {
}

View file

@ -1,9 +1,8 @@
<?php
namespace Arendsen\FluxQueryBuilder\Exception;
namespace Hosterra\FluxBuilder\Exception;
use Exception;
class FunctionNotImplementedException extends Exception
{
class FunctionNotImplementedException extends Exception {
}

View file

@ -1,13 +1,11 @@
<?php
namespace Arendsen\FluxQueryBuilder\Exception;
namespace Hosterra\FluxBuilder\Exception;
use Exception;
class FunctionRequiredSettingMissingException extends Exception
{
public function __construct(string $functionName, string $message)
{
parent::__construct('Function ' . $functionName . ' - ' . $message);
}
class FunctionRequiredSettingMissingException extends Exception {
public function __construct( string $functionName, string $message ) {
parent::__construct( 'Function ' . $functionName . ' - ' . $message );
}
}

View file

@ -1,16 +1,14 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression;
namespace Hosterra\FluxBuilder\Expression;
use Arendsen\FluxQueryBuilder\Exception\ExpressionNotImplementedException;
use Hosterra\FluxBuilder\Exception\ExpressionNotImplementedException;
abstract class Base
{
/**
* @throws ExpressionNotImplementedException
*/
public function __toString()
{
throw new ExpressionNotImplementedException('__toString', get_class($this));
}
abstract class Base {
/**
* @throws ExpressionNotImplementedException
*/
public function __toString() {
throw new ExpressionNotImplementedException( '__toString', get_class( $this ) );
}
}

View file

@ -1,207 +1,194 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression;
namespace Hosterra\FluxBuilder\Expression;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
use Exception;
class KeyFilter 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 = '!~';
class KeyFilter 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,
];
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;
/**
* @var array $expressions
*/
private $expressions;
private function __construct(string $key, string $operator, $value)
{
$this->checkOperator($operator);
$this->expressions[] = 'r.' . $key . ' ' . $operator . ' ' . new Type($value);
}
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): KeyFilter
{
return new self($key, $operator, $value);
}
public static function set( string $key, string $operator, $value ): KeyFilter {
return new self( $key, $operator, $value );
}
public static function setEqualTo(string $key, string $value): KeyFilter
{
return self::set($key, self::EQUAL_TO, $value);
}
public static function setEqualTo( string $key, string $value ): KeyFilter {
return self::set( $key, self::EQUAL_TO, $value );
}
public static function setNotEqualTo(string $key, string $value): KeyFilter
{
return self::set($key, self::NOT_EQUAL_TO, $value);
}
public static function setNotEqualTo( string $key, string $value ): KeyFilter {
return self::set( $key, self::NOT_EQUAL_TO, $value );
}
public static function setGreaterThan(string $key, int $value): KeyFilter
{
return self::set($key, self::GREATER_THAN, $value);
}
public static function setGreaterThan( string $key, int $value ): KeyFilter {
return self::set( $key, self::GREATER_THAN, $value );
}
public static function setGreaterOrEqualTo(string $key, int $value): KeyFilter
{
return self::set($key, self::GREATER_EQUAL_TO, $value);
}
public static function setGreaterOrEqualTo( string $key, int $value ): KeyFilter {
return self::set( $key, self::GREATER_EQUAL_TO, $value );
}
public static function setLessThan(string $key, int $value): KeyFilter
{
return self::set($key, self::LESS_THAN, $value);
}
public static function setLessThan( string $key, int $value ): KeyFilter {
return self::set( $key, self::LESS_THAN, $value );
}
public static function setLessOrEqualTo(string $key, int $value): KeyFilter
{
return self::set($key, self::LESS_EQUAL_TO, $value);
}
public static function setLessOrEqualTo( string $key, int $value ): KeyFilter {
return self::set( $key, self::LESS_EQUAL_TO, $value );
}
public static function setEqualToRegex(string $key, string $value): KeyFilter
{
return self::set($key, self::EQUAL_TO_REGEX, $value);
}
public static function setEqualToRegex( string $key, string $value ): KeyFilter {
return self::set( $key, self::EQUAL_TO_REGEX, $value );
}
public static function setNotEqualToRegex(string $key, string $value): KeyFilter
{
return self::set($key, self::NOT_EQUAL_TO_REGEX, $value);
}
public static function setNotEqualToRegex( string $key, string $value ): KeyFilter {
return self::set( $key, self::NOT_EQUAL_TO_REGEX, $value );
}
public function and(string $key, string $operator, $value): KeyFilter
{
$this->checkOperator($operator);
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type($value);
return $this;
}
public function and( string $key, string $operator, $value ): KeyFilter {
$this->checkOperator( $operator );
$this->expressions[] = 'and r.' . $key . ' ' . $operator . ' ' . new Type( $value );
public function andEqualTo(string $key, string $value): KeyFilter
{
$this->and($key, self::EQUAL_TO, $value);
return $this;
}
return $this;
}
public function andNotEqualTo(string $key, string $value): KeyFilter
{
$this->and($key, self::NOT_EQUAL_TO, $value);
return $this;
}
public function andEqualTo( string $key, string $value ): KeyFilter {
$this->and( $key, self::EQUAL_TO, $value );
public function andGreaterThan(string $key, int $value): KeyFilter
{
$this->and($key, self::GREATER_THAN, $value);
return $this;
}
return $this;
}
public function andGreaterOrEqualTo(string $key, int $value): KeyFilter
{
$this->and($key, self::GREATER_EQUAL_TO, $value);
return $this;
}
public function andNotEqualTo( string $key, string $value ): KeyFilter {
$this->and( $key, self::NOT_EQUAL_TO, $value );
public function andLessThan(string $key, int $value): KeyFilter
{
$this->and($key, self::LESS_THAN, $value);
return $this;
}
return $this;
}
public function andLessOrEqualTo(string $key, int $value): KeyFilter
{
$this->and($key, self::LESS_EQUAL_TO, $value);
return $this;
}
public function andGreaterThan( string $key, int $value ): KeyFilter {
$this->and( $key, self::GREATER_THAN, $value );
public function andEqualToRegex(string $key, string $value): KeyFilter
{
$this->and($key, self::EQUAL_TO_REGEX, $value);
return $this;
}
return $this;
}
public function andNotEqualToRegex(string $key, string $value): KeyFilter
{
$this->and($key, self::NOT_EQUAL_TO_REGEX, $value);
return $this;
}
public function andGreaterOrEqualTo( string $key, int $value ): KeyFilter {
$this->and( $key, self::GREATER_EQUAL_TO, $value );
public function or(string $key, string $operator, $value): KeyFilter
{
$this->checkOperator($operator);
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type($value);
return $this;
}
return $this;
}
public function orEqualTo(string $key, string $value): KeyFilter
{
$this->or($key, self::EQUAL_TO, $value);
return $this;
}
public function andLessThan( string $key, int $value ): KeyFilter {
$this->and( $key, self::LESS_THAN, $value );
public function orNotEqualTo(string $key, string $value): KeyFilter
{
$this->or($key, self::NOT_EQUAL_TO, $value);
return $this;
}
return $this;
}
public function orGreaterThan(string $key, int $value): KeyFilter
{
$this->or($key, self::GREATER_THAN, $value);
return $this;
}
public function andLessOrEqualTo( string $key, int $value ): KeyFilter {
$this->and( $key, self::LESS_EQUAL_TO, $value );
public function orGreaterOrEqualTo(string $key, int $value): KeyFilter
{
$this->or($key, self::GREATER_EQUAL_TO, $value);
return $this;
}
return $this;
}
public function orLessThan(string $key, int $value): KeyFilter
{
$this->or($key, self::LESS_THAN, $value);
return $this;
}
public function andEqualToRegex( string $key, string $value ): KeyFilter {
$this->and( $key, self::EQUAL_TO_REGEX, $value );
public function orLessOrEqualTo(string $key, int $value): KeyFilter
{
$this->or($key, self::LESS_EQUAL_TO, $value);
return $this;
}
return $this;
}
public function orEqualToRegex(string $key, string $value): KeyFilter
{
$this->or($key, self::EQUAL_TO_REGEX, $value);
return $this;
}
public function andNotEqualToRegex( string $key, string $value ): KeyFilter {
$this->and( $key, self::NOT_EQUAL_TO_REGEX, $value );
public function orNotEqualToRegex(string $key, string $value): KeyFilter
{
$this->or($key, self::NOT_EQUAL_TO_REGEX, $value);
return $this;
}
return $this;
}
public function __toString()
{
return implode(' ', $this->expressions);
}
public function or( string $key, string $operator, $value ): KeyFilter {
$this->checkOperator( $operator );
$this->expressions[] = 'or r.' . $key . ' ' . $operator . ' ' . new Type( $value );
protected function checkOperator(string $operator)
{
if (!in_array($operator, self::COMPARISON_OPERATORS)) {
throw new Exception('Operator "' . $operator . '" is not supported!');
}
}
return $this;
}
public function orEqualTo( string $key, string $value ): KeyFilter {
$this->or( $key, self::EQUAL_TO, $value );
return $this;
}
public function orNotEqualTo( string $key, string $value ): KeyFilter {
$this->or( $key, self::NOT_EQUAL_TO, $value );
return $this;
}
public function orGreaterThan( string $key, int $value ): KeyFilter {
$this->or( $key, self::GREATER_THAN, $value );
return $this;
}
public function orGreaterOrEqualTo( string $key, int $value ): KeyFilter {
$this->or( $key, self::GREATER_EQUAL_TO, $value );
return $this;
}
public function orLessThan( string $key, int $value ): KeyFilter {
$this->or( $key, self::LESS_THAN, $value );
return $this;
}
public function orLessOrEqualTo( string $key, int $value ): KeyFilter {
$this->or( $key, self::LESS_EQUAL_TO, $value );
return $this;
}
public function orEqualToRegex( string $key, string $value ): KeyFilter {
$this->or( $key, self::EQUAL_TO_REGEX, $value );
return $this;
}
public function orNotEqualToRegex( string $key, string $value ): KeyFilter {
$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,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
namespace Arendsen\FluxQueryBuilder\Expression;
namespace Hosterra\FluxBuilder\Expression;
use Arendsen\FluxQueryBuilder\Type\FieldRecordType;
use Hosterra\FluxBuilder\Type\FieldRecordType;
class Map extends Base
{
private static $string;
class Map extends Base {
private static $string;
public static function with(string $name, string $content): Map
{
$object = new self();
$object::$string = 'r with ' . $name . ': ' . $content;
return $object;
}
public static function with( string $name, string $content ): Map {
$object = new self();
$object::$string = 'r with ' . $name . ': ' . $content;
public static function columns(array $columns)
{
$object = new self();
$object::$string = new FieldRecordType($columns);
return $object;
}
return $object;
}
public function __toString()
{
return self::$string;
}
public static function columns( array $columns ) {
$object = new self();
$object::$string = new FieldRecordType( $columns );
return $object;
}
public function __toString() {
return self::$string;
}
}

View file

@ -1,37 +1,33 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression;
namespace Hosterra\FluxBuilder\Expression;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Selection extends Base
{
private $string;
class Selection extends Base {
private $string;
private function __construct(string $string)
{
$this->string = $string;
}
private function __construct( string $string ) {
$this->string = $string;
}
public static function if(string $value): Selection
{
return new self('if ' . $value);
}
public static function if( string $value ): Selection {
return new self( 'if ' . $value );
}
public function then($then): Selection
{
$this->string .= ' then ' . new Type($then);
return $this;
}
public function then( $then ): Selection {
$this->string .= ' then ' . new Type( $then );
public function else($else): Selection
{
$this->string .= ' else ' . new Type($else);
return $this;
}
return $this;
}
public function __toString()
{
return $this->string;
}
public function else( $else ): Selection {
$this->string .= ' else ' . new Type( $else );
return $this;
}
public function __toString() {
return $this->string;
}
}

View file

@ -1,51 +1,49 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type\ArrayType;
use Arendsen\FluxQueryBuilder\Type\CustomType;
use Arendsen\FluxQueryBuilder\Type\DurationType;
use Arendsen\FluxQueryBuilder\Type\FnType;
use Hosterra\FluxBuilder\Type;
use Hosterra\FluxBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type\CustomType;
use Hosterra\FluxBuilder\Type\DurationType;
use Hosterra\FluxBuilder\Type\FnType;
class AggregateWindow extends Base
{
/**
* @var string $every
*/
private $every;
class AggregateWindow extends Base {
/**
* @var string $every
*/
private $every;
/**
* @var string $fn
*/
private $fn;
/**
* @var string $fn
*/
private $fn;
/**
* @var array $options
*/
private $options;
/**
* @var array $options
*/
private $options;
public function __construct($every, $fn, array $options = [])
{
$this->every = $every;
$this->fn = $fn;
$this->options = $options;
}
public function __construct( $every, $fn, array $options = [] ) {
$this->every = $every;
$this->fn = $fn;
$this->options = $options;
}
public function __toString()
{
$input = new ArrayType(array_filter([
'every' => new DurationType($this->every),
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
'fn' => new CustomType($this->fn),
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
'column' => isset($this->options['column']) ? new Type($this->options['column']) : null,
'timeSrc' => isset($this->options['timeSrc']) ? new Type($this->options['timeSrc']) : null,
'timeDst' => isset($this->options['timeDst']) ? new Type($this->options['timeDst']) : null,
'createEmpty' => isset($this->options['createEmpty']) && !$this->options['createEmpty'] ?
new Type($this->options['createEmpty']) : null,
]));
return '|> aggregateWindow(' . $input . ') ';
}
public function __toString() {
$input = new ArrayType( array_filter( [
'every' => new DurationType( $this->every ),
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
'fn' => new CustomType( $this->fn ),
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
'column' => isset( $this->options['column'] ) ? new Type( $this->options['column'] ) : null,
'timeSrc' => isset( $this->options['timeSrc'] ) ? new Type( $this->options['timeSrc'] ) : null,
'timeDst' => isset( $this->options['timeDst'] ) ? new Type( $this->options['timeDst'] ) : null,
'createEmpty' => isset( $this->options['createEmpty'] ) && ! $this->options['createEmpty'] ?
new Type( $this->options['createEmpty'] ) : null,
] ) );
return '|> aggregateWindow(' . $input . ') ';
}
}

View file

@ -1,16 +1,14 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Exception\FunctionNotImplementedException;
use Hosterra\FluxBuilder\Exception\FunctionNotImplementedException;
abstract class Base
{
/**
* @throws FunctionNotImplementedException
*/
public function __toString()
{
throw new FunctionNotImplementedException('__toString', get_class($this));
}
abstract class Base {
/**
* @throws FunctionNotImplementedException
*/
public function __toString() {
throw new FunctionNotImplementedException( '__toString', get_class( $this ) );
}
}

View file

@ -1,33 +1,31 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type\ArrayType;
class Bottom extends Base
{
/**
* @var int $n
*/
private $n;
class Bottom extends Base {
/**
* @var int $n
*/
private $n;
/**
* @var array $columns
*/
private $columns;
/**
* @var array $columns
*/
private $columns;
public function __construct($n, array $columns = [])
{
$this->n = $n;
$this->columns = $columns;
}
public function __construct( $n, array $columns = [] ) {
$this->n = $n;
$this->columns = $columns;
}
public function __toString()
{
$input = new ArrayType(array_filter([
'n' => $this->n,
'columns' => $this->columns ?: null,
]));
return '|> bottom(' . $input . ') ';
}
public function __toString() {
$input = new ArrayType( array_filter( [
'n' => $this->n,
'columns' => $this->columns ?: null,
] ) );
return '|> bottom(' . $input . ') ';
}
}

View file

@ -1,27 +1,24 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Count extends Base
{
/**
* @var string|null $column
*/
private $column;
class Count extends Base {
/**
* @var string|null $column
*/
private $column;
public function __construct(?string $column = null)
{
$this->column = $column;
}
public function __construct( ?string $column = null ) {
$this->column = $column;
}
public function __toString()
{
$params = new Type(array_filter([
'column' => $this->column
]));
public function __toString() {
$params = new Type( array_filter( [
'column' => $this->column
] ) );
return '|> count(' . $params . ') ';
}
return '|> count(' . $params . ') ';
}
}

View file

@ -1,35 +1,32 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type;
use Hosterra\FluxBuilder\Type\ArrayType;
class Duplicate extends Base
{
/**
* @var string $column
*/
private $column;
class Duplicate extends Base {
/**
* @var string $column
*/
private $column;
/**
* @var string $as
*/
private $as;
/**
* @var string $as
*/
private $as;
public function __construct(string $column, string $as)
{
$this->column = $column;
$this->as = $as;
}
public function __construct( string $column, string $as ) {
$this->column = $column;
$this->as = $as;
}
public function __toString()
{
$input = new ArrayType([
'column' => $this->column,
'as' => $this->as
]);
public function __toString() {
$input = new ArrayType( [
'column' => $this->column,
'as' => $this->as
] );
return '|> duplicate(' . $input . ') ';
}
return '|> duplicate(' . $input . ') ';
}
}

View file

@ -1,51 +1,47 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Exception\FunctionInvalidInputException;
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
use Hosterra\FluxBuilder\Exception\FunctionInvalidInputException;
class Filter extends Base
{
/**
* @var mixed $filter
*/
private $filter;
use Hosterra\FluxBuilder\Expression\KeyFilter;
public function __construct($filter)
{
$this->filter = $filter;
}
class Filter extends Base {
/**
* @var mixed $filter
*/
private $filter;
public function __toString()
{
return '|> filter(fn: (r) => ' . $this->format() . ') ';
}
public function __construct( $filter ) {
$this->filter = $filter;
}
/**
* @throws FunctionInvalidInputException
*/
protected function format(): string
{
if ($this->filter instanceof KeyValue || $this->filter instanceof KeyFilter) {
return $this->filter->__toString();
} elseif (is_array($this->filter)) {
$filterCounter = 0;
$filterString = '';
foreach ($this->filter as $filter) {
if ($filterCounter > 0) {
$filterString .= ' or ';
}
public function __toString() {
return '|> filter(fn: (r) => ' . $this->format() . ') ';
}
$filterString .= 'r._field == "' . $filter . '"';
/**
* @throws FunctionInvalidInputException
*/
protected function format(): string {
if ( $this->filter instanceof KeyValue || $this->filter instanceof KeyFilter ) {
return $this->filter->__toString();
} elseif ( is_array( $this->filter ) ) {
$filterCounter = 0;
$filterString = '';
foreach ( $this->filter as $filter ) {
if ( $filterCounter > 0 ) {
$filterString .= ' or ';
}
$filterCounter++;
}
$filterString .= 'r._field == "' . $filter . '"';
return $filterString;
}
$filterCounter ++;
}
throw new FunctionInvalidInputException('Filter input is incorrect.');
}
return $filterString;
}
throw new FunctionInvalidInputException( 'Filter input is incorrect.' );
}
}

View file

@ -1,27 +1,24 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class First extends Base
{
/**
* @var string|null $column
*/
private $column;
class First extends Base {
/**
* @var string|null $column
*/
private $column;
public function __construct(?string $column = null)
{
$this->column = $column;
}
public function __construct( ?string $column = null ) {
$this->column = $column;
}
public function __toString()
{
$params = new Type(array_filter([
'column' => $this->column
]));
public function __toString() {
$params = new Type( array_filter( [
'column' => $this->column
] ) );
return '|> first(' . $params . ') ';
}
return '|> first(' . $params . ') ';
}
}

View file

@ -1,23 +1,20 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class From extends Base
{
/**
* @var array $settings
*/
private $settings;
class From extends Base {
/**
* @var array $settings
*/
private $settings;
public function __construct(array $settings)
{
$this->settings = $settings;
}
public function __construct( array $settings ) {
$this->settings = $settings;
}
public function __toString()
{
return 'from(' . new Type($this->settings) . ') ';
}
public function __toString() {
return 'from(' . new Type( $this->settings ) . ') ';
}
}

View file

@ -1,34 +1,31 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Group extends Base
{
/**
* @var array $columns
*/
private $columns;
class Group extends Base {
/**
* @var array $columns
*/
private $columns;
/**
* @var string $mode
*/
private $mode;
/**
* @var string $mode
*/
private $mode;
public function __construct(array $columns, string $mode = 'by')
{
$this->columns = $columns;
$this->mode = $mode;
}
public function __construct( array $columns, string $mode = 'by' ) {
$this->columns = $columns;
$this->mode = $mode;
}
public function __toString()
{
$array = new Type([
'columns' => $this->columns,
'mode' => $this->mode,
]);
public function __toString() {
$array = new Type( [
'columns' => $this->columns,
'mode' => $this->mode,
] );
return '|> group(' . $array . ') ';
}
return '|> group(' . $array . ') ';
}
}

View file

@ -1,21 +1,18 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
class Last extends Base
{
/**
* @var int $column
*/
private $column;
class Last extends Base {
/**
* @var int $column
*/
private $column;
public function __construct(string $column = '_value')
{
$this->column = $column;
}
public function __construct( string $column = '_value' ) {
$this->column = $column;
}
public function __toString()
{
return '|> last(column: "' . (string)$this->column . '") ';
}
public function __toString() {
return '|> last(column: "' . (string) $this->column . '") ';
}
}

View file

@ -1,27 +1,24 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
class Limit extends Base
{
/**
* @var int $limit
*/
private $limit;
class Limit extends Base {
/**
* @var int $limit
*/
private $limit;
/**
* @var int $offset
*/
private $offset;
/**
* @var int $offset
*/
private $offset;
public function __construct(int $limit, int $offset = 0)
{
$this->limit = $limit;
$this->offset = $offset;
}
public function __construct( int $limit, int $offset = 0 ) {
$this->limit = $limit;
$this->offset = $offset;
}
public function __toString()
{
return '|> limit(n: ' . (string)$this->limit . ', offset: ' . (string)$this->offset . ') ';
}
public function __toString() {
return '|> limit(n: ' . (string) $this->limit . ', offset: ' . (string) $this->offset . ') ';
}
}

View file

@ -1,23 +1,20 @@
<?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
{
/**
* @var mixed $query
*/
private $query;
class Map extends Base {
/**
* @var mixed $query
*/
private $query;
public function __construct($query)
{
$this->query = $query;
}
public function __construct( $query ) {
$this->query = $query;
}
public function __toString()
{
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
}
public function __toString() {
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
}
}

View file

@ -1,27 +1,24 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Max extends Base
{
/**
* @var string|null $column
*/
private $column;
class Max extends Base {
/**
* @var string|null $column
*/
private $column;
public function __construct(?string $column = null)
{
$this->column = $column;
}
public function __construct( ?string $column = null ) {
$this->column = $column;
}
public function __toString()
{
$params = new Type(array_filter([
'column' => $this->column
]));
public function __toString() {
$params = new Type( array_filter( [
'column' => $this->column
] ) );
return '|> max(' . $params . ') ';
}
return '|> max(' . $params . ') ';
}
}

View file

@ -1,29 +1,26 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type;
use Hosterra\FluxBuilder\Type\ArrayType;
class Mean extends Base
{
/**
* @var string $column
*/
private $column;
class Mean extends Base {
/**
* @var string $column
*/
private $column;
public function __construct(string $column = '_value')
{
$this->column = $column;
}
public function __construct( string $column = '_value' ) {
$this->column = $column;
}
public function __toString()
{
$input = new ArrayType(array_filter([
'column' => !empty($this->column) && $this->column !== '_value' ?
new Type($this->column) : null
]));
public function __toString() {
$input = new ArrayType( array_filter( [
'column' => ! empty( $this->column ) && $this->column !== '_value' ?
new Type( $this->column ) : null
] ) );
return '|> mean(' . $input . ') ';
}
return '|> mean(' . $input . ') ';
}
}

View file

@ -1,21 +1,18 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
class Measurement extends Base
{
/**
* @var string $measurement
*/
private $measurement;
class Measurement extends Base {
/**
* @var string $measurement
*/
private $measurement;
public function __construct(string $measurement)
{
$this->measurement = $measurement;
}
public function __construct( string $measurement ) {
$this->measurement = $measurement;
}
public function __toString()
{
return '|> filter(fn: (r) => r._measurement == "' . (string)$this->measurement . '") ';
}
public function __toString() {
return '|> filter(fn: (r) => r._measurement == "' . (string) $this->measurement . '") ';
}
}

View file

@ -1,27 +1,24 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Min extends Base
{
/**
* @var string|null $column
*/
private $column;
class Min extends Base {
/**
* @var string|null $column
*/
private $column;
public function __construct(?string $column = null)
{
$this->column = $column;
}
public function __construct( ?string $column = null ) {
$this->column = $column;
}
public function __toString()
{
$params = new Type(array_filter([
'column' => $this->column
]));
public function __toString() {
$params = new Type( array_filter( [
'column' => $this->column
] ) );
return '|> min(' . $params . ') ';
}
return '|> min(' . $params . ') ';
}
}

View file

@ -1,40 +1,37 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Exception\FunctionRequiredSettingMissingException;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Exception\FunctionRequiredSettingMissingException;
use Hosterra\FluxBuilder\Type;
use DateTime;
class Range extends Base
{
/**
* @var mixed $start
*/
private $start;
class Range extends Base {
/**
* @var mixed $start
*/
private $start;
/**
* @var mixed $stop
*/
private $stop;
/**
* @var mixed $stop
*/
private $stop;
public function __construct(DateTime $start, ?DateTime $stop = null)
{
$this->start = new Type($start);
$this->stop = $stop ? new Type($stop) : null;
}
public function __construct( DateTime $start, ?DateTime $stop = null ) {
$this->start = new Type( $start );
$this->stop = $stop ? new Type( $stop ) : null;
}
public function __toString()
{
if (!$this->start) {
throw new FunctionRequiredSettingMissingException('Range', 'Start setting is required!');
}
public function __toString() {
if ( ! $this->start ) {
throw new FunctionRequiredSettingMissingException( 'Range', 'Start setting is required!' );
}
$settingsString = 'start: ' . $this->start;
if ($this->stop) {
$settingsString .= ', stop: ' . $this->stop;
}
$settingsString = 'start: ' . $this->start;
if ( $this->stop ) {
$settingsString .= ', stop: ' . $this->stop;
}
return '|> range(' . $settingsString . ') ';
}
return '|> range(' . $settingsString . ') ';
}
}

View file

@ -1,21 +1,18 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
class RawFunction extends Base
{
/**
* @var string $input
*/
private $input;
class RawFunction extends Base {
/**
* @var string $input
*/
private $input;
public function __construct(string $input)
{
$this->input = $input;
}
public function __construct( string $input ) {
$this->input = $input;
}
public function __toString()
{
return $this->input . ' ';
}
public function __toString() {
return $this->input . ' ';
}
}

View file

@ -1,30 +1,27 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type\RecordType;
use Hosterra\FluxBuilder\Type\RecordType;
class Reduce extends Base
{
/**
* @var array $settings
*/
private $settings;
class Reduce extends Base {
/**
* @var array $settings
*/
private $settings;
/**
* @var array $identity
*/
private $identity;
/**
* @var array $identity
*/
private $identity;
public function __construct(array $settings, array $identity)
{
$this->settings = $settings;
$this->identity = $identity;
}
public function __construct( array $settings, array $identity ) {
$this->settings = $settings;
$this->identity = $identity;
}
public function __toString()
{
return '|> reduce(fn: (r, accumulator) => (' . new RecordType($this->settings) . '), ' .
'identity: ' . new RecordType($this->identity) . ') ';
}
public function __toString() {
return '|> reduce(fn: (r, accumulator) => (' . new RecordType( $this->settings ) . '), ' .
'identity: ' . new RecordType( $this->identity ) . ') ';
}
}

View file

@ -1,30 +1,27 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Sort extends Base
{
/**
* @var array $columns
*/
private $columns;
class Sort extends Base {
/**
* @var array $columns
*/
private $columns;
/**
* @var bool $desc
*/
private $desc;
/**
* @var bool $desc
*/
private $desc;
public function __construct(array $columns = ['_value'], bool $desc = false)
{
$this->columns = $columns;
$this->desc = $desc;
}
public function __construct( array $columns = [ '_value' ], bool $desc = false ) {
$this->columns = $columns;
$this->desc = $desc;
}
public function __toString()
{
return '|> sort(columns: [' . new Type($this->columns) .
'], desc: ' . new Type($this->desc) . ') ';
}
public function __toString() {
return '|> sort(columns: [' . new Type( $this->columns ) .
'], desc: ' . new Type( $this->desc ) . ') ';
}
}

View file

@ -1,21 +1,18 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
class Sum extends Base
{
/**
* @var string $column
*/
private $column;
class Sum extends Base {
/**
* @var string $column
*/
private $column;
public function __construct(string $column)
{
$this->column = $column;
}
public function __construct( string $column ) {
$this->column = $column;
}
public function __toString()
{
return '|> sum(column: "' . (string)$this->column . '") ';
}
public function __toString() {
return '|> sum(column: "' . (string) $this->column . '") ';
}
}

View file

@ -1,27 +1,24 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class Unique extends Base
{
/**
* @var string|null $column
*/
private $column;
class Unique extends Base {
/**
* @var string|null $column
*/
private $column;
public function __construct(?string $column = null)
{
$this->column = $column;
}
public function __construct( ?string $column = null ) {
$this->column = $column;
}
public function __toString()
{
$params = new Type(array_filter([
'column' => $this->column
]));
public function __toString() {
$params = new Type( array_filter( [
'column' => $this->column
] ) );
return '|> unique(' . $params . ') ';
}
return '|> unique(' . $params . ') ';
}
}

View file

@ -1,42 +1,40 @@
<?php
namespace Arendsen\FluxQueryBuilder\Functions;
namespace Hosterra\FluxBuilder\Functions;
use Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type\ArrayType;
use Arendsen\FluxQueryBuilder\Type\DurationType;
use Hosterra\FluxBuilder\Type;
use Hosterra\FluxBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type\DurationType;
class Window extends Base
{
/**
* @var string $every
*/
private $every;
class Window extends Base {
/**
* @var string $every
*/
private $every;
/**
* @var array $options
*/
private $options;
/**
* @var array $options
*/
private $options;
public function __construct($every, array $options = [])
{
$this->every = $every;
$this->options = $options;
}
public function __construct( $every, array $options = [] ) {
$this->every = $every;
$this->options = $options;
}
public function __toString()
{
$input = new ArrayType(array_filter([
'every' => new DurationType($this->every),
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
'stopColumn' => isset($this->options['stopColumn']) ? new Type($this->options['stopColumn']) : null,
'createEmpty' => isset($this->options['createEmpty']) && $this->options['createEmpty'] ?
new Type($this->options['createEmpty']) : null,
]));
return '|> window(' . $input . ') ';
}
public function __toString() {
$input = new ArrayType( array_filter( [
'every' => new DurationType( $this->every ),
'period' => isset( $this->options['period'] ) ? new DurationType( $this->options['period'] ) : null,
'offset' => isset( $this->options['offset'] ) ? new DurationType( $this->options['offset'] ) : null,
'location' => isset( $this->options['location'] ) ? new Type( $this->options['location'] ) : null,
'timeColumn' => isset( $this->options['timeColumn'] ) ? new Type( $this->options['timeColumn'] ) : null,
'startColumn' => isset( $this->options['startColumn'] ) ? new Type( $this->options['startColumn'] ) : null,
'stopColumn' => isset( $this->options['stopColumn'] ) ? new Type( $this->options['stopColumn'] ) : null,
'createEmpty' => isset( $this->options['createEmpty'] ) && $this->options['createEmpty'] ?
new Type( $this->options['createEmpty'] ) : null,
] ) );
return '|> window(' . $input . ') ';
}
}

View file

@ -1,64 +1,62 @@
<?php
namespace Arendsen\FluxQueryBuilder;
namespace Hosterra\FluxBuilder;
use Exception;
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
use Arendsen\FluxQueryBuilder\Builder\Basics;
use Arendsen\FluxQueryBuilder\Builder\Universe;
use Hosterra\FluxBuilder\Builder\QueryBuilderInterface;
use Hosterra\FluxBuilder\Builder\Basics;
use Hosterra\FluxBuilder\Builder\Universe;
class QueryBuilder implements QueryBuilderInterface
{
use Basics;
use Universe;
class QueryBuilder implements QueryBuilderInterface {
/**
* @var array $requiredFluxQueryParts
*/
private $requiredFluxQueryParts = [];
const VERSION = '2.0.0';
use Basics;
use Universe;
/**
* @var array $fluxQueryParts
*/
private $fluxQueryParts = [];
/**
* @var array $requiredFluxQueryParts
*/
private $requiredFluxQueryParts = [];
/**
* @var array $requiredData
*/
private $requiredData = [];
/**
* @var array $fluxQueryParts
*/
private $fluxQueryParts = [];
protected function addToQuery($query)
{
$this->fluxQueryParts[] = $query;
/**
* @var array $requiredData
*/
private $requiredData = [];
foreach ($this->requiredFluxQueryParts as $input) {
if ($query instanceof $input) {
$this->requiredData[] = $query;
}
}
}
protected function addToQuery( $query ) {
$this->fluxQueryParts[] = $query;
public function build(): string
{
$this->checkRequired();
foreach ( $this->requiredFluxQueryParts as $input ) {
if ( $query instanceof $input ) {
$this->requiredData[] = $query;
}
}
}
$query = '';
public function build(): string {
$this->checkRequired();
foreach ($this->fluxQueryParts as $part) {
$query .= $part;
}
$query = '';
return $query;
}
foreach ( $this->fluxQueryParts as $part ) {
$query .= $part;
}
protected function checkRequired()
{
foreach ($this->requiredFluxQueryParts as $key => $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!');
} elseif (!isset($this->requiredData[$key])) {
throw new Exception('You need to define the "' . $input . '" part of the query!');
}
}
}
return $query;
}
protected function checkRequired() {
foreach ( $this->requiredFluxQueryParts as $key => $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!' );
} elseif ( ! isset( $this->requiredData[ $key ] ) ) {
throw new Exception( 'You need to define the "' . $input . '" part of the query!' );
}
}
}
}

View file

@ -1,26 +1,22 @@
<?php
namespace Arendsen\FluxQueryBuilder;
namespace Hosterra\FluxBuilder;
class Settings
{
/**
* @var array $settings
*/
protected $settings;
class Settings {
/**
* @var array $settings
*/
protected $settings;
public function __construct(array $settings = [])
{
$this->settings = $settings;
}
public function __construct( array $settings = [] ) {
$this->settings = $settings;
}
public static function set(array $settings = [])
{
return new self($settings);
}
public static function set( array $settings = [] ) {
return new self( $settings );
}
public function get(string $key)
{
return isset($this->settings[$key]) ? $this->settings[$key] : null;
}
public function get( string $key ) {
return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : null;
}
}

View file

@ -1,43 +1,41 @@
<?php
namespace Arendsen\FluxQueryBuilder;
namespace Hosterra\FluxBuilder;
use Arendsen\FluxQueryBuilder\Type\TypeInterface;
use Arendsen\FluxQueryBuilder\Type\ArrayType;
use Arendsen\FluxQueryBuilder\Type\BooleanType;
use Arendsen\FluxQueryBuilder\Type\TimeType;
use Hosterra\FluxBuilder\Type\TypeInterface;
use Hosterra\FluxBuilder\Type\ArrayType;
use Hosterra\FluxBuilder\Type\BooleanType;
use Hosterra\FluxBuilder\Type\TimeType;
use DateTime;
class Type
{
/**
* @var mixed $value
*/
protected $value;
class Type {
/**
* @var mixed $value
*/
protected $value;
public function __construct($value)
{
$this->value = $value;
}
public function __construct( $value ) {
$this->value = $value;
}
public function __toString(): string
{
switch (gettype($this->value)) {
case 'object':
if ($this->value instanceof DateTime) {
return new TimeType($this->value);
}
return $this->value->__toString();
case 'string':
return '"' . $this->value . '"';
case 'boolean':
return new BooleanType($this->value);
case 'array':
return new ArrayType($this->value);
case 'NULL':
return 'null';
default:
return (string)$this->value;
}
}
public function __toString(): string {
switch ( gettype( $this->value ) ) {
case 'object':
if ( $this->value instanceof DateTime ) {
return new TimeType( $this->value );
}
return $this->value->__toString();
case 'string':
return '"' . $this->value . '"';
case 'boolean':
return new BooleanType( $this->value );
case 'array':
return new ArrayType( $this->value );
case 'NULL':
return 'null';
default:
return (string) $this->value;
}
}
}

View file

@ -1,47 +1,41 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
use Arendsen\FluxQueryBuilder\Settings;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Settings;
use Hosterra\FluxBuilder\Type;
class ArrayType implements TypeInterface
{
/**
* @var array $value
*/
protected $value;
class ArrayType implements TypeInterface {
/**
* @var array $value
*/
protected $value;
public function __construct(array $value)
{
$this->value = $value;
}
public function __construct( array $value ) {
$this->value = $value;
}
public function __toString(): string
{
array_walk($this->value, function (&$value, $key) {
if ($this->isAssociativeArray($key)) {
$value = $key . ': ' . $this->getPrefix($value) . new Type($value) . $this->getSuffix($value);
} else {
$value = $this->getPrefix($value) . new Type($value) . $this->getSuffix($value);
}
});
public function __toString(): string {
array_walk( $this->value, function ( &$value, $key ) {
if ( $this->isAssociativeArray( $key ) ) {
$value = $key . ': ' . $this->getPrefix( $value ) . new Type( $value ) . $this->getSuffix( $value );
} else {
$value = $this->getPrefix( $value ) . new Type( $value ) . $this->getSuffix( $value );
}
} );
return implode(', ', $this->value);
}
return implode( ', ', $this->value );
}
protected function isAssociativeArray($key): bool
{
return is_string($key);
}
protected function isAssociativeArray( $key ): bool {
return is_string( $key );
}
protected function getPrefix($value): string
{
return is_array($value) ? '[' : '';
}
protected function getPrefix( $value ): string {
return is_array( $value ) ? '[' : '';
}
protected function getSuffix($value): string
{
return is_array($value) ? ']' : '';
}
protected function getSuffix( $value ): string {
return is_array( $value ) ? ']' : '';
}
}

View file

@ -1,16 +1,13 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
class BooleanType implements TypeInterface
{
public function __construct($value)
{
$this->value = $value;
}
class BooleanType implements TypeInterface {
public function __construct( $value ) {
$this->value = $value;
}
public function __toString(): string
{
return $this->value ? 'true' : 'false';
}
public function __toString(): string {
return $this->value ? 'true' : 'false';
}
}

View file

@ -1,16 +1,13 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
class CustomType implements TypeInterface
{
public function __construct(string $value)
{
$this->value = $value;
}
class CustomType implements TypeInterface {
public function __construct( string $value ) {
$this->value = $value;
}
public function __toString(): string
{
return $this->value;
}
public function __toString(): string {
return $this->value;
}
}

View file

@ -1,16 +1,13 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
class DurationType implements TypeInterface
{
public function __construct(string $value)
{
$this->value = $value;
}
class DurationType implements TypeInterface {
public function __construct( string $value ) {
$this->value = $value;
}
public function __toString(): string
{
return $this->value;
}
public function __toString(): string {
return $this->value;
}
}

View file

@ -1,32 +1,29 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
use Arendsen\FluxQueryBuilder\Settings;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Settings;
use Hosterra\FluxBuilder\Type;
class FieldRecordType implements TypeInterface
{
public const SETTING_IS_RECORD = 'isRecord';
class FieldRecordType implements TypeInterface {
public const SETTING_IS_RECORD = 'isRecord';
/**
* @var array $value
*/
private $value;
/**
* @var array $value
*/
private $value;
public function __construct(array $value)
{
$this->value = $value;
}
public function __construct( array $value ) {
$this->value = $value;
}
public function __toString(): string
{
array_walk($this->value, function (&$value, $key) {
if (is_string($key)) {
$value = $key . ': ' . $value;
}
});
public function __toString(): string {
array_walk( $this->value, function ( &$value, $key ) {
if ( is_string( $key ) ) {
$value = $key . ': ' . $value;
}
} );
return '{' . implode(', ', $this->value) . '}';
}
return '{' . implode( ', ', $this->value ) . '}';
}
}

View file

@ -1,51 +1,47 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class FnType implements TypeInterface
{
/**
* @var array $params
*/
protected $params;
class FnType implements TypeInterface {
/**
* @var array $params
*/
protected $params;
/**
* @var string $content
*/
protected $content;
/**
* @var string $content
*/
protected $content;
private function __construct(array $params)
{
$this->params = $params;
}
private function __construct( array $params ) {
$this->params = $params;
}
public static function params(array $params)
{
return new self($params);
}
public static function params( array $params ) {
return new self( $params );
}
public function withBody(string $content)
{
$this->content = $content;
return $this;
}
public function withBody( string $content ) {
$this->content = $content;
public function withBlock(string $content)
{
$this->content = '{ ' . $content . ' }';
return $this;
}
return $this;
}
public function __toString(): string
{
array_walk($this->params, function (&$value, $key) {
if (is_string($key)) {
$value = $key . ' = ' . new Type($value);
}
});
public function withBlock( string $content ) {
$this->content = '{ ' . $content . ' }';
return '(' . implode(', ', $this->params) . ') => ' . $this->content;
}
return $this;
}
public function __toString(): string {
array_walk( $this->params, function ( &$value, $key ) {
if ( is_string( $key ) ) {
$value = $key . ' = ' . new Type( $value );
}
} );
return '(' . implode( ', ', $this->params ) . ') => ' . $this->content;
}
}

View file

@ -1,16 +1,13 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
class MathType implements TypeInterface
{
public function __construct(string $value)
{
$this->value = $value;
}
class MathType implements TypeInterface {
public function __construct( string $value ) {
$this->value = $value;
}
public function __toString(): string
{
return $this->value;
}
public function __toString(): string {
return $this->value;
}
}

View file

@ -1,36 +1,32 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
use Arendsen\FluxQueryBuilder\Type;
use Hosterra\FluxBuilder\Type;
class RecordType implements TypeInterface
{
/**
* @var array $value
*/
private $value;
class RecordType implements TypeInterface {
/**
* @var array $value
*/
private $value;
public function __construct(array $value)
{
$this->value = $value;
}
public function __construct( array $value ) {
$this->value = $value;
}
public function __toString(): string
{
array_walk($this->value, function (&$value, $key) {
if (is_array($value)) {
$value = $this->getPrefix($key) . new RecordType($value);
} else {
$value = $this->getPrefix($key) . new Type($value);
}
});
public function __toString(): string {
array_walk( $this->value, function ( &$value, $key ) {
if ( is_array( $value ) ) {
$value = $this->getPrefix( $key ) . new RecordType( $value );
} else {
$value = $this->getPrefix( $key ) . new Type( $value );
}
} );
return '{' . implode(', ', $this->value) . '}';
}
return '{' . implode( ', ', $this->value ) . '}';
}
private function getPrefix($key): string
{
return is_string($key) ? $key . ': ' : '';
}
private function getPrefix( $key ): string {
return is_string( $key ) ? $key . ': ' : '';
}
}

View file

@ -1,18 +1,15 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
use DateTime;
class TimeType implements TypeInterface
{
public function __construct(DateTime $dateTime)
{
$this->dateTime = $dateTime;
}
class TimeType implements TypeInterface {
public function __construct( DateTime $dateTime ) {
$this->dateTime = $dateTime;
}
public function __toString(): string
{
return 'time(v: ' . $this->dateTime->format('Y-m-d\TH:i:s\Z') . ')';
}
public function __toString(): string {
return 'time(v: ' . $this->dateTime->format( 'Y-m-d\TH:i:s\Z' ) . ')';
}
}

View file

@ -1,8 +1,7 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
namespace Hosterra\FluxBuilder\Type;
interface TypeInterface
{
public function __toString(): string;
interface TypeInterface {
public function __toString(): string;
}

View file

@ -1,36 +1,33 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Expression;
use Exception;
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
use Hosterra\FluxBuilder\Expression\KeyFilter;
use PHPUnit\Framework\TestCase;
final class KeyFilterExpressionTest extends TestCase
{
public function testSimpleKeyvalue()
{
$keyFilter = KeyFilter::setEqualTo('_measurement', 'test_measurement')
->andEqualTo('_field', 'user')
->or('count', '>=', '1')
->and('user', KeyFilter::EQUAL_TO, 'my_username')
->orNotEqualTo('test', 'world');
final class KeyFilterExpressionTest extends TestCase {
public function testSimpleKeyvalue() {
$keyFilter = KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
->andEqualTo( '_field', 'user' )
->or( 'count', '>=', '1' )
->and( 'user', KeyFilter::EQUAL_TO, 'my_username' )
->orNotEqualTo( 'test', 'world' );
$query = 'r._measurement == "test_measurement" and r._field == "user" or ' .
'r.count >= "1" and r.user == "my_username" or r.test != "world"';
$query = 'r._measurement == "test_measurement" and r._field == "user" or ' .
'r.count >= "1" and r.user == "my_username" or r.test != "world"';
$this->assertEquals($keyFilter->__toString(), $query);
}
$this->assertEquals( $keyFilter->__toString(), $query );
}
public function testInvalidOperator()
{
$this->expectException(Exception::class);
public function testInvalidOperator() {
$this->expectException( Exception::class );
KeyFilter::set('_measurement', '9dkda9e', 'test_measurement')
->andEqualTo('_field', 'user')
->or('_field', '==', 'field2')
->andEqualTo('user', 'my_username');
}
KeyFilter::set( '_measurement', '9dkda9e', 'test_measurement' )
->andEqualTo( '_field', 'user' )
->or( '_field', '==', 'field2' )
->andEqualTo( 'user', 'my_username' );
}
}

View file

@ -1,43 +1,40 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
use Arendsen\FluxQueryBuilder\Type\FnType;
use Hosterra\FluxBuilder\Functions\AggregateWindow;
use Hosterra\FluxBuilder\Type\FnType;
use PHPUnit\Framework\TestCase;
final class AggregateWindowFunctionTest extends TestCase
{
public function testSimpleWindow()
{
$expression = new AggregateWindow('20s', 'mean');
final class AggregateWindowFunctionTest extends TestCase {
public function testSimpleWindow() {
$expression = new AggregateWindow( '20s', 'mean' );
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testAllParameters()
{
$expression = new AggregateWindow(
'20s',
FnType::params(['r'])->withBody('r._field == "test"'),
[
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'column' => '_value',
'timeSrc' => '_stop',
'timeDst' => '_time',
'createEmpty' => false
]
);
public function testAllParameters() {
$expression = new AggregateWindow(
'20s',
FnType::params( [ 'r' ] )->withBody( 'r._field == "test"' ),
[
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'column' => '_value',
'timeSrc' => '_stop',
'timeDst' => '_time',
'createEmpty' => false
]
);
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test", ' .
'location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test", ' .
'location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Count;
use Hosterra\FluxBuilder\Functions\Count;
use PHPUnit\Framework\TestCase;
final class CountFunctionTest extends TestCase
{
public function testSimpleCount()
{
$expression = new Count();
final class CountFunctionTest extends TestCase {
public function testSimpleCount() {
$expression = new Count();
$query = '|> count() ';
$query = '|> count() ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testCountWithColumn()
{
$expression = new Count('_value');
public function testCountWithColumn() {
$expression = new Count( '_value' );
$query = '|> count(column: "_value") ';
$query = '|> count(column: "_value") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,20 +1,18 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
use Hosterra\FluxBuilder\Functions\Duplicate;
use PHPUnit\Framework\TestCase;
final class DuplicateFunctionTest extends TestCase
{
public function testSimpleDuplicate()
{
$expression = new Duplicate('tag', 'tag_dup');
final class DuplicateFunctionTest extends TestCase {
public function testSimpleDuplicate() {
$expression = new Duplicate( 'tag', 'tag_dup' );
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,48 +1,33 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
use Arendsen\FluxQueryBuilder\Functions\Filter;
use Hosterra\FluxBuilder\Expression\KeyFilter;
use Hosterra\FluxBuilder\Functions\Filter;
use PHPUnit\Framework\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'));
final class FilterFunctionTest extends TestCase {
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
'r._field == "field2" and r.user == "my_username") ';
public function testFieldFilter() {
$expression = new Filter( [ 'user', 'field2', 'field3' ] );
$this->assertEquals($expression->__toString(), $query);
}
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
public function testFieldFilter()
{
$expression = new Filter(['user', 'field2', 'field3']);
$this->assertEquals( $expression->__toString(), $query );
}
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
public function testKeyFilter() {
$expression = new Filter( KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
->andEqualTo( '_field', 'user' )
->orEqualTo( '_field', 'field2' )
->andEqualTo( 'user', 'my_username' ) );
$this->assertEquals($expression->__toString(), $query);
}
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
'r._field == "field2" and r.user == "my_username") ';
public function testKeyFilter()
{
$expression = new Filter(KeyFilter::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 ' .
'r._field == "field2" and r.user == "my_username") ';
$this->assertEquals($expression->__toString(), $query);
}
$this->assertEquals( $expression->__toString(), $query );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\First;
use Hosterra\FluxBuilder\Functions\First;
use PHPUnit\Framework\TestCase;
final class FirstFunctionTest extends TestCase
{
public function testSimpleFirst()
{
$expression = new First();
final class FirstFunctionTest extends TestCase {
public function testSimpleFirst() {
$expression = new First();
$query = '|> first() ';
$query = '|> first() ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testFirstWithColumn()
{
$expression = new First('something');
public function testFirstWithColumn() {
$expression = new First( 'something' );
$query = '|> first(column: "something") ';
$query = '|> first(column: "something") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,40 +1,37 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\From;
use Hosterra\FluxBuilder\Functions\From;
use PHPUnit\Framework\TestCase;
final class FromFunctionTest extends TestCase
{
/**
* @dataProvider somethingProvider
*/
public function testSomething($settings, $query)
{
$expression = new From($settings);
final class FromFunctionTest extends TestCase {
/**
* @dataProvider somethingProvider
*/
public function testSomething( $settings, $query ) {
$expression = new From( $settings );
$this->assertEquals($expression->__toString(), $query);
}
$this->assertEquals( $expression->__toString(), $query );
}
public function somethingProvider(): array
{
return [
'from bucket' => [
[
'bucket' => 'test-bucket',
],
'from(bucket: "test-bucket") '
],
'from bucket and host' => [
[
'bucket' => 'test-bucket',
'host' => 'test',
],
'from(bucket: "test-bucket", host: "test") '
],
];
}
public function somethingProvider(): array {
return [
'from bucket' => [
[
'bucket' => 'test-bucket',
],
'from(bucket: "test-bucket") '
],
'from bucket and host' => [
[
'bucket' => 'test-bucket',
'host' => 'test',
],
'from(bucket: "test-bucket", host: "test") '
],
];
}
}

View file

@ -1,20 +1,18 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Group;
use Hosterra\FluxBuilder\Functions\Group;
use PHPUnit\Framework\TestCase;
final class GroupFunctionTest extends TestCase
{
public function testSimpleGroup()
{
$expression = new Group(['foo', 'bar'], 'by');
final class GroupFunctionTest extends TestCase {
public function testSimpleGroup() {
$expression = new Group( [ 'foo', 'bar' ], 'by' );
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Last;
use Hosterra\FluxBuilder\Functions\Last;
use PHPUnit\Framework\TestCase;
final class LastFunctionTest extends TestCase
{
public function testSimpleLast()
{
$expression = new Last();
final class LastFunctionTest extends TestCase {
public function testSimpleLast() {
$expression = new Last();
$query = '|> last(column: "_value") ';
$query = '|> last(column: "_value") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testLastWithValue()
{
$expression = new Last('something');
public function testLastWithValue() {
$expression = new Last( 'something' );
$query = '|> last(column: "something") ';
$query = '|> last(column: "something") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Limit;
use Hosterra\FluxBuilder\Functions\Limit;
use PHPUnit\Framework\TestCase;
final class LimitFunctionTest extends TestCase
{
public function testSimpleLimit()
{
$expression = new Limit(1);
final class LimitFunctionTest extends TestCase {
public function testSimpleLimit() {
$expression = new Limit( 1 );
$query = '|> limit(n: 1, offset: 0) ';
$query = '|> limit(n: 1, offset: 0) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testLimitWithOffset()
{
$expression = new Limit(10, 2);
public function testLimitWithOffset() {
$expression = new Limit( 10, 2 );
$query = '|> limit(n: 10, offset: 2) ';
$query = '|> limit(n: 10, offset: 2) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,47 +1,43 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Map;
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
use Arendsen\FluxQueryBuilder\Expression\Selection as SelectionExpression;
use Hosterra\FluxBuilder\Functions\Map;
use Hosterra\FluxBuilder\Expression\Map as MapExpression;
use Hosterra\FluxBuilder\Expression\Selection as SelectionExpression;
use PHPUnit\Framework\TestCase;
final class MapFunctionTest extends TestCase
{
public function testSimpleMap()
{
$expression = new Map('r with name: r.user');
final class MapFunctionTest extends TestCase {
public function testSimpleMap() {
$expression = new Map( 'r with name: r.user' );
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testWithMapObject()
{
$expression = new Map(MapExpression::with('name', 'r.user'));
public function testWithMapObject() {
$expression = new Map( MapExpression::with( 'name', 'r.user' ) );
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testRecordMapObject()
{
$expression = new Map(MapExpression::columns([
'time' => 'r._time',
'source' => 'r.tag',
'alert' => SelectionExpression::if('r._value > 10')->then(true)->else(false)->__toString(),
'test' => SelectionExpression::if('r._value > 10')->then('yes')->else('no')->__toString()
])->__toString());
public function testRecordMapObject() {
$expression = new Map( MapExpression::columns( [
'time' => 'r._time',
'source' => 'r.tag',
'alert' => SelectionExpression::if( 'r._value > 10' )->then( true )->else( false )->__toString(),
'test' => SelectionExpression::if( 'r._value > 10' )->then( 'yes' )->else( 'no' )->__toString()
] )->__toString() );
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
'alert: if r._value > 10 then true else false, ' .
'test: if r._value > 10 then "yes" else "no"} })) ';
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
'alert: if r._value > 10 then true else false, ' .
'test: if r._value > 10 then "yes" else "no"} })) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Max;
use Hosterra\FluxBuilder\Functions\Max;
use PHPUnit\Framework\TestCase;
final class MaxFunctionTest extends TestCase
{
public function testSimpleMax()
{
$expression = new Max();
final class MaxFunctionTest extends TestCase {
public function testSimpleMax() {
$expression = new Max();
$query = '|> max() ';
$query = '|> max() ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testMaxWithColumn()
{
$expression = new Max('something');
public function testMaxWithColumn() {
$expression = new Max( 'something' );
$query = '|> max(column: "something") ';
$query = '|> max(column: "something") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Mean;
use Hosterra\FluxBuilder\Functions\Mean;
use PHPUnit\Framework\TestCase;
final class MeanFunctionTest extends TestCase
{
public function testSimpleMean()
{
$expression = new Mean();
final class MeanFunctionTest extends TestCase {
public function testSimpleMean() {
$expression = new Mean();
$query = '|> mean() ';
$query = '|> mean() ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testWithParameterColumn()
{
$expression = new Mean('test');
public function testWithParameterColumn() {
$expression = new Mean( 'test' );
$query = '|> mean(column: "test") ';
$query = '|> mean(column: "test") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Min;
use Hosterra\FluxBuilder\Functions\Min;
use PHPUnit\Framework\TestCase;
final class MinFunctionTest extends TestCase
{
public function testSimpleMin()
{
$expression = new Min();
final class MinFunctionTest extends TestCase {
public function testSimpleMin() {
$expression = new Min();
$query = '|> min() ';
$query = '|> min() ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testMinWithColumn()
{
$expression = new Min('something');
public function testMinWithColumn() {
$expression = new Min( 'something' );
$query = '|> min(column: "something") ';
$query = '|> min(column: "something") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,47 +1,43 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use DateTime;
use Arendsen\FluxQueryBuilder\Functions\Range;
use Hosterra\FluxBuilder\Functions\Range;
use PHPUnit\Framework\TestCase;
final class RangeFunctionTest extends TestCase
{
public function testOnlyStartOption()
{
$expression = new Range(
new DateTime('2022-08-12 18:00:00')
);
final class RangeFunctionTest extends TestCase {
public function testOnlyStartOption() {
$expression = new Range(
new DateTime( '2022-08-12 18:00:00' )
);
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testWithStopOption()
{
$expression = new Range(
new DateTime('2022-08-12 18:00:00'),
new DateTime('2022-08-12 20:00:00')
);
public function testWithStopOption() {
$expression = new Range(
new DateTime( '2022-08-12 18:00:00' ),
new DateTime( '2022-08-12 20:00:00' )
);
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testRangeInBetween()
{
$expression = new Range(
new DateTime('2022-08-12 17:31:00'),
new DateTime('2022-08-12 18:31:00')
);
public function testRangeInBetween() {
$expression = new Range(
new DateTime( '2022-08-12 17:31:00' ),
new DateTime( '2022-08-12 18:31:00' )
);
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
$this->assertEquals($expected, $expression->__toString());
}
$this->assertEquals( $expected, $expression->__toString() );
}
}

View file

@ -1,21 +1,19 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Reduce;
use Arendsen\FluxQueryBuilder\Type\MathType;
use Hosterra\FluxBuilder\Functions\Reduce;
use Hosterra\FluxBuilder\Type\MathType;
use PHPUnit\Framework\TestCase;
final class ReduceFunctionTest extends TestCase
{
public function testSimpleReduce()
{
$expression = new Reduce(['sum' => new MathType('r._value + accumulator.sum')], ['sum' => 0]);
final class ReduceFunctionTest extends TestCase {
public function testSimpleReduce() {
$expression = new Reduce( [ 'sum' => new MathType( 'r._value + accumulator.sum' ) ], [ 'sum' => 0 ] );
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,20 +1,18 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Sort;
use Hosterra\FluxBuilder\Functions\Sort;
use PHPUnit\Framework\TestCase;
final class SortFunctionTest extends TestCase
{
public function testSimpleSort()
{
$expression = new Sort(['foo', 'bar'], true);
final class SortFunctionTest extends TestCase {
public function testSimpleSort() {
$expression = new Sort( [ 'foo', 'bar' ], true );
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,20 +1,18 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Sum;
use Hosterra\FluxBuilder\Functions\Sum;
use PHPUnit\Framework\TestCase;
final class SumFunctionTest extends TestCase
{
public function testSimpleSum()
{
$expression = new Sum('_value');
final class SumFunctionTest extends TestCase {
public function testSimpleSum() {
$expression = new Sum( '_value' );
$query = '|> sum(column: "_value") ';
$query = '|> sum(column: "_value") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,29 +1,26 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Unique;
use Hosterra\FluxBuilder\Functions\Unique;
use PHPUnit\Framework\TestCase;
final class UniqueunctionTest extends TestCase
{
public function testSimpleUnique()
{
$expression = new Unique();
final class UniqueunctionTest extends TestCase {
public function testSimpleUnique() {
$expression = new Unique();
$query = '|> unique() ';
$query = '|> unique() ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testUniqueWithColumn()
{
$expression = new Unique('something');
public function testUniqueWithColumn() {
$expression = new Unique( 'something' );
$query = '|> unique(column: "something") ';
$query = '|> unique(column: "something") ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,38 +1,35 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Functions;
use Arendsen\FluxQueryBuilder\Functions\Window;
use Hosterra\FluxBuilder\Functions\Window;
use PHPUnit\Framework\TestCase;
final class WindowFunctionTest extends TestCase
{
public function testSimpleWindow()
{
$expression = new Window('20s');
final class WindowFunctionTest extends TestCase {
public function testSimpleWindow() {
$expression = new Window( '20s' );
$query = '|> window(every: 20s) ';
$query = '|> window(every: 20s) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
public function testAllParameters()
{
$expression = new Window('20s', [
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'timeColumn' => '_time',
'startColumn' => '_start',
'stopColumn' => '_stop',
'createEmpty' => true
]);
public function testAllParameters() {
$expression = new Window( '20s', [
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'timeColumn' => '_time',
'startColumn' => '_start',
'stopColumn' => '_stop',
'createEmpty' => true
] );
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
$this->assertEquals($query, $expression->__toString());
}
$this->assertEquals( $query, $expression->__toString() );
}
}

View file

@ -1,256 +1,253 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests;
use Closure;
use DateTime;
use Exception;
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
use Hosterra\FluxBuilder\Expression\KeyFilter;
use PHPUnit\Framework\TestCase;
use Arendsen\FluxQueryBuilder\QueryBuilder;
use Arendsen\FluxQueryBuilder\Type\MathType;
use Hosterra\FluxBuilder\QueryBuilder;
use Hosterra\FluxBuilder\Type\MathType;
final class QueryBuilderTest extends TestCase
{
/**
* @dataProvider newTestsProvider
*/
public function testBasicQuery(string $methodName, array $params = [], string $expected = '')
{
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket('test_bucket')
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
->fromMeasurement('test_measurement');
final class QueryBuilderTest extends TestCase {
/**
* @dataProvider newTestsProvider
*/
public function testBasicQuery( string $methodName, array $params = [], string $expected = '' ) {
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket( 'test_bucket' )
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) )
->fromMeasurement( 'test_measurement' );
call_user_func_array([$queryBuilder, $methodName], $params);
call_user_func_array( [ $queryBuilder, $methodName ], $params );
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
'|> filter(fn: (r) => r._measurement == "test_measurement") ' . $expected;
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
'|> filter(fn: (r) => r._measurement == "test_measurement") ' . $expected;
$this->assertEquals($expectedQuery, $queryBuilder->build());
}
$this->assertEquals( $expectedQuery, $queryBuilder->build() );
}
public function newTestsProvider(): array
{
return [
'addAggregateWindow' => [
'addAggregateWindow',
['20s', 'mean', ['timeDst' => '_time']],
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
],
'addBottom' => [
'addBottom',
[2, ['_value']],
'|> bottom(n: 2, columns: ["_value"]) '
],
'addCount' => [
'addCount',
['_value'],
'|> count(column: "_value") '
],
'addDuplicate' => [
'addDuplicate',
['old_name', 'new_name'],
'|> duplicate(column: "old_name", as: "new_name") '
],
'addFilter' => [
'addFilter',
[KeyValue::setGreaterOrEqualTo('count', 2)->andGreaterOrEqualTo('count2', 3)],
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) '
],
'addKeyFilter' => [
'addKeyFilter',
[KeyFilter::setEqualTo('user', 'username')],
'|> filter(fn: (r) => r.user == "username") '
],
'addFieldFilter' => [
'addFieldFilter',
[['email', 'username']],
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
],
'addFirst' => [
'addFirst',
['something'],
'|> first(column: "something") '
],
'addGroup' => [
'addGroup',
[['_field', 'ip']],
'|> group(columns: ["_field", "ip"], mode: "by") '
],
'addLast' => [
'addLast',
['something'],
'|> last(column: "something") '
],
'addLimit' => [
'addLimit',
[20, 40],
'|> limit(n: 20, offset: 40) '
],
'addMap' => [
'addMap',
['r with name: r.user'],
'|> map(fn: (r) => ({ r with name: r.user })) '
],
'addMax' => [
'addMax',
[],
'|> max() '
],
'addMean' => [
'addMean',
['something'],
'|> mean(column: "something") '
],
'addMin' => [
'addMin',
['something'],
'|> min(column: "something") '
],
'addRawFunction' => [
'addRawFunction',
['|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time")'],
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
],
'addReduce' => [
'addReduce',
[['count' => new MathType('accumulator.count + 1')], ['count' => 0]],
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) '
],
'addSort' => [
'addSort',
[['column1', 'column2'], true],
'|> sort(columns: ["column1", "column2"], desc: true) '
],
'addSum' => [
'addSum',
['something'],
'|> sum(column: "something") '
],
'addUnique' => [
'addUnique',
['something'],
'|> unique(column: "something") '
],
'addUnwindow' => [
'addUnwindow',
[],
'|> window(every: inf) '
],
'addWindow' => [
'addWindow',
['20s', ['timeColumn' => '_time']],
'|> window(every: 20s, timeColumn: "_time") '
],
];
}
public function newTestsProvider(): array {
return [
'addAggregateWindow' => [
'addAggregateWindow',
[ '20s', 'mean', [ 'timeDst' => '_time' ] ],
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
],
'addBottom' => [
'addBottom',
[ 2, [ '_value' ] ],
'|> bottom(n: 2, columns: ["_value"]) '
],
'addCount' => [
'addCount',
[ '_value' ],
'|> count(column: "_value") '
],
'addDuplicate' => [
'addDuplicate',
[ 'old_name', 'new_name' ],
'|> duplicate(column: "old_name", as: "new_name") '
],
'addFilter' => [
'addFilter',
[ KeyValue::setGreaterOrEqualTo( 'count', 2 )->andGreaterOrEqualTo( 'count2', 3 ) ],
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) '
],
'addKeyFilter' => [
'addKeyFilter',
[ KeyFilter::setEqualTo( 'user', 'username' ) ],
'|> filter(fn: (r) => r.user == "username") '
],
'addFieldFilter' => [
'addFieldFilter',
[ [ 'email', 'username' ] ],
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
],
'addFirst' => [
'addFirst',
[ 'something' ],
'|> first(column: "something") '
],
'addGroup' => [
'addGroup',
[ [ '_field', 'ip' ] ],
'|> group(columns: ["_field", "ip"], mode: "by") '
],
'addLast' => [
'addLast',
[ 'something' ],
'|> last(column: "something") '
],
'addLimit' => [
'addLimit',
[ 20, 40 ],
'|> limit(n: 20, offset: 40) '
],
'addMap' => [
'addMap',
[ 'r with name: r.user' ],
'|> map(fn: (r) => ({ r with name: r.user })) '
],
'addMax' => [
'addMax',
[],
'|> max() '
],
'addMean' => [
'addMean',
[ 'something' ],
'|> mean(column: "something") '
],
'addMin' => [
'addMin',
[ 'something' ],
'|> min(column: "something") '
],
'addRawFunction' => [
'addRawFunction',
[ '|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time")' ],
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
],
'addReduce' => [
'addReduce',
[ [ 'count' => new MathType( 'accumulator.count + 1' ) ], [ 'count' => 0 ] ],
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) '
],
'addSort' => [
'addSort',
[ [ 'column1', 'column2' ], true ],
'|> sort(columns: ["column1", "column2"], desc: true) '
],
'addSum' => [
'addSum',
[ 'something' ],
'|> sum(column: "something") '
],
'addUnique' => [
'addUnique',
[ 'something' ],
'|> unique(column: "something") '
],
'addUnwindow' => [
'addUnwindow',
[],
'|> window(every: inf) '
],
'addWindow' => [
'addWindow',
[ '20s', [ 'timeColumn' => '_time' ] ],
'|> window(every: 20s, timeColumn: "_time") '
],
];
}
/**
* @dataProvider throwsExceptionWithoutRequiredDataProvider
*/
public function testThrowsExceptionWithoutRequiredData($from, $measurement, $range)
{
$this->expectException(Exception::class);
/**
* @dataProvider throwsExceptionWithoutRequiredDataProvider
*/
public function testThrowsExceptionWithoutRequiredData( $from, $measurement, $range ) {
$this->expectException( Exception::class );
$queryBuilder = new QueryBuilder();
$queryBuilder = new QueryBuilder();
if ($from) {
$queryBuilder->from($from);
}
if ($range) {
$queryBuilder->addRangeStart($range['start']);
}
if ($measurement) {
$queryBuilder->fromMeasurement($measurement);
}
if ( $from ) {
$queryBuilder->from( $from );
}
if ( $range ) {
$queryBuilder->addRangeStart( $range['start'] );
}
if ( $measurement ) {
$queryBuilder->fromMeasurement( $measurement );
}
$queryBuilder->build();
}
$queryBuilder->build();
}
public function throwsExceptionWithoutRequiredDataProvider(): array
{
return [
'without from data' => [
null, 'test_measurement', ['start' => new DateTime('2022-08-12 20:05:00')],
],
'without measurement data' => [
['from' => 'test_bucket'], null, ['start' => new DateTime('2022-08-12 20:05:00')],
],
'without range data' => [
['from' => 'test_bucket'], 'test_measurement', null,
],
];
}
public function throwsExceptionWithoutRequiredDataProvider(): array {
return [
'without from data' => [
null,
'test_measurement',
[ 'start' => new DateTime( '2022-08-12 20:05:00' ) ],
],
'without measurement data' => [
[ 'from' => 'test_bucket' ],
null,
[ 'start' => new DateTime( '2022-08-12 20:05:00' ) ],
],
'without range data' => [
[ 'from' => 'test_bucket' ],
'test_measurement',
null,
],
];
}
public function testThrowsExceptionWhenIncorrectOrder()
{
$this->expectException(Exception::class);
public function testThrowsExceptionWhenIncorrectOrder() {
$this->expectException( Exception::class );
$queryBuilder = new QueryBuilder();
$queryBuilder->from(['bucket' => 'test_bucket'])
->fromMeasurement('test_measurement')
->addRangeStart(new DateTime('2022-08-12 20:05:00'));
$queryBuilder = new QueryBuilder();
$queryBuilder->from( [ 'bucket' => 'test_bucket' ] )
->fromMeasurement( 'test_measurement' )
->addRangeStart( new DateTime( '2022-08-12 20:05:00' ) );
$queryBuilder->build();
}
$queryBuilder->build();
}
public function testQueryWithWindow()
{
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket('test_bucket')
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
->addWindow('20s')
->addMean()
->addDuplicate('tag', 'tag_dup')
->fromMeasurement('test_measurement')
->addFilter(KeyValue::setGreaterOrEqualTo('count', 2)->andGreaterOrEqualTo('count2', 3))
->addKeyFilter(KeyFilter::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2))
->addUnWindow();
public function testQueryWithWindow() {
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket( 'test_bucket' )
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) )
->addReduce( [ 'count' => new MathType( 'accumulator.count + 1' ) ], [ 'count' => 0 ] )
->addWindow( '20s' )
->addMean()
->addDuplicate( 'tag', 'tag_dup' )
->fromMeasurement( 'test_measurement' )
->addFilter( KeyValue::setGreaterOrEqualTo( 'count', 2 )->andGreaterOrEqualTo( 'count2', 3 ) )
->addKeyFilter( KeyFilter::setGreaterOrEqualTo( 'count', 1 )->andGreaterOrEqualTo( 'count2', 2 ) )
->addUnWindow();
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) ' .
'|> window(every: 20s) |> mean() |> duplicate(column: "tag", as: "tag_dup") ' .
'|> filter(fn: (r) => r._measurement == "test_measurement") ' .
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) ' .
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) ' .
'|> window(every: 20s) |> mean() |> duplicate(column: "tag", as: "tag_dup") ' .
'|> filter(fn: (r) => r._measurement == "test_measurement") ' .
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) ' .
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
$this->assertEquals($expectedQuery, $queryBuilder->build());
}
$this->assertEquals( $expectedQuery, $queryBuilder->build() );
}
public function testCorrectInstancesAreCreated()
{
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket('test_bucket')
->addRangeStart(new DateTime('2022-08-12 17:31:00'));
public function testCorrectInstancesAreCreated() {
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket( 'test_bucket' )
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) );
$instances = [
\Arendsen\FluxQueryBuilder\Functions\From::class,
\Arendsen\FluxQueryBuilder\Functions\Range::class,
\Arendsen\FluxQueryBuilder\Functions\Measurement::class,
];
$instances = [
\Hosterra\FluxBuilder\Functions\From::class,
\Hosterra\FluxBuilder\Functions\Range::class,
\Hosterra\FluxBuilder\Functions\Measurement::class,
];
$requiredFluxQueryParts = $this->getClassProperty($queryBuilder, 'requiredFluxQueryParts');
$requiredFluxQueryParts = $this->getClassProperty( $queryBuilder, 'requiredFluxQueryParts' );
foreach ($requiredFluxQueryParts as $keyPart => $part) {
$this->assertEquals($instances[$keyPart], $part);
}
}
foreach ( $requiredFluxQueryParts as $keyPart => $part ) {
$this->assertEquals( $instances[ $keyPart ], $part );
}
}
private function getClassProperty($object, string $property): array
{
$propertyReader = function & ($object, $property) {
$value = & Closure::bind(function & () use ($property) {
return $this->$property;
}, $object, $object)->__invoke();
private function getClassProperty( $object, string $property ): array {
$propertyReader = function & ( $object, $property ) {
$value = &Closure::bind( function & () use ( $property ) {
return $this->$property;
}, $object, $object )->__invoke();
return $value;
};
return $value;
};
return $propertyReader($object, $property);
}
return $propertyReader( $object, $property );
}
}

View file

@ -1,97 +1,94 @@
<?php
declare(strict_types=1);
declare( strict_types=1 );
namespace Tests\Type;
use DateTime;
use Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Type\CustomType;
use Arendsen\FluxQueryBuilder\Type\DurationType;
use Arendsen\FluxQueryBuilder\Type\FnType;
use Arendsen\FluxQueryBuilder\Type\MathType;
use Arendsen\FluxQueryBuilder\Type\RecordType;
use Hosterra\FluxBuilder\Type;
use Hosterra\FluxBuilder\Type\CustomType;
use Hosterra\FluxBuilder\Type\DurationType;
use Hosterra\FluxBuilder\Type\FnType;
use Hosterra\FluxBuilder\Type\MathType;
use Hosterra\FluxBuilder\Type\RecordType;
use PHPUnit\Framework\TestCase;
final class FactoryTypeTest extends TestCase
{
/**
* @dataProvider getFluxStringProvider
*/
public function testGetFluxString($value, $expected)
{
$type = new Type($value);
final class FactoryTypeTest extends TestCase {
/**
* @dataProvider getFluxStringProvider
*/
public function testGetFluxString( $value, $expected ) {
$type = new Type( $value );
$this->assertEquals($expected, $type->__toString());
}
$this->assertEquals( $expected, $type->__toString() );
}
public function getFluxStringProvider()
{
return [
'DateTime' => [
new DateTime('2022-08-15 23:09:00'),
'time(v: 2022-08-15T23:09:00Z)',
],
'String' => [
'value',
'"value"',
],
'Integer' => [
12345,
'12345'
],
'Boolean True' => [
true,
'true'
],
'Boolean False' => [
false,
'false'
],
'Array' => [
['hello', 'world'],
'"hello", "world"'
],
'Dictionary' => [
['hello' => 'world', 'foo' => 'bar'],
'hello: "world", foo: "bar"'
],
'Array Multidimensional' => [
['hello' => ['test', 'foo']],
'hello: ["test", "foo"]'
],
'Array Multidimensional 2' => [
['hello' => ['test' => 'bar', 'foo' => 'hi']],
'hello: [test: "bar", foo: "hi"]'
],
'RecordType' => [
new RecordType(['foo' => 'bar', 'nested' => ['hello' => 'world']]),
'{foo: "bar", nested: {hello: "world"}}'
],
'DurationType' => [
new DurationType('5h'),
'5h',
],
'MathType' => [
new MathType('r.count + 1'),
'r.count + 1'
],
'CustomType' => [
new CustomType('this can be anything'),
'this can be anything'
],
'FnType with only content' => [
FnType::params([])->withBlock('r with _value: r._value * r._value'),
'() => { r with _value: r._value * r._value }'
],
'FnType with params and a body' => [
FnType::params(['r'])->withBody('r with _value: r._value * r._value'),
'(r) => r with _value: r._value * r._value'
],
'FnType with params and a block' => [
FnType::params(['r', 'a'])->withBlock('return r with _value: r._value * r._value'),
'(r, a) => { return r with _value: r._value * r._value }'
],
];
}
public function getFluxStringProvider() {
return [
'DateTime' => [
new DateTime( '2022-08-15 23:09:00' ),
'time(v: 2022-08-15T23:09:00Z)',
],
'String' => [
'value',
'"value"',
],
'Integer' => [
12345,
'12345'
],
'Boolean True' => [
true,
'true'
],
'Boolean False' => [
false,
'false'
],
'Array' => [
[ 'hello', 'world' ],
'"hello", "world"'
],
'Dictionary' => [
[ 'hello' => 'world', 'foo' => 'bar' ],
'hello: "world", foo: "bar"'
],
'Array Multidimensional' => [
[ 'hello' => [ 'test', 'foo' ] ],
'hello: ["test", "foo"]'
],
'Array Multidimensional 2' => [
[ 'hello' => [ 'test' => 'bar', 'foo' => 'hi' ] ],
'hello: [test: "bar", foo: "hi"]'
],
'RecordType' => [
new RecordType( [ 'foo' => 'bar', 'nested' => [ 'hello' => 'world' ] ] ),
'{foo: "bar", nested: {hello: "world"}}'
],
'DurationType' => [
new DurationType( '5h' ),
'5h',
],
'MathType' => [
new MathType( 'r.count + 1' ),
'r.count + 1'
],
'CustomType' => [
new CustomType( 'this can be anything' ),
'this can be anything'
],
'FnType with only content' => [
FnType::params( [] )->withBlock( 'r with _value: r._value * r._value' ),
'() => { r with _value: r._value * r._value }'
],
'FnType with params and a body' => [
FnType::params( [ 'r' ] )->withBody( 'r with _value: r._value * r._value' ),
'(r) => r with _value: r._value * r._value'
],
'FnType with params and a block' => [
FnType::params( [ 'r', 'a' ] )->withBlock( 'return r with _value: r._value * r._value' ),
'(r, a) => { return r with _value: r._value * r._value }'
],
];
}
}