How to access RowDataPacket mysql-node.js

connection.query('
SET @update_id := 0; 
UPDATE relations set x1 = ?, y1 = ?, id = (SELECT @update_id := id) WHERE element_to =?;
SELECT @update_id;',[data.x2,data.y2,id],function(err,result){
if(err){console.error(err);}
else{console.log(result);console.log(result.@update_id);}
});

I get the following result from the query:

[ RowDataPacket {
  '@update_id': 'WAbWA1WA5WA2WA8WAdWA4WA9' } ] ]

How do I access the @update_id field to store the value in a variable. I know these are objects, and I tried the following to access them, for example:

results.@update_id; 

But I get undefined when I try to write a value. How to get the cost?

+7
source share
2 answers

Try the following:

results[0].@update_id
+16
source

use console.log(JSON.stringify(result));

then if you want to access variable data

var data = JSON.stringify(result[0].@update_id)
console.log(data);

You cannot use an index on EG

console.log(data[0].@update_id) wrong

0
source

All Articles