Reorder and new queries, also change to Query/Builder
This commit is contained in:
62
src/Implement/Database/Query/Create.php
Normal file
62
src/Implement/Database/Query/Create.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace ProVM\Implement\Database\Query;
|
||||
|
||||
use ProVM\Implement\Database\Query;
|
||||
use ProVM\Concept\Database;
|
||||
|
||||
abstract class Create extends Query implements Database\Query\Create
|
||||
{
|
||||
use hasTable;
|
||||
|
||||
public function __construct(string $table)
|
||||
{
|
||||
$this->table($table);
|
||||
}
|
||||
|
||||
public function table(string $table): Database\Query\Create
|
||||
{
|
||||
return $this->setTable($table);
|
||||
}
|
||||
public function columns(array|string $columns): Database\Query\Create
|
||||
{
|
||||
return $this->setColumns($columns);
|
||||
}
|
||||
|
||||
protected array|string $columns;
|
||||
|
||||
public function getColumns(): array
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
public function addColumn(string $column): Database\Query\Create
|
||||
{
|
||||
$this->columns []= $column;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setColumns(array|string $columns): Database\Query\Create
|
||||
{
|
||||
if (is_string($columns)) {
|
||||
$this->columns = $columns;
|
||||
return $this;
|
||||
}
|
||||
foreach ($columns as $column) {
|
||||
$this->addColumn($column);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getColumnsString(): string
|
||||
{
|
||||
if (is_string($this->columns)) {
|
||||
return $this->columns;
|
||||
}
|
||||
return implode(', ', $this->getColumns());
|
||||
}
|
||||
|
||||
public function build(): string
|
||||
{
|
||||
return "CREATE {$this->getTable()} ({$this->getColumnsString()})";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user