79541528

Date: 2025-03-28 13:21:04
Score: 2
Natty:
Report link

You can add the db check contraint in the type attribute of the column definition.

sequelize

  sequelize.define(
    'products',
    {
      price: {
        type: 'numeric CHECK (price > 0)',
        ...
      },
    },
  )

sequelize-typescript

  @Column({
    type: 'numeric CHECK (price > 0)', // instead of DataType.NUMBER
    ...
  })
  declare price: number

You can also add them using migrations. See: https://stackoverflow.com/a/51076516/6192751

You can also use js validations to accomplish this on the client side. See: https://github.com/sequelize/sequelize-typescript/issues/576#issuecomment-485383173

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Enogwe Victor