A running PostgreSQL server: connection getters plus the owned container.
More...
#include <testcontainers/modules/PostgreSQL.hpp>
|
| const std::string & | host () const noexcept |
| | The address a client in the test process connects to.
|
| std::uint16_t | port () const noexcept |
| | The host port published for the server port 5432.
|
| const std::string & | username () const noexcept |
| const std::string & | password () const noexcept |
| const std::string & | database () const noexcept |
| std::string | connection_string () const |
| | URI-form DSN, postgresql://user[:password]@host:port/database, every component percent-encoded — paste into PQconnectdb / pqxx::connection.
|
| std::string | connection_string_with_scheme (const std::string &scheme) const |
| | The same DSN under a different scheme, for polyglot consumers ("postgres" for Go-style tools, "postgresql+psycopg" for SQLAlchemy, ...).
|
| std::string | conninfo () const |
| | libpq keyword/value form of the same DSN: host=... port=...
dbname=... user=... password=..., values quoted per libpq rules (the password keyword is omitted when empty).
|
| ExecResult | exec_sql (const std::string &sql) const |
| | Run one SQL command through the in-container psql (psql -v ON_ERROR_STOP=1 -X -tA -U <user> -d <db> -c <sql>) — a zero-dependency seed/assert helper.
|
| Container & | container () noexcept |
| | The underlying container handle: exec, read logs, copy files, stop() early, keep() it past the test.
|
| const Container & | container () const noexcept |
A running PostgreSQL server: connection getters plus the owned container.
Move-only — it owns the core Container, whose destructor force-removes the server (RAII teardown; container().keep() or reuse opt out, see Container).
◆ host()
| const std::string & testcontainers::modules::PostgreSQLContainer::host |
( |
| ) |
const |
|
inlinenoexcept |
The address a client in the test process connects to.
Resolved once, when the container started.
◆ port()
| std::uint16_t testcontainers::modules::PostgreSQLContainer::port |
( |
| ) |
const |
|
inlinenoexcept |
The host port published for the server port 5432.
Resolved once, when the container started; a container restarted by hand gets fresh ephemeral ports — re-resolve via container() then.
◆ username()
| const std::string & testcontainers::modules::PostgreSQLContainer::username |
( |
| ) |
const |
|
inlinenoexcept |
◆ password()
| const std::string & testcontainers::modules::PostgreSQLContainer::password |
( |
| ) |
const |
|
inlinenoexcept |
◆ database()
| const std::string & testcontainers::modules::PostgreSQLContainer::database |
( |
| ) |
const |
|
inlinenoexcept |
◆ connection_string()
| std::string testcontainers::modules::PostgreSQLContainer::connection_string |
( |
| ) |
const |
|
inline |
URI-form DSN, postgresql://user[:password]@host:port/database, every component percent-encoded — paste into PQconnectdb / pqxx::connection.
For extra query parameters (sslmode=disable and friends), rebuild with ConnectionString and the discrete getters.
This DSN is host-side: a SIBLING CONTAINER on a shared network dials <alias>:5432 (PostgreSQLImage::kPort) instead — build that DSN with ConnectionString, your alias, and kPort.
◆ connection_string_with_scheme()
| std::string testcontainers::modules::PostgreSQLContainer::connection_string_with_scheme |
( |
const std::string & | scheme | ) |
const |
The same DSN under a different scheme, for polyglot consumers ("postgres" for Go-style tools, "postgresql+psycopg" for SQLAlchemy, ...).
The scheme has its own method name — not a connection_string parameter — so it cannot be mistaken for the DATABASE argument that connection_string(...) takes in other modules.
◆ conninfo()
| std::string testcontainers::modules::PostgreSQLContainer::conninfo |
( |
| ) |
const |
libpq keyword/value form of the same DSN: host=... port=...
dbname=... user=... password=..., values quoted per libpq rules (the password keyword is omitted when empty).
Equivalent input to PQconnectdb and friends — take whichever form your code base prefers.
◆ exec_sql()
| ExecResult testcontainers::modules::PostgreSQLContainer::exec_sql |
( |
const std::string & | sql | ) |
const |
Run one SQL command through the in-container psql (psql -v ON_ERROR_STOP=1 -X -tA -U <user> -d <db> -c <sql>) — a zero-dependency seed/assert helper.
Output is unaligned tuples-only: one row per line, columns '|'-separated, no headers. Runs over the container-local socket (no password needed). A failing statement is reported via the result's exit_code/stderr_data, not thrown.
◆ container() [1/2]
| Container & testcontainers::modules::PostgreSQLContainer::container |
( |
| ) |
|
|
inlinenoexcept |
The underlying container handle: exec, read logs, copy files, stop() early, keep() it past the test.
◆ container() [2/2]
| const Container & testcontainers::modules::PostgreSQLContainer::container |
( |
| ) |
const |
|
inlinenoexcept |
◆ PostgreSQLImage
| friend class PostgreSQLImage |
|
friend |