Drops.Relation.Schema.Index (drops_relation v0.1.0)

View Source

Represents 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

Types

index_type()

@type index_type() :: :btree | :hash | :gin | :gist | :brin | nil

t()

@type t() :: %Drops.Relation.Schema.Index{
  composite: boolean(),
  fields: [Drops.Relation.Schema.Field.t()],
  name: String.t(),
  type: index_type(),
  unique: boolean()
}

Functions

new(name, fields, unique \\ false, type \\ nil)

Creates a new Index struct.

Parameters

  • name - The index name
  • fields - List of Field structs covered by the index
  • unique - Whether the index enforces uniqueness
  • type - 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