sequelize-auto
sequelize-auto copied to clipboard
Option to generate to sequelize-decorators format
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
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
+1 for this, decorators would be a powerful addition and save a lot of clutter