model.js 986 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const { Model } = require('sequelize');
  3. module.exports = (sequelize, DataTypes) => {
  4. class <%= name %> extends Model {
  5. /**
  6. * Helper method for defining associations.
  7. * This method is not a part of Sequelize lifecycle.
  8. * The `models/index` file will call this method automatically.
  9. */
  10. static associate (models) {
  11. // define association here
  12. }
  13. }
  14. <%= name %>.init({
  15. <% attributes.forEach(function(attribute, index) { %>
  16. <%= attribute.fieldName %>: DataTypes.<%= attribute.dataFunction ? `${attribute.dataFunction.toUpperCase()}(DataTypes.${attribute.dataType.toUpperCase()})` : attribute.dataValues ? `${attribute.dataType.toUpperCase()}(${attribute.dataValues})` : attribute.dataType.toUpperCase() %>
  17. <%= (Object.keys(attributes).length - 1) > index ? ',' : '' %>
  18. <% }) %>
  19. }, {
  20. sequelize,
  21. modelName: '<%= name %>',
  22. <%= underscored ? 'underscored: true,' : '' %>
  23. });
  24. return <%= name %>;
  25. };