Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise { <pending> } #1130

Closed
tnsupport opened this issue Sep 16, 2016 · 5 comments
Closed

Promise { <pending> } #1130

tnsupport opened this issue Sep 16, 2016 · 5 comments

Comments

@tnsupport
Copy link

we added a new query in some existing code and now get an error:

// ---from model.js
var pg = require('pg');
var jwt = require('jsonwebtoken');
var bcrypt = require('bcrypt');
var Pool = require('pg').Pool;

var connectString = {user:"xxx", password:"xxx",
host:"localhost", database:"xxx"};
var pool = new Pool(connectString);
var exports = module.exports = {};

exports.signupsInactiveList = function() {
var data = pool.query("select * from signups");
return data;
}

// ---from test.js script:
var res = model.signupsInactiveList();
console.log(res);

all that is returned is the following:
Promise { }

since we are not specifying any promises, don't know where this is coming from except maybe in the node v6.5 or in the pg pooling - any ideas ?

@joskuijpers
Copy link
Contributor

Pool.query returns a promise. You will need to wait for it to fulfill before printing the result.

Model.signupInactiveList().then((data) => console.log(data))```

> On Sep 16, 2016, at 5:24 PM, tnsupport <notifications@github.com> wrote:
> 
> we added a new query in some existing code and now get an error:
> 
> // ---from model.js
> var pg = require('pg');
> var jwt = require('jsonwebtoken');
> var bcrypt = require('bcrypt');
> var Pool = require('pg').Pool;
> 
> var connectString = {user:"xxx", password:"xxx",
> host:"localhost", database:"xxx"};
> var pool = new Pool(connectString);
> var exports = module.exports = {};
> 
> exports.signupsInactiveList = function() {
> var data = pool.query("select * from signups");
> return data;
> }
> 
> // ---from test.js script:
> var res = model.signupsInactiveList();
> console.log(res);
> 
> all that is returned is the following: 
> Promise { }
> 
> since we are not specifying any promises, don't know where this is coming from except maybe in the node v6.5 or in the pg pooling - any ideas ?
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.
> 

@felixfbecker
Copy link

This is not 100% correct. query() returns a Query object, which is an EventEmitter, but also implements a Promise interface (aka Thenable).

@menasheh
Copy link

I'm having this same problem now. How do you get it to wait for the query to fill exactly?

@felixfbecker
Copy link

Either pass a callback as the last parameter to query() or attach a handler with .then() on the return value

@joskuijpers
Copy link
Contributor

WHat @felixfbecker said. Either use a callback (and use a callback in signupsInactiveList), use Promises and return a promise, or use async/await.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants