2023-01-13 16:26:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Arendsen\FluxQueryBuilder\Builder;
|
|
|
|
|
|
|
|
|
|
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
|
|
|
|
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
2023-02-12 17:18:23 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Count;
|
2023-01-13 16:26:45 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
2023-02-12 17:18:23 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\First;
|
2023-01-13 16:26:45 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Group;
|
2023-02-12 17:18:23 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Last;
|
2023-01-13 16:26:45 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
2023-02-12 17:18:23 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Map;
|
|
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Max;
|
2023-01-13 16:26:45 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Mean;
|
2023-02-12 17:18:23 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Min;
|
|
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
|
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
2023-01-17 16:25:24 +00:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Sum;
|
2023-02-12 17:54:18 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Unique;
|
2023-02-12 17:18:23 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Functions\Window;
|
2023-01-13 16:26:45 +01:00
|
|
|
|
|
|
|
|
trait Universe
|
|
|
|
|
{
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addAggregateWindow($every, $fn, array $options = []): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new AggregateWindow($every, $fn, $options)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addCount(?string $column = null): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Count($column)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addDuplicate(string $column, string $as): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Duplicate($column, $as)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addFirst(?string $column = null): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new First($column)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addGroup(array $columns, $mode = 'by'): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Group($columns, $mode)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addLast(string $column = '_value'): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Last($column)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 16:26:45 +01:00
|
|
|
public function addLimit(int $limit, int $offset = 0): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Limit($limit, $offset)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addMap($query): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Map($query)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addMax(?string $column = null): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Max($column)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addMean(?string $column = ''): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Mean($column)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addMin(?string $column = null): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Min($column)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addReduce(array $settings, array $identity): QueryBuilderInterface
|
2023-01-13 16:26:45 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Reduce($settings, $identity)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addSort(array $columns = ['_value'], bool $desc = false): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Sort($columns, $desc)
|
2023-01-13 16:26:45 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2023-01-17 16:25:24 +00:00
|
|
|
|
|
|
|
|
public function addSum(string $column): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Sum($column)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2023-02-10 11:40:35 +01:00
|
|
|
|
2023-02-12 17:54:18 +01:00
|
|
|
public function addUnique(?string $column = null): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Unique($column)
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:18:23 +01:00
|
|
|
public function addUnWindow(): QueryBuilderInterface
|
2023-02-10 11:46:54 +01:00
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
2023-02-12 17:18:23 +01:00
|
|
|
new Window('inf')
|
|
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addWindow($every, array $options = []): QueryBuilderInterface
|
|
|
|
|
{
|
|
|
|
|
$this->addToQuery(
|
|
|
|
|
new Window($every, $options)
|
2023-02-10 11:46:54 +01:00
|
|
|
);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2023-01-13 16:26:45 +01:00
|
|
|
}
|