I'm fairly new to Node.Js and JS in general. I was trying to create a SQL query for a table. After that, I create a separate query to get one/multiple rows from another table that have the same ID (in here LGID) as the row from the first query. Like a JOIN command but I need the results from the second query as a separate object.
I am using the "node-firebird" client.
Everything works, except "the entire code from the second query"
My expected Output would be something like this:
{
"KDNR": "1",
"NUMBER": "+49123456789",
"NAME1": "John",
"NAME2": "Doe,
"STRASSE": "Musterstrasse 38",
"PLZ": "12345",
"ORT": "Musterstadt",
"TEL": "+49123456787",
"TNK": {
{"NAME": "TANK1"},
{"NAME": "TANK2"},
}
}
db.query('SELECT * FROM LG WHERE NAME1 = ?', [req.userData.orga], (err, lgResult) => {
if (err)
throw err;
lgResult.forEach((row) => {
row.KDNR = ab2str(row.KDNR);
row.NUMBER = ab2str(row.NUMBER);
row.NAME1 = ab2str(row.NAME1);
row.NAME2 = ab2str(row.NAME2);
row.STRASSE = ab2str(row.STRASSE);
row.PLZ = ab2str(row.PLZ);
row.ORT = ab2str(row.ORT);
row.TEL = ab2str(row.TEL);
console.log('test');
db.query('SELECT * FROM TNK WHERE LGID = ?', [1], (errN, tnkResult) => {
if (errN)
return res.status(500).json({ error: 'Error queryisssng DB' });
console.log('another test');
row.TNK.push(tnkResult);
});
return res.status(200).json(lgResult);
});
I can see the test multiple times in the console, but not the another test.
I hope this is enough code for you to help.