-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using pool and native #1061
using pool and native #1061
Conversation
Have you tried? 😄 |
let Pg = require('pg').Pool.native ? |
let Pg = require('pg').native.Pool |
Was close, thanks |
Whoah I am surprised that worked actually! Haha. I am gonna need to make that API nicer or at least documented so I'm gonna reopen this until I get it documented right. 😊 |
A suggestion, it is quite important for developers to understand that when switching over to the new pool, and continue being able to restore a database connection they have to change from |
Update documentation Verbiage
452ff5d
to
b1642f5
Compare
@Brakkar Your question actually helped me uncover a bug with the pool. I also spent some time updating the readme to make it clearer how to consume the pool, both here as well as on pg-pool itself! Thanks! @vitaly-t you're right about that...I'll add some more documentation on error handling to pg-pool! |
@brianc just so since you seem to have some time now to improve your libraries, I wanted to point at things that would make a very worthwhile improvement...
|
@brianc thanks for update, documentation is much better indeed. Glad I could help. I put var pool = new pg.Pool(config); in exported function like this:
Is this bad practice ? Will pool get reinitialized each time processSqlPgQuery is called ? Should I put let dbPool = new pg.Pool( settings.dbConfig ) in top of the file ? |
@Brakkar - yeah that's bad practice. If you instantiate more than 1 pool during the lifetime of your application you're likely leaking resources & creating an unbounded number of clients to postgres. I added some instructions around that here https://github.com/brianc/node-pg-pool#a-note-on-instances |
@vitaly-t pg-query-stream will likely never support native bindings. libpq doesn't expose streaming primitives in a way that libuv or node can easily consume, and the questionable level of performance gain which may or may not present itself is definitely not worth the massive amount of time it will take. If you wanna use query streams, you gotta use the JavaScript implementation. As far as making native bindings have the same |
Thanks Bryan.
|
Correctamundo. Just make sure you don't call On Fri, Jun 24, 2016 at 11:22 AM, Benj notifications@github.com wrote:
|
This gets awfully more complicated for any reusable library. Where previously we could just use one global pool, now we have to figure out how to associate a pool with a database/connection config. When a client wants to connect, it passes in a connection config. Now the library has to decide - do I need to create a new pool object for this config, or do I need to reuse an existing one? I can only guess that perhaps it would have to parse the connection first (which previously wasn't required), and then look at such parameters as For example, it shouldn't create multiple pools when those parameters are the same, but As I said, it gets quite complicated. I have spent many hours at this point trying upgrade |
@brianc what we need now, is a pool factory, something that could take a connection string/object, and either return a new pool object or an existing one, plus an indication of whether it is a new pool. The factory would parse the connection to figure out whether it represents a new physical connection to be created, or if there is already a pool that represents such a physical connection. Perhaps the main reason why developers always wanted to have a separate pool is to have one pool per physical channel. But with the current library we are missing one important piece - to be able to tell when a connection string/object represents a unique physical channel. Yeah, we need a pool factory. |
With a pool factory we'd be in the same bad spot we've been in for years Basically dependency injection instead of a globally mutateable singleton. I realize this causes a public API change for other modules, but it's the On Friday, June 24, 2016, Vitaly Tomilov notifications@github.com wrote:
|
But then where would you place the logic that can offer a separate pool per database server? This is what developers really want. |
I would imagine a developer having separate database servers would configure two pools: var pool1 = new pg.Pool({
database: 'db-1'
})
var pool2 = new pg.Pool({
database: 'db-2'
})
var db1 = new PGPromise(pool1)
var db2 = new PGPromise(pool2) Something like that - then they're able to bootstrap, configure, tweak |
Hi, the syntax for using pg native is:
What if I want to use this with
is there a way to have Pool work in native ?