client.query returns undefined
using the example from the documentation:
// promise
client.query('SELECT NOW() as now')
.then(res => console.log(res.rows[0]))
.catch(e => console.error(e.stack))
fails with: TypeError: Uncaught error: Cannot read property 'then' of undefined.
query no longer can return a Promise?
It should – can you show the complete script you’re testing with, please?
const pg = require('pg')
const client = new pg.Client({
....
})
client.connect().then(() => {
console.log('db is running OK')
client.query('SELECT NOW() as now')
.then(res => console.log(res.rows[0]))
.catch(e => console.error(e.stack))
}).catch(e => console.error(e.stack)
node 8.8.1, pg 7.4.0, aarch64 arch linux 3.10 kernel
That will throw a ReferenceError on new Client. Please show the exact contents of the script.
What version do you have installed?
On Sat, Nov 18, 2017 at 9:11 AM Silur [email protected] wrote:
using the example from the documentation:
// promiseclient.query('SELECT NOW() as now') .then(res => console.log(res.rows[0])) .catch(e => console.error(e.stack))
fails with: TypeError: Uncaught error: Cannot read property 'then' of undefined. query no longer can return a Promise?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/brianc/node-postgres/issues/1509, or mute the thread https://github.com/notifications/unsubscribe-auth/AADDob53v71t0kLgtv3ieHNm-EoD_J57ks5s3vOOgaJpZM4QjCDB .
Closing as we haven't heard anything back.
Can we reopen this?
const pool =
new Pool ({ max: 1
, min: 0
, idleTimeoutMillis: 120000
, connectionTimeoutMillis: 10000
});
exports.testRDS = epsagon.lambdaWrapper (async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
const client = await pool.connect ().catch (err => console.log ({ err }));
console.log ({ client }); //=> Prints a Client object with { ..., readyForQuery: true }
try {
const results = await client.query ('SELECT NOW()');
console.log ({ results }); //=> Prints { results: undefined }
} finally {
client.release (true);
}
});
I got this from: https://gist.github.com/streamich/6175853840fb5209388405910c6cc04b
"pg": "^7.12.1"
@miwillhite That’s strange. Can you get a stack trace?
await new Promise(resolve => {
client.query('SELECT NOW()', (err, results) => {
console.log({ err, results });
console.log(new Error().stack);
resolve();
});
});
Making sure it still happens without epsagon.lambdaWrapper would also be helpful.
@miwillhite (Note that this is a new issue unless client.query ('SELECT NOW()') === undefined is also true without the await.)
@charmander This works fine without the epsagon.lambdaWrapper, sorry for the noise!