Guest User

Untitled

a guest
Jul 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. const map = new Map();
  2. 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'])
  3. .then(res => {
  4. return new Promise((resolve, reject) => {
  5. const { rows } = res;
  6. resolve(rows);
  7. });
  8. })
  9. .then(res1 => {
  10. return new Promise((resolve, reject) => {
  11. for (let i = 0; i < res1.length; i++) {
  12. if (res1[i + 1]) {
  13. pool.query(`SELECT * FROM get_hwtable($1, $2)`, [res1[i].trip_id, res1[i + 1].trip_id]).then(res => {
  14. const { rows: hwRows } = res;
  15. map.set([res1[i].trip_id, res1[i + 1].trip_id], hwRows);
  16. }).catch(e => console.log('20', e));
  17. }
  18. }
  19. setTimeout(() => {
  20. resolve(map);
  21. }, 8000);
  22. });
  23. })
  24. .catch(e => console.log('25', e))
  25. .finally(function () {
  26. console.log(map);
  27. });
Add Comment
Please, Sign In to add comment