banner.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const { DataTypes } = require('sequelize');
  2. const connect = require('./connect');
  3. /*
  4. type: DataTypes.STRING,
  5. allowNull: false,
  6. defaultValue:'',
  7. comment: '名',
  8. */
  9. const model = connect.define(
  10. __filename.slice(__dirname.length + 1).replace('.js', ''),
  11. {
  12. id: {
  13. type: DataTypes.INTEGER,
  14. autoIncrement: true,
  15. primaryKey: true,
  16. comment: 'id',
  17. },
  18. name: {
  19. type: DataTypes.STRING,
  20. allowNull: false,
  21. comment: '名',
  22. },
  23. img: {
  24. type: DataTypes.STRING,
  25. allowNull: false,
  26. comment: '图片',
  27. },
  28. href: {
  29. type: DataTypes.STRING,
  30. defaultValue: '',
  31. comment: '地址',
  32. },
  33. weight: {
  34. type: DataTypes.INTEGER,
  35. defaultValue: 100,
  36. comment: '权重',
  37. },
  38. status: {
  39. type: DataTypes.INTEGER,
  40. defaultValue: 0,
  41. comment: '状态',
  42. },
  43. },
  44. {
  45. comment: '焦点图',
  46. hooks: {
  47. beforeFind(option) {
  48. if (!option.order) {
  49. option.order = [['weight', 'asc']];
  50. }
  51. },
  52. },
  53. }
  54. );
  55. module.exports = model;