postgres: The status field must be present

Like other similar packages (for example, ioredis), postgres needs the status field

Wrapping postgres calls in a try/catch block is expensive for services in cases when the connection is broken and there is an attempt to reconnect

For example, instead of such a code

try {
  return await sql`...`;
} catch(error) {
  return {}
}

we can use much more efficient code while reconnecting is in progress

if (sql.status === postgres.statuses.READY) {
  return await sql`...`;
} else {
  return {};
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

It’s no longer easier to explain - I brought the code!)

wrapping any call in try/catch every time is tedious and clogs up the code.

Look at how it is implemented in redis - it is not necessary to try to call the service if it is unavailable and there is an attempt to connect inside under the hood and you do not want to make an extra call to get an error! The status of the current state of the service would really help

do you think that in redis people suffer from bullshit and came up with the status of the service from nothing to do? 😃

we at redis constantly use status checking and this gives us confidence in the operability of the service without loss in performance as its with try/catch

Well if you are interested in performance, why are you running a service where you don’t expect that your database is available? 🤨

What is it you then do in that catch?

If an error occurs during the call (the error is pushed to the framework level (we use fastify) and the framework processes it), I would assign the connecting status and while under the hood postgres is trying to restore the connection - other requests will not attempt to call sql until the connection is restored and the status is set to ready and so will not generate an exception

Have a look at ioredis - it’s the similar type of library - it has a status field and it’s very useful