ColumnIndex() function
Declares an index on a model column, with Postgres's own index options.
Signature:
export declare function ColumnIndex(options: Partial<ColumnIndexOptions>): FunctionType;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
options |
Partial<ColumnIndexOptions> |
The clauses to build into the statement. |
Returns:
A property decorator.
Remarks
Index from sequelize-typescript is re-exported here and covers the ordinary cases through sequelize's own sync. This declares the index as a CREATE INDEX statement instead, which is what makes the Postgres-specific clauses reachable — partial indices, expression keys, operator classes, concurrent builds, covering columns. Sequelize.sync() runs them after the tables and views are in place.
Declarations accumulate, so a column can carry several, and each is named by its position unless you name it.
Example
@Table
export class Lead extends BaseModel<Lead> {
// case-insensitive lookups, over live rows only
@ColumnIndex({
expression: 'lower("email")',
predicate: '"deletedAt" IS NULL',
unique: true,
})
@Column(DataType.STRING)
public email: string;
}