Add Map expression

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-10-25 17:55:35 +00:00
commit d52f3e9d74
10 changed files with 140 additions and 12 deletions

View file

@ -204,4 +204,4 @@ class KeyFilter extends Base
throw new Exception('Operator "' . $operator . '" is not supported!');
}
}
}
}

View file

@ -207,4 +207,4 @@ class KeyValue extends Base
throw new Exception('Operator "' . $operator . '" is not supported!');
}
}
}
}

27
src/Expression/Map.php Normal file
View file

@ -0,0 +1,27 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression;
use Arendsen\FluxQueryBuilder\Type\FieldRecordType;
class Map extends Base
{
private static $string;
public static function with(string $name, string $content): Map
{
self::$string = 'r with ' . $name . ': ' . $content;
return new self();
}
public static function columns(array $columns)
{
self::$string = new FieldRecordType($columns);
return new self();
}
public function __toString()
{
return self::$string;
}
}

View file

@ -0,0 +1,37 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression;
use Arendsen\FluxQueryBuilder\Type;
class Selection extends Base
{
private $string;
private function __construct(string $string)
{
$this->string = $string;
}
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 else($else): Selection
{
$this->string .= ' else ' . new Type($else);
return $this;
}
public function __toString()
{
return $this->string;
}
}

View file

@ -2,14 +2,16 @@
namespace Arendsen\FluxQueryBuilder\Functions;
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
class Map extends Base
{
/**
* @var array $query
* @var mixed $query
*/
private $query;
public function __construct(string $query)
public function __construct($query)
{
$this->query = $query;
}

View file

@ -158,7 +158,7 @@ class QueryBuilder
return $this;
}
public function addMap(string $query): QueryBuilder
public function addMap($query): QueryBuilder
{
$this->addToQuery(
self::FLUX_PART_MAP,

View file

@ -0,0 +1,27 @@
<?php
namespace Arendsen\FluxQueryBuilder\Type;
use Arendsen\FluxQueryBuilder\Settings;
use Arendsen\FluxQueryBuilder\Type;
class FieldRecordType implements TypeInterface
{
public const SETTING_IS_RECORD = 'isRecord';
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;
}
});
return '{' . implode(', ', $this->value) . '}';
}
}