sequelize / sequelize-auto

Automatically generate bare sequelize models from your database.
2.9k stars 527 forks source link

Add option to create instance instead of automatically returning the definition of the model #629

Open Xoouu opened 1 year ago

Xoouu commented 1 year ago

Instead of defining the model like this:

module.exports = function(sequelize, DataTypes) {
  return sequelize.define('User', {
    // Model attributes are defined here
    firstName: {
      type: DataTypes.STRING,
      allowNull: false
    },
    lastName: {
      type: DataTypes.STRING
      // allowNull defaults to true
    },
  }
}

Being able to choose to define it with an instance:

module.exports = function(sequelize, DataTypes) {
  const User = sequelize.define('User', {
    // Model attributes are defined here
    firstName: {
      type: DataTypes.STRING,
      allowNull: false
    },
    lastName: {
      type: DataTypes.STRING
      // allowNull defaults to true
    }
  }, {
    // Other model options go here
  });

  // Hook
  User.beforeCreate(()=>{
   // something
  })

  return User;
}

If that is possible to already do, where can I find that information?