testcontainers-cpp 0.2.0
Native C++20 Testcontainers over the Docker Engine API
Loading...
Searching...
No Matches
testcontainers::ConnectionString Class Reference

Assembles a connection URL — scheme://[user[:password]@]host[:port][/database][?key=value&...] — percent-encoding every component that needs it. More...

#include <testcontainers/ConnectionString.hpp>

Public Member Functions

 ConnectionString (std::string scheme)
ConnectionStringwith_user (std::string user)
ConnectionStringwith_password (std::string password)
ConnectionStringwith_host (std::string host)
ConnectionStringwith_port (std::uint16_t port)
ConnectionStringwith_database (std::string database)
 The path segment after the host — the database name for the typical DB DSN (also e.g.
ConnectionStringwith_param (std::string key, std::string value)
 Append one key=value query parameter (repeatable; order kept).
std::string to_string () const
 Render the URL from the components set so far.

Detailed Description

Assembles a connection URL — scheme://[user[:password]@]host[:port][/database][?key=value&...] — percent-encoding every component that needs it.

The building block for module connection getters (postgresql://user:pass@localhost:5432/db), usable on its own for any URL-shaped DSN.

Components stay out of the URL until set: no user/password → no userinfo "@", no port → no ":port", no database → no path, no params → no "?". user / password / database / parameter keys and values are percent-encoded (RFC 3986 unreserved characters pass through), so credentials with '@', ':' or '/' survive verbatim; the database is one path segment (a '/' inside it is encoded, not a separator). The scheme is emitted as given; so is the host, except an IPv6 literal, which is bracketed automatically. Parameters keep their insertion order.

Constructor & Destructor Documentation

◆ ConnectionString()

testcontainers::ConnectionString::ConnectionString ( std::string scheme)
inlineexplicit

Member Function Documentation

◆ with_user()

ConnectionString & testcontainers::ConnectionString::with_user ( std::string user)
inline

◆ with_password()

ConnectionString & testcontainers::ConnectionString::with_password ( std::string password)
inline

◆ with_host()

ConnectionString & testcontainers::ConnectionString::with_host ( std::string host)
inline

◆ with_port()

ConnectionString & testcontainers::ConnectionString::with_port ( std::uint16_t port)
inline

◆ with_database()

ConnectionString & testcontainers::ConnectionString::with_database ( std::string database)
inline

The path segment after the host — the database name for the typical DB DSN (also e.g.

an AMQP vhost or a Redis database index).

◆ with_param()

ConnectionString & testcontainers::ConnectionString::with_param ( std::string key,
std::string value )
inline

Append one key=value query parameter (repeatable; order kept).

◆ to_string()

std::string testcontainers::ConnectionString::to_string ( ) const

Render the URL from the components set so far.