You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
final class SelectQueryBuilder implements SelectQueryBuilderInterface
{
use QueryBuilderTrait;
#[QueryBuilderRequiredField]
protected array $RelativePaths = [];
protected string $From = "";
protected string $Where = "";
protected string $InstanceOf = "";
public function __construct()
{
}
public function addRelativePath(string $relativePath): SelectQueryBuilder
{
$this->RelativePaths[] = $relativePath;
return $this;
}
public function relativePaths(array $relativePaths): SelectQueryBuilder
{
$this->RelativePaths = $relativePaths;
return $this;
}
public function from(string $target): SelectQueryBuilder
{
$this->From = "" . $target;
return $this;
}
public function where(string $target, DeegraphEqualityOperator $operator, string $value): SelectQueryBuilder
{
$this->Where = "" . $target . " " . $operator->value . " " . $value;
return $this;
}
public function instanceOf(string $schema): SelectQueryBuilder
{
$this->InstanceOf = "" . $schema;
return $this;
}
public function build(): SelectQuery
{
$builder = "SELECT";
if(sizeof($this->RelativePaths)) $builder .= " " . implode(separator: ", ", array: $this->RelativePaths);
if($this->From != "") $builder .= " FROM $this->From";
if($this->Where != "") $builder .= " WHERE $this->Where";
if($this->InstanceOf != "") $builder .= " INSTANCEOF $this->InstanceOf";
return new SelectQuery(queryString: $builder);
}
}