I've implemented a query to retrieve the list of new users from the database. The query is functioning correctly and returning a total of 15 users. However, when I attempt to store the resultset into a JavaScript array, only the last record is being saved.
Here is a snippet of my code:
var query = `SELECT *
FROM users
WHERE (status ='New')`;
var query = connection.query(query),
response = []; // This array will store the results of our database query
query
.on('error', function (err) {
console.log(err);
})
.on('result', function (res) {
// We are populating our array by iterating through each user row in the database
response.push(res);
/*
for (var key in res) {
if (res.hasOwnProperty(key)) response.push(res[key]);
}
*/
})
.on('end', function () {
console.log('console')
});
The line response.push(res);
seems to be causing the issue. I have also experimented with other methods, as shown in the commented lines below that particular line, but none seem to yield the desired outcome.