Hi,
I have enrolled in web development with nodejs and while going through sequlelize query section
The output for complex queries is not working as expected
Case 1 : simple query
Code :
const {db , Student} = require('./model2')
const task = async () =>{
await db.sync()
const students = await Student.findAll({
where : {age : 13},
})
students.forEach(student => {
console.log(`
Name : ${student.dataValues.name} Age : ${student.dataValues.age}
`)
});
}
task();
Ouput - status - Working and displaying as expected
Executing (default): CREATE TABLE IF NOT EXISTS `students` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(40) NOT NULL, `age` INTEGER(2) NOT NULL DEFAULT -1, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `students`
Executing (default): SELECT `id`, `name`, `age`, `createdAt`, `updatedAt` FROM `students` AS `students` WHERE `students`.`age` = 13;
Name : Shammi Age : 13
Name : Vishesh Age : 13
But while using complex queries i.m getting object object as output
Case 2 : Nested / Complex Query
const {db , Student} = require('./model2')
const task = async () =>{
await db.sync()
const students = await Student.findAll({
where : {
age: { $or:{ $lt: 12, $gt: 18}}},
order:[
['age' ,'DESC']
]
})
students.forEach(student => {
console.log(`
Name : ${student.dataValues.name} Age : ${student.dataValues.age}
`)
});
}
task();
Output status : Not working as expected showing [object] [object ] as below
Executing (default): CREATE TABLE IF NOT EXISTS
students
(id
INTEGER NOT NULL auto_increment ,name
VARCHAR(40) NOT NULL,age
INTEGER(2) NOT NULL DEFAULT -1,createdAt
DATETIME NOT NULL,updatedAt
DATETIME NOT NULL, PRIMARY KEY (id
)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROMstudents
Executing (default): SELECTid
,name
,age
,createdAt
,updatedAt
FROMstudents
ASstudents
WHEREstudents
.age
= ‘[object Object]’ ORDER BYstudents
.age
DESC;
Please help me solve this.