I have the following code to get me some information from my database:
const getDeviceUID = `SELECT Device_UID FROM Device WHERE ThingName = "${deviceName}"`;
const deviceUIDResult = await new Promise((resolve) => {
connection.query(getDeviceUID, (err, results, fields) => {
if (err) return resolve(false);
resolve(results);
});
});
I'm assuming (I'm pretty new to this!) that deviceUIDResult is now a JSON object as when I do this:
console.log("RES: " + JSON.stringify(deviceUIDResult));
I get the following:
RES: [{"Device_UID":"xxxx-xxxx-xxxx-xxxx"}]
But when I try to parse it:
deviceUIDObj = JSON.parse(deviceUIDResult)
I get this:
SyntaxError: Unexpected token o in JSON at position 1
And when I try to extract my field:
var myField = deviceUIDResult["Device_UID"];
it tells me that its undefined. What am I not understanding here?