0

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.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Cyclom
  • 23
  • 1
  • 6
  • you do not describe the behaviour of your code, what you expected to see and what you actually saw. You also did not give sample data in your tables. – Arioch 'The Sep 24 '20 at 11:27
  • Also specify which node.js Firebird driver you're using, as far as I know there are at least 2 of them (maybe more). – Mark Rotteveel Sep 24 '20 at 11:31

0 Answers0