关于节点包“squelize”,“dataValues”是什么意思?

1 node.js sequelize.js koa2

我的问题是:

koa2中间件'/info' ctx.res.body ------>front-end get对象没有dataValues和其他值。只有像这样的对象{a:1,b:2}

在中间件中,我发现ser它有很多键值,例如{dataValue:{a:1,b:2},eviousDataValues:'xxx'}

为什么前端Object与ko2中间件中的'ser'不一样?

这是我的代码

let sequelize = new Sequelize('test', sqlOpt.name, sqlOpt.pwd, {
host: sqlOpt.host,
dialect: 'mysql',
port: sqlOpt.port,
pool: {
max: 5000,
min: 0,
idle: 10000
}})
let api = sequelize.define(
'api', {
  id: {
    type: Sequelize.STRING,
    primaryKey: true
  },
  name: Sequelize.STRING,
  method: Sequelize.STRING,
  url: Sequelize.STRING,
  description: Sequelize.STRING,
  createTime: Sequelize.INTEGER,
  did: Sequelize.STRING,
  status: Sequelize.INTEGER,
  content_type: Sequelize.INTEGER
}, {
  freezeTableName: true,
  tableName: 'apilist',
  timestamps: false
})
module.exports = {
searchbyDid(params) {
  return api.findAll({
  where: {
    did: params.id
  }
})}}

router.get('/info', async ctx => {
  let ser = await ser_m.searchAll()
  for (let val of ser) {
    val.dataValues.item = await api_m.searchbyDid({
      id: val.id
    })
  }
  ctx.response.body = ser
})
Run Code Online (Sandbox Code Playgroud)

Shi*_*vam 5

Sequelize 的响应始终是一个模型实例,其形式如下:

{
  dataValues: [//All your data],
  previousDataValues: [//Old Values],
  ... //many more properties
}
Run Code Online (Sandbox Code Playgroud)

如果您不需要实例,只需要数据。您可以在查询中提供一个附加标志,如raw:true。文档可以在这里找到

这样做

Model.A.findAll({where:{/*Some Conditions*/},raw:true})
Run Code Online (Sandbox Code Playgroud)

将仅返回数据作为普通 JS 对象。