Add Group, Limit, Map, Sort functions
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
1922f33c5c
commit
147b2d9017
11 changed files with 252 additions and 2 deletions
32
src/Function/Group.php
Normal file
32
src/Function/Group.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Function;
|
||||
|
||||
class Group extends Base {
|
||||
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @var string $mode
|
||||
*/
|
||||
private $mode;
|
||||
|
||||
public function __construct(array $columns, string $mode = 'by')
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$columns = array_map(function($column) {
|
||||
return '"' . $column . '"';
|
||||
}, $this->columns);
|
||||
|
||||
return '|> group(columns: [' . implode(', ', $columns) . '], mode: "' . $this->mode . '") ';
|
||||
}
|
||||
|
||||
}
|
||||
22
src/Function/Limit.php
Normal file
22
src/Function/Limit.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Function;
|
||||
|
||||
class Limit extends Base {
|
||||
|
||||
/**
|
||||
* @var int $limit
|
||||
*/
|
||||
private $limit;
|
||||
|
||||
public function __construct(int $limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> limit(n:' . (string)$this->limit . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
22
src/Function/Map.php
Normal file
22
src/Function/Map.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Function;
|
||||
|
||||
class Map extends Base {
|
||||
|
||||
/**
|
||||
* @var array $query
|
||||
*/
|
||||
private $query;
|
||||
|
||||
public function __construct(string $query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> map(fn: (r) => ({ ' . $this->query . ' })) ';
|
||||
}
|
||||
|
||||
}
|
||||
33
src/Function/Sort.php
Normal file
33
src/Function/Sort.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Function;
|
||||
|
||||
class Sort extends Base {
|
||||
|
||||
/**
|
||||
* @var array $columns
|
||||
*/
|
||||
private $columns;
|
||||
|
||||
/**
|
||||
* @var bool $desc
|
||||
*/
|
||||
private $desc;
|
||||
|
||||
public function __construct(array $columns, bool $desc = false)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->desc = $desc;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$columns = array_map(function($column) {
|
||||
return '"' . $column . '"';
|
||||
}, $this->columns);
|
||||
$desc = $this->desc ? 'true' : 'false';
|
||||
|
||||
return '|> sort(columns: [' . implode(', ', $columns) . '], desc: ' . $desc . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue