I'm trying my best to understand nodeJS/typescript and it techniques. But still can't figure out how I can save my databasequery result into a variable and return it. Maybe someone can explain me the problem / help me:
I have a method like this:
public getAllProducts(): ProductArray {
// returns IConnection from "mysql" and connect
this.databaseConnection.getConnection().connect();
var product: any = [];
this.databaseConnection.getConnection().query('SELECT * FROM product', function (error: any, results:any, fields:any) {
if (error) throw error;
product.push(results);
});
console.log(product);
return product;
}
Would be nice if someone can help me out here.