How to access a RowDataPacket object

0 votes

I'm currently developing a desktop application with Node-webkit. During that process I need to get some data from a local MySQL-database.

The querying works fine, but I can't figure out how to access the results. I store all of them in an array that is then passed to a function. In the console they look like this:

RowDataPacket {user_id: 101, ActionsPerformed: 20}
RowDataPacket {user_id: 102, ActionsPerformed: 110}
RowDataPacket {user_id: 104, ActionsPerformed: 3}

And here is the query structure:

var ret = [];
conn.query(SQLquery, function(err, rows, fields) {
    if (err)
        alert("...");
    else {
        for (var i of rows) 
            ret.push(i);
    }
    doStuffwithTheResult(ret);
}

How do I retrieve this in the doStuffwithTheResult function? The values are more important, but if I could get the keys as well that would be great.

Oct 14, 2020 in Java-Script by kartik
• 37,510 points
8,345 views

1 answer to this question.

0 votes

Hello @kartik,

Turns out they are normal objects and you can access them through user_id.

RowDataPacket is actually the name of the constructor function that creates an object, it would look like this new RowDataPacket(user_id, ...). You can check by accessing its name [0].constructor.name

If the result is an array, you would have to use [0].user_id.

Hope it works!!

Thank You!!

answered Oct 14, 2020 by Niroj
• 82,880 points

Related Questions In Java-Script

0 votes
1 answer

How to list the properties of a JavaScript object?

Hii @kartik, Use Reflect.ownKeys(): var obj = {a: 1, b: ...READ MORE

answered Jun 8, 2020 in Java-Script by Niroj
• 82,880 points
773 views
0 votes
0 answers

How to access PHP session variables from jQuery function in a .js file?

How to access PHP session variables from ...READ MORE

Jul 7, 2020 in Java-Script by kartik
• 37,510 points
977 views
0 votes
1 answer

How to convert a ruby hash object to JSON?

Hello @kartik, You can also use JSON.generate: require 'json' JSON.generate({ foo: ...READ MORE

answered Jul 24, 2020 in Java-Script by Niroj
• 82,880 points
11,763 views
0 votes
1 answer

How to deserializing a JSON into a JavaScript object?

Hello @kartik, To collect all item of an array ...READ MORE

answered Sep 3, 2020 in Java-Script by Niroj
• 82,880 points
516 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,880 points
3,689 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,880 points
2,898 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,880 points
818 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,880 points
756 views
0 votes
1 answer

How to clone a JavaScript object?

Hello, You can clone an object and remove ...READ MORE

answered Apr 2, 2020 in Java-Script by Niroj
• 82,880 points
637 views
0 votes
1 answer

How to access PHP session variables from jQuery function in a .js file?

Hello, You can produce the javascript file via ...READ MORE

answered Apr 29, 2020 in Java-Script by Niroj
• 82,880 points
12,237 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP