Advertisement
Guest User

Untitled

a guest
May 13th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. 'use strict';
  2.  
  3. const pgp = require('pg-promise')();
  4. const db = pgp({
  5. host: 'localhost',
  6. port: 5432,
  7. database: 'postgres',
  8. user: 'user',
  9. password: 'password',
  10. ssl: false
  11. });
  12. db.connect();
  13.  
  14. const co = require('co');
  15.  
  16. function* waitAndPrint(n) {
  17. return new Promise(function (resolve) {
  18. console.log(n);
  19. setTimeout(resolve, n);
  20. });
  21. }
  22. function* handler() {
  23. const one = yield db.task(function* (t) {
  24. const result = yield t.oneOrNone('SELECT 1 as one');
  25. yield waitAndPrint(1000);
  26. console.log(result.one);
  27. return result.one;
  28. });
  29. console.log(one);
  30. }
  31.  
  32. co(handler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement