class CQL::Index

Overview

An index on a table: its columns, whether it is unique, and its name. Declare one with Table#index (or Table#add_index) in a table block.

Example Declaring an index

schema.table :members do
  primary :id, Int64
  column :name, String
  column :email, String
  index [:name, :email], unique: true
end

Defined in:

index.cr

Constant Summary

MAX_NAME_LENGTH = 63

Constructors

Instance Method Summary

Constructor Detail

def self.new(table : Table, columns : Array(Symbol), unique : Bool = false, name : String | Nil = nil) #

Create a new index instance on a table

  • @param : table (Table) - The table to create the index on
  • @param : columns (Array(Symbol)) - The columns to index
  • @param : unique (Bool) - Whether the index should be unique (default: false)
  • @param : name (String, nil) - The name of the index (default: nil)

Example

index = CQL::Index.new(schema.users, [:name, :email], unique: true)

[View source]

Instance Method Detail

def columns : Array(Symbol) #

[View source]
def index_name : String #

The index name: the explicit name, or idx_<table>_<columns>. Index names are schema-wide in SQLite and PostgreSQL, so the default includes the table.

Example

CQL::Index.new(schema.users, [:name, :email]).index_name # => "idx_users_name_email"

[View source]
def name : String | Nil #

[View source]
def name=(name : String | Nil) #

[View source]
def table : Table #

[View source]
def unique? : Bool #

[View source]