class Cql::Index

Overview

An index on a table This class represents an index on a table It provides methods for setting the columns and unique constraint It also provides methods for generating the index name

Example Creating a new index

schema.define do
  table :users do
    column :name, String
    column :email, String
    index [:name, :email], unique: true
  end
end

Defined in:

index.cr

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)
  • @return : Nil
  • @raise : Cql::Error if the table does not exist
  • @raise : Cql::Error if the column does not exist

Example

index = Cql::Index.new(table, [:name, :email], unique: true)

[View source]

Instance Method Detail

def columns : Array(Symbol) #

[View source]
def index_name #

Generate the index name

  • @return : String
  • @raise : Nil

Example

index_name = index.index_name

[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]