Skip to content

Commit

Permalink
Merge pull request #11 from well-known-components/feat/connection-string
Browse files Browse the repository at this point in the history
feat: support a connection string
  • Loading branch information
nicosantangelo authored Jun 7, 2022
2 parents abcbff6 + ca5b0a2 commit 49c7229
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ It supports the following ENV variables:

First everything related with connecting to [Postgres](https://www.postgresql.org/):

- `PG_COMPONENT_PSQL_CONNECTION_STRING`
- `PG_COMPONENT_PSQL_PORT`
- `PG_COMPONENT_PSQL_HOST`
- `PG_COMPONENT_PSQL_DATABASE`
- `PG_COMPONENT_PSQL_USER`
- `PG_COMPONENT_PSQL_PASSWORD`

You'll probably use either the CONNECTION_STRING **or** the other params and not both.

Then the variables related to [Postgres](https://www.postgresql.org/)'s query timeouts:

- `PG_COMPONENT_IDLE_TIMEOUT`
Expand Down
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export async function createPgComponent(
const logger = logs.getLogger("pg-component")

// Environment
const [port, host, database, user, password, idleTimeoutMillis, query_timeout] = await Promise.all([
const [connectionString, port, host, database, user, password, idleTimeoutMillis, query_timeout] = await Promise.all([
config.getString("PG_COMPONENT_PSQL_CONNECTION_STRING"),
config.getNumber("PG_COMPONENT_PSQL_PORT"),
config.getString("PG_COMPONENT_PSQL_HOST"),
config.getString("PG_COMPONENT_PSQL_DATABASE"),
Expand All @@ -31,7 +32,16 @@ export async function createPgComponent(
config.getNumber("PG_COMPONENT_IDLE_TIMEOUT"),
config.getNumber("PG_COMPONENT_QUERY_TIMEOUT"),
])
const defaultOptions = { port, host, database, user, password, idleTimeoutMillis, query_timeout }
const defaultOptions: PoolConfig = {
connectionString,
port,
host,
database,
user,
password,
idleTimeoutMillis,
query_timeout,
}

const STREAM_QUERY_TIMEOUT = await config.getNumber("PG_COMPONENT_STREAM_QUERY_TIMEOUT")
const GRACE_PERIODS = (await config.getNumber("PG_COMPONENT_GRACE_PERIODS")) || 10
Expand Down

0 comments on commit 49c7229

Please sign in to comment.