获取器
优质
小牛编辑
139浏览
2023-12-01
get() 获取器,查询数据时触发
'use strict';
const moment = require('moment')
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const User = app.model.define('users', {
id: { type: INTEGER(20).UNSIGNED, primaryKey: true, autoIncrement: true },
gender: { type: ENUM, values: ['男','女','保密'], allowNull: true, defaultValue: '男', comment: '用户性别'},
// 查询数据时,格式化时间
createdAt: {type: DATE, get() {return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss')}},
updatedAt: {type: DATE, get() {return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm:ss')}}
});
return User;
};