sequelize-joi
v2.0.1
Published
Joi schema validation for Sequelize models
Downloads
440
Maintainers
Readme
Sequelize Joi
Allows specifying Joi validation schema for model attributes in Sequelize.
Installation
npm install sequelize-joi
Usage
const { Sequelize, DataTypes } = require("sequelize");
const { sequelizeJoi, Joi } = require("sequelize-joi");
const database = new Sequelize({
...sequelizeConnectionOptions,
});
sequelizeJoi(database);
const User = database.define("User", {
username: {
type: DataTypes.STRING,
schema: Joi.string().trim().alphanum().min(6).max(30),
},
email: {
type: DataTypes.STRING,
schema: Joi.string().trim().required().email(),
},
password: {
type: DataTypes.STRING,
schema: Joi.string().trim().required().min(8),
},
});