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.
I have written below code
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) {
});
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?
The first object is the result object, the second is the metadata object (containing affected rows etc) - but in mysql, those two are equal.
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
Try :
sequelizeObj.query("SELECT * FROM `reports` WHERE `id` = 1200", { type: Sequelize.QueryTypes.SELECT }).then(function (result) {
});
Add { type: Sequelize.QueryTypes.SELECT }
as the second argument, also remember to import Sequelize first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With