Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const map = new Map();
- pool.query(`SELECT * FROM trips WHERE destination = $1 AND begin_time >= $2 AND begin_time < $3 ORDER BY begin_time`, ['BROWNSVILLE ROCKAWAY AV', '2018-07-18 00:00-04:00', '2018-07-19 00:00-04:00'])
- .then(res => {
- return new Promise((resolve, reject) => {
- const { rows } = res;
- resolve(rows);
- });
- })
- .then(res1 => {
- return new Promise((resolve, reject) => {
- for (let i = 0; i < res1.length; i++) {
- if (res1[i + 1]) {
- pool.query(`SELECT * FROM get_hwtable($1, $2)`, [res1[i].trip_id, res1[i + 1].trip_id]).then(res => {
- const { rows: hwRows } = res;
- map.set([res1[i].trip_id, res1[i + 1].trip_id], hwRows);
- }).catch(e => console.log('20', e));
- }
- }
- setTimeout(() => {
- resolve(map);
- }, 8000);
- });
- })
- .catch(e => console.log('25', e))
- .finally(function () {
- console.log(map);
- });
Add Comment
Please, Sign In to add comment