sequelize-auto icon indicating copy to clipboard operation
sequelize-auto copied to clipboard

Option to generate to sequelize-decorators format

Open hendrul opened this issue 7 years ago • 3 comments

hendrul avatar Jan 25 '18 15:01 hendrul

I'm using this format, it is compatible with sequelize-decorators

// @flow
const { Sequelize, Model, DataTypes } = require('sequelize')
const { Options, Attributes } = require('sequelize-decorators')

module.exports.default = (sequelize: Sequelize): Model => {
  const { models } = sequelize

  @Options({
    tableName: 'dat_sale',
    validate: {
      // POST-VALIDACIONES
    },
    sequelize,
  })
  @Attributes({
    id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      field: 'id',
    },
    ....
  })
  class Sale extends Model {
    static associate() {
      this.hasMany(models.SaleItem, { as: 'items', foreignKey: 'saleId' })
      this.hasMany(models.SalePayment, { as: 'payments', foreignKey: 'saleId' })
    }
  }

  return Sale
}

Note: The associations are for ilustration purposes

hendrul avatar Jan 25 '18 15:01 hendrul

I developed this tool that can help you in the migration process. Use decorators! It generates all Models from its database. You can also modify everything you need without problems. https://github.com/leonetosoft/ny-sequelize-auto

leonetosoft avatar Apr 23 '20 19:04 leonetosoft

+1 for this, decorators would be a powerful addition and save a lot of clutter

adsilva-ivre avatar Apr 26 '21 08:04 adsilva-ivre