sequelize.query() 两次返回相同的结果 [英] sequelize.query() returns same result twice
问题描述
我正在使用 sequelize
连接 mysql 数据库的 nodejs 项目中工作.我还使用 sequelize-values 从 Sequelize 实例中获取原始数据.
I am working in nodejs project in that using sequelize
for connecting mysql database. I am also using sequelize-values for getting raw data from Sequelize instances.
我已经写了下面的代码
var Sequelize = require('sequelize');
require('sequelize-values')(Sequelize);
var sequelizeObj = new Sequelize('mysql://root:@localhost/database');
sequelizeObj.authenticate().then(function (errors) {
console.log(errors)
});
sequelizeObj.query("SELECT * FROM `reports` WHERE `id` = 1200").then(function (result) {
});
现在reports
表只有1条记录id
1200,但是result
给出了相同记录的两个对象,意味着两条记录都是与 id 1200 相同.
Now the table reports
have only 1 record for id
1200, But the result
gives two objects for same records, Means both records are same of id 1200.
[ [ { id: 1200,
productivity_id: 9969,
gross_percentage_points: 100 } ],
[ { id: 1200,
productivity_id: 9969,
gross_percentage_points: 100 } ] ]
让我知道我做错了什么?
Let me know what I am doing wrong?
推荐答案
第一个对象是结果对象,第二个是元数据对象(包含受影响的行等) - 但在 mysql 中,这两者是相等的.
The first object is the result object, the second is the metadata object (containing affected rows etc) - but in mysql, those two are equal.
传递 { type: Sequelize.QueryTypes.SELECT }
作为第二个参数会给你一个结果对象(元数据对象省略
Passing { type: Sequelize.QueryTypes.SELECT }
as the second argument will give you a single result object (metadata object omitted
https://github.com/sequelize/sequelize/wiki/Upgrading-to-2.0#changes-to-raw-query
这篇关于sequelize.query() 两次返回相同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!