Short of writing your own additional function(s) and passing the row
object through them your desired result format is not possible based on the design of the mysqljs/mysql
package. In a standard SELECT
query the result is always an object.
There is a bit of a hack workaround by using the stream
function. Below is an example, but you will still end up with more lines of code than you would if you simply accessed the value via rows[0].name
in a standard query.
let the_query = con.query('SELECT name FROM members WHERE id = 1;');
the_query
.on('result', function(row) {
console.log('row.name:', row.name);
// expected in log:
// row.name: John
})
.on('end', function() {
// this chained event can be excluded
// here for demo purposes
console.log('all done');
});