Conversation

komachi

improve example with parsing connection string for pg-pool, use URL constructor, available since node 10

https://developer.mozilla.org/en-US/docs/Web/API/URL/URL

@charmander

I’m not sure why this is documented this way in the first place instead of using the connectionString option…

@usahai

Is there a way to extend the client for pooled connections? I need to use a schema, but the existing type definitions does not accept a schema, unless I pass it in as a part of the URL in the client. However, it's not extensible to pooled connections.

So this is fine for client -

const client: ClientConfig = new Client(
  process.env.DB_URL,
  //   {
  //   host: process.env.DB_HOST,
  //   port: process.env.DB_PORT as unknown as number,
  //   database: process.env.DB_DATABASE,
  //   user: process.env.DB_USER,
  //   password: process.env.DB_PASSWORD,
  // }
)

And I was thinking maybe if there was a provision to do something like this -

const pool: Pool = new Pool({
  ...client,
  max: 20,
  idleTimeoutMillis: 60000,
  connectionTimeoutMillis: 20000,
})

wherein the URL will get deconstructed on it's own (overly hopeful, I know)
OR

const pool: Pool = new Pool(client, {
  max: 20,
  idleTimeoutMillis: 60000,
  connectionTimeoutMillis: 20000,
})

where the additional parameters get attached to the Pool object.

@charmander

@usahai As I mentioned in the previous comment, use the connectionString pool option to pass a connection string.

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.