mysqlnode.jsnode-webkit

How to access a RowDataPacket object


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.


Solution

  • 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.