Class Index
Index value object
Models a database index and its attributes.
Method Summary
-
__construct() public
Constructor
-
getColumns() public
Gets the index columns.
-
getInclude() public
Gets the index included columns.
-
getLength() public
Gets the index length.
-
getName() public
Gets the index name.
-
getOrder() public
Gets the index columns sort order.
-
getType() public
Gets the index type.
-
getWhere() public
Get the where clause for partial indexes.
-
setAttributes() public
Utility method that maps an array of index options to this object's methods.
-
setColumns() public
Sets the index columns.
-
setInclude() public
Sets the index included columns for a 'covering index'.
-
setLength() public
Sets the index length.
-
setName() public
Sets the index name.
-
setOrder() public
Sets the index columns sort order.
-
setType() public
Sets the index type.
-
setWhere() public
Set the where clause for partial indexes.
-
toArray() public
Convert an index into an array that is compatible with the Index constructor.
Method Detail
__construct() ¶ public
__construct(string $name, array<string> $columns, string $type = self::INDEX, array<string, int>|int|null $length = null, array<string>|null $order = null, array<string>|null $include = null, ?string $where = null)
Constructor
Parameters
-
string$name The name of the index.
-
array<string>$columns The columns to index.
-
string$type optional The type of index, e.g. 'index', 'fulltext'.
-
array<string, int>|int|null$length optional The length of the index.
-
array<string>|null$order optional The sort order of the index columns.
-
array<string>|null$include optional The included columns for covering indexes.
-
?string$where optional The where clause for partial indexes.
getInclude() ¶ public
getInclude(): ?array<string>
Gets the index included columns.
Returns
?array<string>getLength() ¶ public
getLength(): array<string, int>|int|null
Gets the index length.
Can be an array of column names and lengths under MySQL.
Returns
array<string, int>|int|nullgetOrder() ¶ public
getOrder(): ?array<string>
Gets the index columns sort order.
Returns
?array<string>setAttributes() ¶ public
setAttributes(array<string, mixed> $attributes): $this
Utility method that maps an array of index options to this object's methods.
Parameters
-
array<string, mixed>$attributes Attributes to set.
Returns
$thisThrows
RuntimeExceptionsetColumns() ¶ public
setColumns(array<string>|string $columns): $this
Sets the index columns.
Parameters
-
array<string>|string$columns Columns
Returns
$thissetInclude() ¶ public
setInclude(array<string> $includedColumns): $this
Sets the index included columns for a 'covering index'.
In postgres and sqlserver, indexes can define additional non-key columns to build 'covering indexes'. This feature allows you to further optimize well-crafted queries that leverage specific indexes by reading all data from the index.
Parameters
-
array<string>$includedColumns Columns
Returns
$thissetLength() ¶ public
setLength(array<string, int>|int $length): $this
Sets the index length.
In MySQL indexes can have limit clauses to control the number of characters indexed in text and char columns.
Parameters
-
array<string, int>|int$length length value or array of length value
Returns
$thissetName() ¶ public
setName(string $name): $this
Sets the index name.
Parameters
-
string$name Name
Returns
$thissetOrder() ¶ public
setOrder(array<string> $order): $this
Sets the index columns sort order.
Parameters
-
array<string>$order column name sort order key value pair
Returns
$thissetType() ¶ public
setType(string $type): $this
Sets the index type.
Parameters
-
string$type Type
Returns
$thissetWhere() ¶ public
setWhere(?string $where): $this
Set the where clause for partial indexes.
Parameters
-
?string$where The where clause for partial indexes.
Returns
$thistoArray() ¶ public
toArray(): array<string, mixed>
Convert an index into an array that is compatible with the Index constructor.
Returns
array<string, mixed>