ulmus/src/Query/Alter.php
2024-05-31 12:26:39 +00:00

42 lines
907 B
PHP

<?php
namespace Ulmus\Query;
use Ulmus\Adapter\AdapterInterface;
use Ulmus\Common\EntityField;
class Alter extends Fragment {
const SQL_TOKEN = "ALTER TABLE";
public string $table;
public string $engine;
public int $order = -80;
public bool $skipExisting = true;
public array $fieldList;
public AdapterInterface $adapter;
public function __construct(AdapterInterface $adapter) {
$this->adapter = $adapter;
}
public function render() : string
{
return $this->renderSegments([
static::SQL_TOKEN, $this->renderTables($this->table), $this->renderFields(),
]);
}
public function renderFields() : string
{
return PHP_EOL . implode("," . PHP_EOL, array_map(function($field) {
return " " . EntityField::generateAlterColumn($this->adapter, $field);
}, $this->fieldList));
}
}