Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::core::connection_config Struct Reference

Configuration for database connection. More...

#include <database_backend.h>

Collaboration diagram for database::core::connection_config:
Collaboration graph

Static Public Member Functions

static connection_config from_string (const std::string &connect_string)
 Construct connection_config from legacy connection string.
 

Public Attributes

std::string host
 
uint16_t port = 0
 
std::string database
 
std::string username
 
std::string password
 
std::map< std::string, std::string > options
 

Detailed Description

Configuration for database connection.

Provides a structured way to pass connection parameters to backends, replacing raw connection strings with typed configuration.

Definition at line 50 of file database_backend.h.

Member Function Documentation

◆ from_string()

connection_config database::core::connection_config::from_string ( const std::string & connect_string)
static

Construct connection_config from legacy connection string.

Parameters
connect_stringConnection string (format depends on backend)
Returns
Parsed connection configuration

Note: Parsing logic is backend-specific. This is a utility for backward compatibility.

Examples
/home/runner/work/database_system/database_system/database/async/async_operations.h.

Definition at line 15 of file database_backend.cpp.

16{
17 connection_config config;
18
19 // Parse connection string in key=value format
20 // Example: "host=localhost port=5432 dbname=testdb user=postgres password=secret"
21
22 std::istringstream stream(connect_string);
23 std::string token;
24
25 while (stream >> token)
26 {
27 // Find '=' separator
28 size_t pos = token.find('=');
29 if (pos == std::string::npos)
30 {
31 continue; // Skip malformed tokens
32 }
33
34 std::string key = token.substr(0, pos);
35 std::string value = token.substr(pos + 1);
36
37 // Remove quotes if present
38 if (!value.empty() && value.front() == '\'' && value.back() == '\'')
39 {
40 value = value.substr(1, value.length() - 2);
41 }
42
43 // Map common keys to config fields
44 if (key == "host" || key == "hostname")
45 {
46 config.host = value;
47 }
48 else if (key == "port")
49 {
50 try
51 {
52 config.port = static_cast<uint16_t>(std::stoi(value));
53 }
54 catch (...)
55 {
56 // Invalid port, use default
57 }
58 }
59 else if (key == "database" || key == "dbname" || key == "db")
60 {
61 config.database = value;
62 }
63 else if (key == "user" || key == "username")
64 {
65 config.username = value;
66 }
67 else if (key == "password" || key == "pass" || key == "pwd")
68 {
69 config.password = value;
70 }
71 else
72 {
73 // Store other options
74 config.options[key] = value;
75 }
76 }
77
78 return config;
79}

References database, host, options, password, port, and username.

Referenced by database::integrated::unified_database_system::impl::connect(), database::async::async_database::connect_async(), database::database_manager::connect_result(), and main().

Here is the caller graph for this function:

Member Data Documentation

◆ database

◆ host

◆ options

◆ password

◆ port

◆ username


The documentation for this struct was generated from the following files: