Skip to content

Home > @opengovsg/testcontainers > getPostgresConnectionString

getPostgresConnectionString() function ​

Build a Postgres connection string from container info. Credentials are read back from configuration.environment; database overrides the DB name (the confetti per-run randomUUID() pattern).

By default the URL targets the mapped **host** port, for connecting from the test process. Pass internal: true for the container-internal address (localhost:5432) needed by commands run *inside* the container, e.g. pg_dump/pg_restore via StartedTestContainer.exec.

Signature:

typescript
getPostgresConnectionString: (container: ContainerInformation, options?: {
    database?: string;
    internal?: boolean;
}) => string

Parameters ​

ParameterTypeDescription
containerContainerInformation
options{ database?: string; internal?: boolean; }(Optional)

Returns:

string