Hi there! Is there any way to retrieve database connection options from pgp instance? For example something like this:
const pgp = require('pg-promise')();
const db = pgp(connection);
db.$config.connection
Not presently.
And nobody ever asked about it before. I'm not sure about its value though, considering that you are passing the connection into the database object yourself anyway.
Do you have a special use-case that would need it?
I agree, but it makes sense if you make a reusable library which accepts db as a parameter and needs information about connection itself. We can pass the connection object into the library too, though.
if you make reusable library wich accepts db as a parameter and needs information about connection itself
Valid point, marking it as a feature request.
Great! I think that it wouldn't be hard to implement. Maybe I can make a PR for this?
No worries, I will implement it soon. Will require tests + documentation updates, so I better do it myself ;)
On second thought thought, it cannot be something like db.$config.connection, because $config represents the state of the initialized library, and there can be multiple db objects, all using the same $config object.
Currently, I'm thinking something like db.$cn, perhaps...
That makes sense.
Implemented in v5.6.8. See the release notes for details.
In version 6.x of the library, Database also exposes property $pool, which represents the connection pool used by the object.