brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

Add interface to generic-pool getters #61

Closed lenemson closed 7 years ago

lenemson commented 7 years ago

If one needs to access pool state (total size, available objects and in use objects) it has to access the genericPool getters like this:

const Pool = require('pg-pool');

const pool = new Pool();

const size = pool.pool.getPoolSize();
const available = pool.pool.availableObjetcsCount();
const borrowed = pool.pool.inUseObjectsCount();

While it works it is a bit risky cause pool.pool is an internal generic-pool 2.4.3 instance thus we have no control to when generic-pool will be updated and when the api will break, and it will break because generic-pool 3's getters has been renamed.

So I suggest with this PR to add pg-pool getters that wrap generic-pool getters in order to safely access the pool state, When pg-pool will update his version of 'generic-pool' we will just need to update the pg-pool getters to use the new names of the generic-pool getters and it will be transparent with no breaking changes for the users.

sibedge commented 7 years ago

This PR could be part of it: https://github.com/brianc/node-pg-pool/pull/59

as it does the same, specifically for one flag.

brianc commented 7 years ago

generic pool has been removed as a dependency, so all the getters are now directly on pool and anything documented is considered part of the public API and wont be changing between major versions. So...yay! 💃

If you or your company benefit from node-postgres and have the means, please consider supporting my work on Patreon.