node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

client.query returns undefined

Open Silur opened this issue 9 years ago • 10 comments

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?

Silur avatar Nov 18 '17 15:11 Silur

It should – can you show the complete script you’re testing with, please?

charmander avatar Nov 18 '17 16:11 charmander

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)

Silur avatar Nov 18 '17 16:11 Silur

node 8.8.1, pg 7.4.0, aarch64 arch linux 3.10 kernel

Silur avatar Nov 18 '17 16:11 Silur

That will throw a ReferenceError on new Client. Please show the exact contents of the script.

charmander avatar Nov 18 '17 17:11 charmander

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 .

brianc avatar Nov 18 '17 21:11 brianc

Closing as we haven't heard anything back.

brianc avatar Dec 04 '17 04:12 brianc

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 avatar Nov 10 '19 12:11 miwillhite

@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.

charmander avatar Nov 11 '19 04:11 charmander

@miwillhite (Note that this is a new issue unless client.query ('SELECT NOW()') === undefined is also true without the await.)

charmander avatar Nov 11 '19 04:11 charmander

@charmander This works fine without the epsagon.lambdaWrapper, sorry for the noise!

miwillhite avatar Nov 11 '19 10:11 miwillhite