Drops.Relation.Schema.Index (drops_relation v0.1.0)
View SourceRepresents a database index on a table.
This struct stores information about a database index including its name, the fields it covers, whether it's unique, and its type. Fields are stored as Field structs containing complete metadata.
Examples
# Simple index
%Drops.Relation.Schema.Index{
name: "users_email_index",
fields: [%Drops.Relation.Schema.Field{name: :email, ...}],
unique: true,
type: :btree
}
# Composite index
%Drops.Relation.Schema.Index{
name: "users_name_email_index",
fields: [
%Drops.Relation.Schema.Field{name: :name, ...},
%Drops.Relation.Schema.Field{name: :email, ...}
],
unique: false,
type: :btree
}
Summary
Functions
Creates a new Index struct.
Types
@type index_type() :: :btree | :hash | :gin | :gist | :brin | nil
@type t() :: %Drops.Relation.Schema.Index{ composite: boolean(), fields: [Drops.Relation.Schema.Field.t()], name: String.t(), type: index_type(), unique: boolean() }
Functions
@spec new(String.t(), [Drops.Relation.Schema.Field.t()], boolean(), index_type()) :: t()
Creates a new Index struct.
Parameters
name
- The index namefields
- List of Field structs covered by the indexunique
- Whether the index enforces uniquenesstype
- The index type (optional)
Examples
iex> field = Drops.Relation.Schema.Field.new(:email, :string, :string, :email)
iex> index = Drops.Relation.Schema.Index.new("users_email_index", [field], true, :btree)
iex> index.name
"users_email_index"
iex> index.unique
true