Is it a way to get all data from a database?
So far I accomplished to get all data from a table:
router.get('/', function (req, res, next) {
db.serialize(function () {
db.all('SELECT id, name, surname FROM Table1', function (
err,
rows
) {
return res.send(rows);
});
});
db.close();
});
but if there are more tables, Table1, Table2 and Table3 for example.
Trying to put all the queries in the db.all call doesn't seem to work.
router.get('/', function (req, res, next) {
db.serialize(function () {
db.all('SELECT id, name, surname FROM Table1, SELECT date, city FROM Table2, SELECT person, year FROM Table3', function (
err,
rows
) {
return res.send(rows);
});
});
db.close();
});
UPDATE
these are the tables, how can I get all their data and send it into front-end? that's what I want to do.
I would rather want to have them like separate tables in the front-end where the call is fetched like this:
callAPI() {
fetch('http://localhost:9000/testAPI')
.then((res) => res.text())
.then((res) => this.setState({ apiResponse: res }));
}
is there a way to send all these tables?




function(){}portion of the previous. Your'e doing that correctly if your code keeps indenting to the right. Call res.send only in the last one... That only helps if you have only a few tables and know how the queries in advance. If you want to ask the database for the table list, and then act on it, it gets more complex. Specifically, you need a way to iterate asynchronously. You can do that and avoid nesting callbacks using node'sasynclibrary or perhapsPromise.allif your framework understands promises.Promise.allworks fine. I updated the question with the tables, I don't understand why isn't it working. Sending one table is working fine but sending them all doesn't work