• The @Unique decorator is used to make an attribute unique, it is a shortcut for setting the unique option of the Attribute decorator. Learn more about unique constraints in our documentation.

    Returns PropertyOrGetterDescriptor

    Example

    This makes "firstName" unique

    class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
    @Attribute(DataTypes.STRING)
    @Unique
    declare firstName: string;
    }

    Example

    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 @Unique decorator is used to make an attribute unique, it is a shortcut for setting the unique option of the Attribute decorator. Learn more about unique constraints in our documentation.

    Parameters

    Returns PropertyOrGetterDescriptor

    Example

    This makes "firstName" unique

    class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
    @Attribute(DataTypes.STRING)
    @Unique
    declare firstName: string;
    }

    Example

    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 @Unique decorator is used to make an attribute unique, it is a shortcut for setting the unique option of the Attribute decorator. Learn more about unique constraints in our documentation.

    Parameters

    Returns void

    Example

    This makes "firstName" unique

    class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
    @Attribute(DataTypes.STRING)
    @Unique
    declare firstName: string;
    }

    Example

    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;
    }