|
Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
|
Fluent builder for constructing database connection strings. More...
#include <connection_string_builder.h>

Public Member Functions | |
| connection_string_builder ()=default | |
| ~connection_string_builder ()=default | |
| connection_string_builder (const connection_string_builder &)=default | |
| connection_string_builder & | operator= (const connection_string_builder &)=default |
| connection_string_builder (connection_string_builder &&) noexcept=default | |
| connection_string_builder & | operator= (connection_string_builder &&) noexcept=default |
| connection_string_builder & | host (std::string_view h) |
| Set the database host. | |
| connection_string_builder & | port (uint16_t p) |
| Set the database port. | |
| connection_string_builder & | database (std::string_view db) |
| Set the database name. | |
| connection_string_builder & | user (std::string_view u) |
| Set the username for authentication. | |
| connection_string_builder & | password (std::string_view p) |
| Set the password for authentication. | |
| connection_string_builder & | ssl_mode (enum ssl_mode mode) |
| Set the SSL connection mode. | |
| connection_string_builder & | connect_timeout (uint32_t seconds) |
| Set the connection timeout. | |
| connection_string_builder & | application_name (std::string_view name) |
| Set the application name (for PostgreSQL) | |
| connection_string_builder & | in_memory () |
| Configure SQLite to use in-memory database. | |
| connection_string_builder & | option (std::string_view key, std::string_view value) |
| Add a custom option. | |
| kcenon::common::Result< std::string > | build (backend_type type) const |
| Build the connection string for the specified backend. | |
| connection_string_builder & | reset () |
| Reset the builder to initial state. | |
Private Member Functions | |
| kcenon::common::Result< std::string > | build_postgres () const |
| kcenon::common::Result< std::string > | build_sqlite () const |
| kcenon::common::Result< std::string > | build_mongodb () const |
| kcenon::common::Result< std::string > | build_redis () const |
Static Private Member Functions | |
| static std::string | ssl_mode_to_postgres_string (enum ssl_mode mode) |
Private Attributes | |
| std::optional< std::string > | host_ |
| std::optional< uint16_t > | port_ |
| std::optional< std::string > | database_ |
| std::optional< std::string > | user_ |
| std::optional< std::string > | password_ |
| std::optional< enum ssl_mode > | ssl_mode_ |
| std::optional< uint32_t > | connect_timeout_ |
| std::optional< std::string > | application_name_ |
| bool | in_memory_ = false |
| std::vector< std::pair< std::string, std::string > > | custom_options_ |
Fluent builder for constructing database connection strings.
This class provides a type-safe way to build connection strings for different database backends. It validates required fields per backend and generates properly formatted connection strings.
Thread Safety: This class is not thread-safe. Each thread should use its own builder instance.
Definition at line 76 of file connection_string_builder.h.
|
default |
|
default |
|
default |
|
defaultnoexcept |
| connection_string_builder & database::integrated::connection_string_builder::application_name | ( | std::string_view | name | ) |
Set the application name (for PostgreSQL)
| name | Application name |
Definition at line 46 of file connection_string_builder.cpp.
References application_name_.
Referenced by test_builder_chaining(), and test_postgres_app_name().

|
nodiscard |
Build the connection string for the specified backend.
| type | Database backend type |
Validates that required fields are set for the backend:
Definition at line 61 of file connection_string_builder.cpp.
References build_mongodb(), build_postgres(), build_redis(), build_sqlite(), database::integrated::mongodb, database::integrated::postgres, database::integrated::redis, and database::integrated::sqlite.
Referenced by test_builder_chaining(), test_builder_copy(), test_builder_reset(), test_builder_reuse(), test_mongodb_basic(), test_mongodb_default_host(), test_mongodb_ssl(), test_mongodb_with_auth(), test_postgres_app_name(), test_postgres_basic(), test_postgres_custom_option(), test_postgres_empty(), test_postgres_ssl(), test_postgres_timeout(), test_postgres_verify_ca(), test_redis_basic(), test_redis_with_database(), test_redis_with_password(), test_sqlite_file(), test_sqlite_memory(), test_sqlite_memory_overrides_file(), and test_sqlite_no_database().


|
nodiscardprivate |
Definition at line 158 of file connection_string_builder.cpp.
References connect_timeout_, custom_options_, database_, database::integrated::disable, host_, password_, port_, ssl_mode_, and user_.
Referenced by build().

|
nodiscardprivate |
Definition at line 91 of file connection_string_builder.cpp.
References application_name_, connect_timeout_, custom_options_, database_, host_, password_, port_, ssl_mode_, ssl_mode_to_postgres_string(), and user_.
Referenced by build().


|
nodiscardprivate |
Definition at line 211 of file connection_string_builder.cpp.
References database_, host_, password_, port_, and user_.
Referenced by build().

|
nodiscardprivate |
Definition at line 143 of file connection_string_builder.cpp.
References database_, and in_memory_.
Referenced by build().

| connection_string_builder & database::integrated::connection_string_builder::connect_timeout | ( | uint32_t | seconds | ) |
Set the connection timeout.
| seconds | Timeout in seconds |
Definition at line 41 of file connection_string_builder.cpp.
References connect_timeout_.
Referenced by test_builder_chaining(), and test_postgres_timeout().

| connection_string_builder & database::integrated::connection_string_builder::database | ( | std::string_view | db | ) |
Set the database name.
| db | Database name or file path (for SQLite) |
Definition at line 21 of file connection_string_builder.cpp.
References database_.
Referenced by test_builder_chaining(), test_builder_copy(), test_builder_reset(), test_builder_reuse(), test_mongodb_basic(), test_mongodb_default_host(), test_mongodb_with_auth(), test_postgres_basic(), test_postgres_ssl(), test_redis_with_database(), test_sqlite_file(), and test_sqlite_memory_overrides_file().

| connection_string_builder & database::integrated::connection_string_builder::host | ( | std::string_view | h | ) |
Set the database host.
| h | Hostname or IP address |
Definition at line 11 of file connection_string_builder.cpp.
References host_.
Referenced by test_builder_chaining(), test_builder_copy(), test_builder_reset(), test_builder_reuse(), test_mongodb_basic(), test_mongodb_ssl(), test_mongodb_with_auth(), test_postgres_app_name(), test_postgres_basic(), test_postgres_custom_option(), test_postgres_ssl(), test_postgres_timeout(), test_postgres_verify_ca(), test_redis_basic(), test_redis_with_database(), and test_redis_with_password().

| connection_string_builder & database::integrated::connection_string_builder::in_memory | ( | ) |
Configure SQLite to use in-memory database.
Definition at line 51 of file connection_string_builder.cpp.
References in_memory_.
Referenced by test_sqlite_memory(), and test_sqlite_memory_overrides_file().

|
defaultnoexcept |
|
default |
| connection_string_builder & database::integrated::connection_string_builder::option | ( | std::string_view | key, |
| std::string_view | value ) |
Add a custom option.
| key | Option key |
| value | Option value |
Definition at line 56 of file connection_string_builder.cpp.
References custom_options_.
Referenced by test_builder_chaining(), and test_postgres_custom_option().

| connection_string_builder & database::integrated::connection_string_builder::password | ( | std::string_view | p | ) |
Set the password for authentication.
| p | Password |
Definition at line 31 of file connection_string_builder.cpp.
References password_.
Referenced by test_builder_chaining(), test_builder_reuse(), test_mongodb_with_auth(), test_postgres_basic(), and test_redis_with_password().

| connection_string_builder & database::integrated::connection_string_builder::port | ( | uint16_t | p | ) |
Set the database port.
| p | Port number (1-65535) |
Definition at line 16 of file connection_string_builder.cpp.
References port_.
Referenced by test_builder_chaining(), test_builder_copy(), test_builder_reset(), test_builder_reuse(), test_mongodb_basic(), test_postgres_basic(), and test_redis_basic().

| connection_string_builder & database::integrated::connection_string_builder::reset | ( | ) |
Reset the builder to initial state.
Definition at line 77 of file connection_string_builder.cpp.
References application_name_, connect_timeout_, custom_options_, database_, host_, in_memory_, password_, port_, reset(), ssl_mode_, and user_.
Referenced by reset(), test_builder_reset(), and test_builder_reuse().


| connection_string_builder & database::integrated::connection_string_builder::ssl_mode | ( | enum ssl_mode | mode | ) |
Set the SSL connection mode.
| mode | SSL mode |
Definition at line 36 of file connection_string_builder.cpp.
References ssl_mode_.
Referenced by test_builder_chaining(), test_mongodb_ssl(), test_postgres_ssl(), and test_postgres_verify_ca().

|
staticnodiscardprivate |
Definition at line 241 of file connection_string_builder.cpp.
References database::integrated::allow, database::integrated::disable, database::integrated::prefer, database::integrated::require, database::integrated::verify_ca, and database::integrated::verify_full.
Referenced by build_postgres().

| connection_string_builder & database::integrated::connection_string_builder::user | ( | std::string_view | u | ) |
Set the username for authentication.
| u | Username |
Definition at line 26 of file connection_string_builder.cpp.
References user_.
Referenced by test_builder_chaining(), test_builder_reuse(), test_mongodb_with_auth(), and test_postgres_basic().

|
private |
Definition at line 184 of file connection_string_builder.h.
Referenced by application_name(), build_postgres(), and reset().
|
private |
Definition at line 183 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), connect_timeout(), and reset().
|
private |
Definition at line 186 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), option(), and reset().
|
private |
Definition at line 179 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), build_redis(), build_sqlite(), database(), and reset().
|
private |
Definition at line 177 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), build_redis(), host(), and reset().
|
private |
Definition at line 185 of file connection_string_builder.h.
Referenced by build_sqlite(), in_memory(), and reset().
|
private |
Definition at line 181 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), build_redis(), password(), and reset().
|
private |
Definition at line 178 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), build_redis(), port(), and reset().
|
private |
Definition at line 182 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), reset(), and ssl_mode().
|
private |
Definition at line 180 of file connection_string_builder.h.
Referenced by build_mongodb(), build_postgres(), build_redis(), reset(), and user().