In my NodeJS app I need to make a query to Postgres and then I need to make GET request for every row in the PG result. And return all GET results in an array.
What's wrong with my code?
var promise = require('bluebird');
var pgp = require('pg-promise')({ promiseLib: promise });
var db = pgp(connectionString);
var rp = require('request-promise');
var query = 'select id from my_table';
var processIDs = pgResults => {
var requests = pgResults.map( row => rp(`mysite.com/${row.id}`) );
return promise.all(requests);
}
db.any(query)
.then(processIDs)
.then( results => console.log(results) );
The second question, how to include IDs from PG query in the final result array?