Adds a column to the index.
Also see columns for adding multiple columns at once or expression for specifying an arbitrary expression.
await db.schema
.alterTable('person')
.addIndex('person_first_name_and_age_index')
.column('first_name')
.column('age desc')
.execute()
The generated SQL (MySQL):
alter table `person` add index `person_first_name_and_age_index` (`first_name`, `age` desc)
Specifies a list of columns for the index.
Also see column for adding a single column or expression for specifying an arbitrary expression.
await db.schema
.alterTable('person')
.addIndex('person_first_name_and_age_index')
.columns(['first_name', 'age desc'])
.execute()
The generated SQL (MySQL):
alter table `person` add index `person_first_name_and_age_index` (`first_name`, `age` desc)
Specifies an arbitrary expression for the index.
import { sql } from 'kysely'
await db.schema
.alterTable('person')
.addIndex('person_first_name_index')
.expression(sql<boolean>`(first_name < 'Sami')`)
.execute()
The generated SQL (MySQL):
alter table `person` add index `person_first_name_index` ((first_name < 'Sami'))
Makes the index unique.
await db.schema
.alterTable('person')
.addIndex('person_first_name_index')
.unique()
.column('email')
.execute()
The generated SQL (MySQL):
alter table `person` add unique index `person_first_name_index` (`email`)
Specifies the index type.
await db.schema
.alterTable('person')
.addIndex('person_first_name_index')
.column('first_name')
.using('hash')
.execute()
The generated SQL (MySQL):
alter table `person` add index `person_first_name_index` (`first_name`) using hash
Specifies the index type.
await db.schema
.alterTable('person')
.addIndex('person_first_name_index')
.column('first_name')
.using('hash')
.execute()
The generated SQL (MySQL):
alter table `person` add index `person_first_name_index` (`first_name`) using hash
Simply calls the provided function passing
thisas the only argument.$callreturns what the provided function returns.