如何在Sequelize表中指定范围?

时间:2018-08-29 14:57:39

标签: sequelize.js

如何在下表的gpa列中指定0.0到4.0之间的范围?

 const Student = db.define('student', {
      firstname: {
        type: Sequelize.STRING,
        validate: {
          notEmpty: true,
        },
        allowNull: false,
      },
      lastname: {
        type: Sequelize.STRING,
        validate: {
          notEmpty: true,
        },
        allowNull: false,
      },
      gpa: {
        type: Sequelize.INTEGER, 
      }
    });

1 个答案:

答案 0 :(得分:0)

我认为这可以帮助您验证:

const Student = db.define('student', {
    ...
    gpa: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        validate: {
            min: 0,
            max: 4
        }
    }
    ...
})

更多详细信息: DO READ