Add KeyValue expression

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-08-05 18:51:35 +00:00
commit b2d1bd403c
7 changed files with 67 additions and 92 deletions

View file

@ -1,30 +0,0 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression\Filter;
use Arendsen\FluxQueryBuilder\Expression\Base;
class AndExpression extends Base {
/**
* @var string $key
*/
private $key;
/**
* @var string $value
*/
private $value;
public function __construct(string $key, string $value)
{
$this->key = $key;
$this->value = $value;
}
public function __toString()
{
return 'and r.' . $this->key . ' == "' . $this->value . '"';
}
}

View file

@ -1,24 +0,0 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression\Filter;
use Arendsen\FluxQueryBuilder\Expression\Base;
class Measurement extends Base {
/**
* @var array $measurement
*/
private $measurement;
public function __construct(string $measurement)
{
$this->measurement = $measurement;
}
public function __toString()
{
return 'r._measurement == "' . $this->measurement . '"';
}
}

View file

@ -1,30 +0,0 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression\Filter;
use Arendsen\FluxQueryBuilder\Expression\Base;
class OrExpression extends Base {
/**
* @var string $key
*/
private $key;
/**
* @var string $value
*/
private $value;
public function __construct(string $key, string $value)
{
$this->key = $key;
$this->value = $value;
}
public function __toString()
{
return 'or r.' . $this->key . ' == "' . $this->value . '"';
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Arendsen\FluxQueryBuilder\Expression;
class KeyValue extends Base {
/**
* @var array $expressions
*/
private $expressions;
public function __construct(string $key, string $value)
{
$this->expressions[] = 'r.' . $key . ' == "' . $value . '"';
}
public static function set(string $key, string $value): KeyValue
{
return new self($key, $value);
}
public function and(string $key, string $value): KeyValue
{
$this->expressions[] = 'and r.' . $key . ' == "' . $value . '"';
return $this;
}
public function or(string $key, string $value): KeyValue
{
$this->expressions[] = 'or r.' . $key . ' == "' . $value . '"';
return $this;
}
public function __toString()
{
return implode(' ', $this->expressions);
}
}