Adds a column to the index.
Also see columns for adding multiple columns at once or expression for specifying an arbitrary expression.
import { sql } from 'kysely'
await db.schema
.alterTable('person')
.addIndex('person_first_name_and_age_index')
.column('first_name')
.column(sql`(left(lower(last_name), 1))`)
.column('age desc')
.execute()
The generated SQL (MySQL):
alter table `person`
add index `person_first_name_and_age_index` (
`first_name`,
(left(lower(last_name), 1)),
`age` desc
)
Adds a column to the index.
Also see columns for adding multiple columns at once or expression for specifying an arbitrary expression.
import { sql } from 'kysely'
await db.schema
.alterTable('person')
.addIndex('person_first_name_and_age_index')
.column('first_name')
.column(sql`(left(lower(last_name), 1))`)
.column('age desc')
.execute()
The generated SQL (MySQL):
alter table `person`
add index `person_first_name_and_age_index` (
`first_name`,
(left(lower(last_name), 1)),
`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.
import { sql } from 'kysely'
await db.schema
.alterTable('person')
.addIndex('person_first_name_and_age_index')
.columns(['first_name', sql`(left(lower(last_name), 1))`, 'age desc'])
.execute()
The generated SQL (MySQL):
alter table `person`
add index `person_first_name_and_age_index` (
`first_name`,
(left(lower(last_name), 1)),
`age` desc
)
Optionaloptions: AbortableQueryOptionsSpecifies 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'))
Use column or columns with an Expression instead.
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.