Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 806 Bytes

README.md

File metadata and controls

37 lines (29 loc) · 806 Bytes

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