60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
namespace DatabaseHelper\interfaces;
|
|
|
|
use DatabaseHelper\enums\ColumnTypes;
|
|
use DatabaseHelper\enums\CascadeTypes;
|
|
use DatabaseHelper\enums\EngineTypes;
|
|
use DatabaseHelper\enums\CharsetTypes;
|
|
use DatabaseHelper\enums\CollationTypes;
|
|
|
|
/**
|
|
* Defines a blueprint for building database tables with a fluent interface, which supports method chaining.
|
|
*/
|
|
interface TableBlueprint
|
|
{
|
|
public function __construct(string $tableName);
|
|
|
|
/**
|
|
* Adds a column.
|
|
* @param string $name Column name.
|
|
* @param ColumnTypes $type Column type.
|
|
* @param mixed|null $default Default value (optional).
|
|
* @param bool $nullable Nullable column (default: false).
|
|
* @param bool $unique Unique constraint (default: false).
|
|
* @return TableBlueprint Current instance for method chaining.
|
|
*/
|
|
public function column(string $name, ColumnTypes $type, mixed $default = null, bool $nullable = false, bool $unique = false): TableBlueprint;
|
|
|
|
public function primaryColumn(string $name, ColumnTypes $type, bool $autoincrement = false): TableBlueprint;
|
|
|
|
public function foreignColumn(TableBlueprint $foreignTable, CascadeTypes $onDelete, CascadeTypes $onUpdate): TableBlueprint;
|
|
|
|
/**
|
|
* Sets the table engine.
|
|
* @param EngineTypes $engine Storage engine.
|
|
* @return TableBlueprint Current instance for method chaining.
|
|
*/
|
|
public function engine(EngineTypes $engine): TableBlueprint;
|
|
|
|
/**
|
|
* Sets the character set.
|
|
* @param CharsetTypes $charset Character set.
|
|
* @return TableBlueprint Current instance for method chaining.
|
|
*/
|
|
public function charset(CharsetTypes $charset): TableBlueprint;
|
|
|
|
/**
|
|
* Sets the collation.
|
|
* @param CollationTypes $collation Collation to use.
|
|
* @return TableBlueprint Current instance for method chaining.
|
|
*/
|
|
public function collation(CollationTypes $collation): TableBlueprint;
|
|
|
|
/**
|
|
* Executes the blueprint.
|
|
* @return void
|
|
*/
|
|
public function create(): void;
|
|
}
|
|
|