sequelize-joi

2.0.1 • Public • Published

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

Package Sidebar

Install

npm i sequelize-joi

Weekly Downloads

111

Version

2.0.1

License

MIT

Unpacked Size

4.39 kB

Total Files

4

Last publish

Collaborators

  • mattiamalonni