class Avram::Migrator::CreateIndexStatement

Overview

Builds an SQL statement for creating an index using table name, column name(s), index type and unique flag.

Usage

For a single column:

CreateIndexStatement.new(:users, columns: :email, using: :btree, unique: true).build
# => "CREATE UNIQUE INDEX users_email_index ON users USING btree (email);"

For multiple columns:

CreateIndexStatement.new(:users, columns: [:email, :username], using: :btree, unique: true).build
# => "CREATE UNIQUE INDEX users_email_username_index ON users USING btree (email, username);"

With custom name:

CreateIndexStatement.new(:users, columns: [:email, :username], name: :custom_index_name).build
# => "CREATE INDEX custom_index_name ON users USING btree (email, username);"

Included Modules

Defined in:

avram/migrator/create_index_statement.cr

Constructors

Instance Method Summary

Instance methods inherited from module Avram::Migrator::IndexStatementHelpers

add_index(column : Symbol, unique = false, using : Symbol = :btree) add_index, index_added?(index : String, column : Symbol) index_added?

Instance methods inherited from class Object

blank_for_validates_required? : Bool blank_for_validates_required?

Constructor Detail

def self.new(table : TableName, columns : Columns, using : Symbol = :btree, unique : Bool = false, name : String | Nil | Symbol | Nil = nil) #

[View source]

Instance Method Detail

def build #

[View source]