I'm using the mysql2/promise
package. And here's what I'm doing:
const mysql = require('mysql2/promise');
const dbConnection = await mysql.createConnection({
host: environment.dbUrl,
port: '3306',
user: environment.dbUser,
password: environment.dbPassword,
database: environment.db,
});
return (dbConnection);
const verifications = await dbConnection.execute('SELECT * FROM verifications WHERE code = ?', [code]);
console.log('verifications', verifications);
But the query result is containing a bunch of column descriptions that I don't need. How shall I get rid of them?
[ [],
[ { catalog: 'def',
schema: 'testdb',
name: 'id',
orgName: 'id',
table: 'verifications',
orgTable: 'verifications',
characterSet: 63,
columnLength: 11,
columnType: 3,
flags: 16899,
decimals: 0 },
{ catalog: 'def',
schema: 'testdb',
name: 'code',
orgName: 'code',
table: 'verifications',
orgTable: 'verifications',
characterSet: 63,
columnLength: 11,
columnType: 3,
flags: 4097,
decimals: 0 },
{ catalog: 'def',
schema: 'testdb',
name: 'createdAt',
orgName: 'createdAt',
table: 'verifications',
orgTable: 'verifications',
characterSet: 63,
columnLength: 19,
columnType: 7,
flags: 1152,
decimals: 0 } ] ]
You can just do const [rows, fields]
to get the relevant info
const [rows, fields] = await dbConnection.execute('SELECT * FROM verifications WHERE code = ?', [code]);