1、sequelize findOne 如何对查询的结果添加字段

  const content = await Content.findOne({
    where: { id },
    attributes: ['id', 'title', 'content']
  })
  const md = new MarkdownIt()
  const html = md.render(content.content)
  content.setDataValue('html', html)

参考链接:sequelize 获取查询结果(result)后, 如何在 result 上添加一个字段 ?

2、sequelize create 没有返回自增 id

// 返回值中没有 id
const result = await Content.create({ topicId, title, content })

原因是 Model 定义时 id 没有添加

autoIncrement: true,
primaryKey: true,

参考链接:sequelizejs使用cteate插入一条数据之后没有返回id?

标签: Node.js, Koa