企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
[TOC] ### 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; }; ~~~