Hello. I have a small suggestion.
I find myself doing this many times:
const ssl = !!process.env.SSL
const connectionOptions = {
url: 'postgresql://...',
...ssl && { extra: { ssl: true } }
}
It works but feels a bit intimidating. I think there could be a better alternative:
const ssl = !!process.env.SSL
const connectionOptions = {
url: 'postgresql://...',
extra: ssl ? { ssl: true }
}
It is similar to the ternary operator in purpose.
When ssl
is true, the result would be:
{ url: 'postgresql://...', extra: { ssl: true } }
When ssl
is false, the result would be:
{ url: 'postgresql://...' }
We could also allow a shorter version if the value we want is equal to the condition result:
const cert = fs.writeFileSync(...)
const connectionOptions = {
url: 'postgresql://...',
ssl: cert?
}
When ssl
is true (would work for any truthy value), the result would be:
{ url: 'postgresql://...', ssl: <cert-content> }
When ssl
is a falsy value, the result would be:
{ url: 'postgresql://...' }