Sequelize. SQLite Type checking

Viewed 98

I started using Sequelize with SQLite. When I try to insert or update a value, it doesn't check for type-errors. For example I can use string values in a column with sequelize.BOOLEAN type.

I know SQLite allows this, but what about Sequelize? It doesn't check or I am missing something?

Should I add a validation check for each datatype? Is there an easy way of checking types instead of validating one by one in every model?

Update

I didn't have much time to find the best answer, and I decided to go with the built-in validation instead. For example, for checking if the value is bool or not, I used:

SOME_FIELD_VALIDATOR: {
  isIn: {
     args: [['true', 'false', true, false, 1, 0, '1', '0']],
     msg: 'Not a valid boolean.'
  }
}

It may slow down the process, but I think it is better than not checking.

0 Answers
Related