gpt4 book ai didi

node.js - 关于 Node 包 'squelize' , 'dataValues' 是什么意思?

转载 作者:行者123 更新时间:2023-12-03 22:17:57 25 4
gpt4 key购买 nike

我的问题是:

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
})

最佳答案

来自 Sequelize 的响应始终是一个模型实例,其形式为。

{
dataValues: [//All your data],
previousDataValues: [//Old Values],
... //many more properties
}

如果您不需要实例,而只需要数据。您可以在查询中提供一个额外的标志作为 raw:true 。文档可用 here

这样做
Model.A.findAll({where:{/*Some Conditions*/},raw:true})

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

关于node.js - 关于 Node 包 'squelize' , 'dataValues' 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44753699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com