| public primaryKey( boolean $primaryKey = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $primaryKey | boolean | |
public function primaryKey(bool $primaryKey = true): static
{
$this->primaryKey = $primaryKey;
return $this;
}
Represents the metadata of a column in a database table.
It provides information about the column's type, size, scale, and other details.
The Column class is used to store and retrieve metadata about a column in a database table.
It's typically used in conjunction with the TableSchema class, which represents the metadata of a database table as a whole.
Here is an example of how to use the Column class:
use Yiisoft\Db\Schema\IntegerColumn;
$column = (new IntegerColumn())
->notNull()
->dbType('int')
->size(11)
->defaultValue(0)
->autoIncrement()
->primaryKey();
| Method | Description | Defined By |
|---|---|---|
| throwWrongTypeException() | Yiisoft\Db\Schema\Column\AbstractColumn |
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_TYPE | \Yiisoft\Db\Constant\ColumnType::STRING | Yiisoft\Db\Schema\Column\AbstractColumn |
| public __construct( string|null $type = null, boolean $autoIncrement = false, string|null $check = null, string|null $comment = null, boolean $computed = false, string|null $dbType = null, string|null $extra = null, boolean $primaryKey = false, string|null $name = null, boolean|null $notNull = null, Yiisoft\Db\Constraint\ForeignKey|null $reference = null, integer|null $scale = null, integer|null $size = null, boolean $unique = false, boolean $unsigned = false, mixed $args ): mixed | ||
| $type | string|null |
The column's abstract type. |
| $autoIncrement | boolean |
Whether the column is auto-incremental. |
| $check | string|null |
The check constraint for the column. |
| $comment | string|null |
The column's comment. |
| $computed | boolean |
Whether the column is a computed column. |
| $dbType | string|null |
The column's database type. |
| $extra | string|null |
Any extra information that needs to be appended to the column's definition. |
| $primaryKey | boolean |
Whether the column is a primary key. |
| $name | string|null |
The column's name. |
| $notNull | boolean|null |
Whether the column is not nullable. |
| $reference | Yiisoft\Db\Constraint\ForeignKey|null |
The foreign key constraint. |
| $scale | integer|null |
The number of digits to the right of the decimal point. |
| $size | integer|null |
The column's size. |
| $unique | boolean |
Whether the column is unique. |
| $unsigned | boolean |
Whether the column is unsigned. |
| $args | mixed |
Additional arguments to be passed to the constructor. |
public function __construct(
?string $type = null,
private bool $autoIncrement = false,
private ?string $check = null,
private ?string $comment = null,
private bool $computed = false,
private ?string $dbType = null,
private ?string $extra = null,
private bool $primaryKey = false,
private ?string $name = null,
private ?bool $notNull = null,
private ?ForeignKey $reference = null,
private ?int $scale = null,
private ?int $size = null,
private bool $unique = false,
private bool $unsigned = false,
mixed ...$args,
) {
$this->type = $type ?? static::DEFAULT_TYPE;
if (array_key_exists('defaultValue', $args)) {
$this->defaultValue = $args['defaultValue'];
unset($args['defaultValue']);
}
/** @psalm-var array<string, mixed> $args */
foreach ($args as $property => $value) {
if (property_exists($this, $property)) {
$this->$property = $value;
}
}
}
| public autoIncrement( boolean $autoIncrement = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $autoIncrement | boolean | |
public function autoIncrement(bool $autoIncrement = true): static
{
$this->autoIncrement = $autoIncrement;
return $this;
}
| public check( string|null $check ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $check | string|null | |
public function check(?string $check): static
{
$this->check = $check;
return $this;
}
| public comment( string|null $comment ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $comment | string|null | |
public function comment(?string $comment): static
{
$this->comment = $comment;
return $this;
}
| public computed( boolean $computed = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $computed | boolean | |
public function computed(bool $computed = true): static
{
$this->computed = $computed;
return $this;
}
| public dbType( string|null $dbType ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $dbType | string|null | |
public function dbType(?string $dbType): static
{
$this->dbType = $dbType;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\ColumnInterface::dbTypecast()
Convert a value from its PHP representation to a database-specific representation.
yiisoft/db calls it automatically by when preparing an SQL statement, so you don't usually need to call it directly in your code.
If the value is null or an \Yiisoft\Db\Schema\Column\Expression, there will be no conversion.
| public abstract dbTypecast( mixed $value ): mixed | ||
| $value | mixed | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
|---|---|---|
public function dbTypecast(mixed $value): mixed;
| public defaultValue( mixed $defaultValue ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $defaultValue | mixed | |
public function defaultValue(mixed $defaultValue): static
{
$this->defaultValue = $defaultValue;
return $this;
}
| public extra( string|null $extra ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $extra | string|null | |
public function extra(?string $extra): static
{
$this->extra = $extra;
return $this;
}
| public getDefaultValue( ): mixed |
public function getDefaultValue(): mixed
{
return $this->defaultValue ?? null;
}
| public getReference( ): Yiisoft\Db\Constraint\ForeignKey|null |
public function getReference(): ?ForeignKey
{
return $this->reference;
}
| public hasDefaultValue( ): boolean |
public function hasDefaultValue(): bool
{
return property_exists($this, 'defaultValue');
}
| public isAutoIncrement( ): boolean |
public function isAutoIncrement(): bool
{
return $this->autoIncrement;
}
| public notNull( boolean|null $notNull = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $notNull | boolean|null | |
public function notNull(?bool $notNull = true): static
{
$this->notNull = $notNull;
return $this;
}
| public null( ): Yiisoft\Db\Schema\Column\AbstractColumn |
public function null(): static
{
$this->notNull = false;
return $this;
}
Defined in: Yiisoft\Db\Schema\Column\ColumnInterface::phpTypecast()
Converts the input value after retrieval from the database.
| public abstract phpTypecast( mixed $value ): mixed | ||
| $value | mixed | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
|---|---|---|
public function phpTypecast(mixed $value): mixed;
| public primaryKey( boolean $primaryKey = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $primaryKey | boolean | |
public function primaryKey(bool $primaryKey = true): static
{
$this->primaryKey = $primaryKey;
return $this;
}
| public reference( Yiisoft\Db\Constraint\ForeignKey|null $reference ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $reference | Yiisoft\Db\Constraint\ForeignKey|null | |
public function reference(?ForeignKey $reference): static
{
$this->reference = $reference;
return $this;
}
| public scale( integer|null $scale ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $scale | integer|null | |
public function scale(?int $scale): static
{
$this->scale = $scale;
return $this;
}
| public size( integer|null $size ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $size | integer|null | |
public function size(?int $size): static
{
$this->size = $size;
return $this;
}
| protected throwWrongTypeException( string $type ): never | ||
| $type | string | |
protected function throwWrongTypeException(string $type): never
{
throw new InvalidArgumentException("Wrong $type value for $this->type column.");
}
| public type( string $type ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $type | string | |
public function type(string $type): static
{
$this->type = $type;
return $this;
}
| public unique( boolean $unique = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $unique | boolean | |
public function unique(bool $unique = true): static
{
$this->unique = $unique;
return $this;
}
| public unsigned( boolean $unsigned = true ): Yiisoft\Db\Schema\Column\AbstractColumn | ||
| $unsigned | boolean | |
public function unsigned(bool $unsigned = true): static
{
$this->unsigned = $unsigned;
return $this;
}
Signup or Login in order to comment.