mini\Database\Attributes\Index class

Documentation

Creates database index

Inspired by Entity Framework Core's [Index] attribute.

For single-column indexes, apply to the property. For composite indexes, apply to the class level.

Single column example:

#[Index]
public string $email;

#[Index(unique: true)]
public string $username;

Composite index example:

#[Index(columns: ['last_name', 'first_name'])]
#[Index(columns: ['email'], unique: true)]
class User {
    public string $first_name;
    public string $last_name;
    public string $email;
}

Descending indexes:

#[Index(columns: ['created_at'], descending: true)]
class Post { }

// Per-column control for composite
#[Index(columns: ['category', 'created_at'], descending: [false, true])]
class Article { }

Properties (4)

public ?array $columns
public ?string $name
public bool $unique
public array|bool $descending

Methods (1)

Documentation missing

Source

src/Database/Attributes/Index.php:44-59