ConstThis makes "firstName" unique
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
@Attribute(DataTypes.STRING)
@Unique
declare firstName: string;
}
This creates a composite unique on columns "firstName" and "lastName"
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
@Attribute(DataTypes.STRING)
@Unique('firstName-lastName')
declare firstName: string;
@Attribute(DataTypes.STRING)
@Unique('firstName-lastName')
declare lastName: string;
}
The
@Uniquedecorator is used to make an attribute unique, it is a shortcut for setting theuniqueoption of the Attribute decorator. Learn more about unique constraints in our documentation.