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.
84 lines
2.1 KiB
84 lines
2.1 KiB
<?php
|
|
|
|
namespace Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders;
|
|
|
|
use Darksparrow\DeegraphPHP\Attributes\QueryBuilderRequiredField;
|
|
use Darksparrow\DeegraphPHP\Attributes\QueryBuilderQuery;
|
|
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilderTrait;
|
|
|
|
#[QueryBuilderQuery]
|
|
final class InsertQuery
|
|
{
|
|
use QueryBuilderTrait;
|
|
|
|
#[QueryBuilderRequiredField]
|
|
protected string $RelativePath = "";
|
|
|
|
protected array $Keys = [];
|
|
|
|
protected array $Schemas = [];
|
|
|
|
protected string $Values = "";
|
|
|
|
protected bool $Duplicate = false;
|
|
|
|
protected bool $Replace = false;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
$instance = new QueryBuilderQuery();
|
|
$instance->ValidateValues($this);
|
|
|
|
$builder = "INSERT INTO $this->RelativePath";
|
|
|
|
if(sizeof($this->Keys) > 0) $builder .= "KEYS " . implode(separator: ", ", array: $this->Keys);
|
|
if(sizeof($this->Schemas) > 0) $builder .= "SCHEMAS " . implode(separator: ", ", array: $this->Schemas);
|
|
if($this->Values != "") $builder .= "VALUES $this->Values";
|
|
if($this->Duplicate) $builder .= "DUPLICATE";
|
|
if($this->Replace) $builder .= "REPLACE";
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function RelativePath(string $relativePath): InsertQuery
|
|
{
|
|
self::ValidateDeegraphPath(target: $relativePath);
|
|
$this->RelativePath = $relativePath;
|
|
return $this;
|
|
}
|
|
|
|
public function Keys(string $keys): InsertQuery
|
|
{
|
|
$this->Keys = $keys;
|
|
return $this;
|
|
}
|
|
|
|
public function Schemas(string $schemas): InsertQuery
|
|
{
|
|
$this->Schemas = $schemas;
|
|
return $this;
|
|
}
|
|
|
|
public function Values(string $values): InsertQuery
|
|
{
|
|
$this->Values .= $values;
|
|
return $this;
|
|
}
|
|
|
|
public function Duplicate(): InsertQuery
|
|
{
|
|
$this->Duplicate = true;
|
|
return $this;
|
|
}
|
|
|
|
public function Replace(): InsertQuery
|
|
{
|
|
$this->Replace = true;
|
|
return $this;
|
|
}
|
|
}
|