## 版本v4 #### 参考:https://eggjs.org/zh-cn/tutorials/sequelize.html #### github:https://github.com/eggjs/egg-sequelize #### confit/plugin.js开启 ![](https://img.kancloud.cn/6f/f2/6ff22d3b10274991e2cfb64cff8b26a5_357x107.png) #### app.js初始化model ![](https://img.kancloud.cn/51/b8/51b88a64258138abf85e353b610a1b4b_674x210.png) #### Model引用方式 ``` module.exports = app => { const {Sequelize, model} = app const Model = model.define('[name]', { id: { type: Sequelize.STRING.BINARY, // VARCHAR BINARY default: Sequelize.UUIDV1, primaryKey: true } },{ freezeTableName: true, tableName: [name], timestamps: true, // 是否给每条记录添加 createdAt 和 updatedAt 字段 默认true paranoid: true // 设置 deletedAt 字段 默认为false }) Model.associate = function() { // belongsTo hasMany ... } return Model } ``` * 封装有效V4版本 ![](https://img.kancloud.cn/e5/04/e504542eb9a372b3ab7296ecc73a0751_722x169.png)