Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

395
Views
How to check for node-postgres if no results

I am confused what exactly node-postgres postgres database returned if no records ?

try {
  const {
    rows: [user]
  } = await pool.query(`SELECT * FROM "users" WHERE username = $1 LIMIT 1`, [
    username
  ]);

  console.log('user', user);

  if (!user || typeof username !== 'undefined') return false;

  return await bcrypt.compare(password, user.password);
} catch (e) {
  console.log(e);
}

How to check if there is no user result

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

For a SELECT query, the pg.Result rows is an empty array [] with rows.length === 0

The rowCount === 0 as well but this can be different in an INSERT/UPDATE query where it becomes the updated rows.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!