I'm working on a script that insert and reads information on a mysql database. I've done the first step which is create registers on the database and works but I'm having issues reading the data out from the database.
I have a main.ts that call all the functions that performs the select/insert statements and a dao.ts with all the funtions that interact with the database.
This is the code where I call the function:
const vehiclesDB = select('SELECT * FROM vehicles', con);
console.log(vehiclesDB);
This is always returning undefined.
And this is the code that performs the sql statement:
export const select = (statement: string, dbConnection: any) => {
const results = dbConnection.query(statement, function (err, res, fields) {
if (err) throw err;
return res;
});
return results;
}
If I do a console.log on the res variable inside the select function I can see the result rows. I've tryed setting the results variable as return from the select function but what I can see on the main.ts then is the db connection details.
This is the library I'm working with to interact with mysql through node: https://github.com/mysqljs/mysql