diff --git a/README.md b/README.md index adda1ae..ef5f019 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/index.ts b/src/index.ts index cb121ba..d4df835 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"), @@ -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