Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const pgp = require('pg-promise')();
- const db = pgp({
- host: 'localhost',
- port: 5432,
- database: 'postgres',
- user: 'user',
- password: 'password',
- ssl: false
- });
- db.connect();
- const co = require('co');
- function* waitAndPrint(n) {
- return new Promise(function (resolve) {
- console.log(n);
- setTimeout(resolve, n);
- });
- }
- function* handler() {
- const one = yield db.task(function* (t) {
- const result = yield t.oneOrNone('SELECT 1 as one');
- yield waitAndPrint(1000);
- console.log(result.one);
- return result.one;
- });
- console.log(one);
- }
- co(handler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement