Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
configuration.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
31#pragma once
32
33#include <chrono>
34#include <cstddef>
35#include <cstdint>
36#include <string>
37
38namespace database
39{
40namespace integrated
41{
42
49enum class db_log_level
50{
51 trace,
52 debug,
53 info,
54 warning,
55 error,
56 critical,
57 fatal
58};
59
65enum class backend_type
66{
67 postgres,
68 sqlite,
69 mongodb,
70 redis
71};
72
79{
80 standard,
81 typed
82};
83
91{
93 std::string pool_name{ "default_pool" };
94
96 std::size_t min_connections{ 2 };
97
99 std::size_t max_connections{ 10 };
100
102 std::chrono::seconds connection_timeout{ 30 };
103
105 std::chrono::seconds idle_timeout{ 300 }; // 5 minutes
106
109
111 std::chrono::seconds health_check_interval{ 60 };
112
115};
116
123{
125 std::string pool_name{ "db_thread_pool" };
126
128 std::size_t thread_count{ 0 };
129
131 std::size_t max_queue_size{ 1000 };
132
135
138};
139
147{
149 bool enable_query_logging{ false };
150
153
155 bool log_slow_queries{ true };
156
158 std::chrono::milliseconds slow_query_threshold{ 1000 }; // 1 second
159
162
164 bool enable_file_logging{ false };
165
167 std::string log_directory{ "./logs" };
168
170 std::size_t log_rotation_size{ 10 * 1024 * 1024 }; // 10 MB
171
173 std::size_t log_rotation_count{ 5 };
174};
175
183{
185 bool enable_metrics{ true };
186
188 bool enable_profiling{ false };
189
192
194 std::chrono::seconds metrics_interval{ 60 };
195
198
200 std::chrono::milliseconds query_latency_warning{ 500 };
201
204
206 std::string prometheus_endpoint{ "/metrics" };
207
209 std::uint16_t prometheus_port{ 9090 };
210};
211
218{
221
223 std::string connection_string{ "host=localhost port=5432 dbname=postgres" };
224
226 bool enable_ssl{ false };
227
229 std::string ssl_cert_path{};
230
232 std::string ssl_key_path{};
233
236
238 bool enable_query_cache{ false };
239
241 std::size_t query_cache_size{ 100 * 1024 * 1024 }; // 100 MB
242
244 std::string username{};
245
247 std::string password{};
248};
249
270{
273
276
279
282
285
286 // Integration flags (compile-time configurable via CMake)
289
292
295
296 // Builder pattern methods for fluent API
297
304 unified_db_config& set_backend(backend_type type, const std::string& connection_str)
305 {
306 database.type = type;
307 database.connection_string = connection_str;
308 return *this;
309 }
310
317 unified_db_config& set_credentials(const std::string& user, const std::string& pass)
318 {
319 database.username = user;
320 database.password = pass;
321 return *this;
322 }
323
330 unified_db_config& set_pool_size(std::size_t min, std::size_t max)
331 {
334 return *this;
335 }
336
342 unified_db_config& set_pool_name(const std::string& name)
343 {
345 return *this;
346 }
347
354 {
355 logger.min_log_level = level;
356 return *this;
357 }
358
365 {
367 return *this;
368 }
369
377 bool enable = true, std::chrono::milliseconds threshold = std::chrono::milliseconds(1000))
378 {
379 logger.log_slow_queries = enable;
380 logger.slow_query_threshold = threshold;
381 return *this;
382 }
383
390 unified_db_config& enable_file_logging(bool enable = true, const std::string& directory = "./logs")
391 {
393 logger.log_directory = directory;
394 return *this;
395 }
396
403 {
404 monitoring.enable_metrics = enable;
406 return *this;
407 }
408
417 bool enable = true, std::uint16_t port = 9090, const std::string& endpoint = "/metrics")
418 {
422 return *this;
423 }
424
431 {
432 thread.thread_count = count;
433 return *this;
434 }
435
442 {
445 if (enable)
446 {
448 }
449 return *this;
450 }
451
459 unified_db_config& enable_ssl(bool enable = true, const std::string& cert_path = "",
460 const std::string& key_path = "")
461 {
462 database.enable_ssl = enable;
463 database.ssl_cert_path = cert_path;
464 database.ssl_key_path = key_path;
465 return *this;
466 }
467
474 unified_db_config& set_timeouts(std::chrono::seconds acquisition, std::chrono::seconds idle)
475 {
478 return *this;
479 }
480};
481
482} // namespace integrated
483} // namespace database
db_log_level
Database logging level enumeration.
@ trace
Most verbose, includes all operations.
@ critical
Critical failures requiring immediate attention.
@ debug
Debug information for development.
@ info
Informational messages (default)
@ fatal
Fatal errors causing system shutdown.
thread_pool_type
Thread pool implementation type.
@ typed
Typed thread pool with priority support.
@ standard
Standard thread pool (default)
backend_type
Database backend type enumeration.
@ mongodb
MongoDB NoSQL database.
@ sqlite
SQLite embedded database.
@ redis
Redis key-value store.
@ postgres
PostgreSQL database.
Database-specific configuration.
bool enable_prepared_statements
Enable prepared statement caching.
std::string ssl_key_path
Path to SSL key file.
std::size_t query_cache_size
Maximum size of query cache in bytes.
std::string password
Database password (stored in memory - consider using secrets management)
bool enable_query_cache
Enable query result caching.
std::string ssl_cert_path
Path to SSL certificate file.
bool enable_ssl
Enable SSL/TLS for database connections.
std::string connection_string
Connection string (format depends on backend)
backend_type type
Database backend type.
std::string username
Database username.
bool enable_query_logging
Log all SQL queries executed.
bool enable_file_logging
Enable logging to file (in addition to console)
std::string log_directory
Directory for log files.
std::size_t log_rotation_size
Log file rotation size in bytes (0 = no rotation)
std::chrono::milliseconds slow_query_threshold
Threshold for considering a query "slow".
bool enable_connection_logging
Log connection pool events (acquire, release, etc.)
bool log_slow_queries
Automatically detect and log slow queries.
std::size_t log_rotation_count
Number of rotated log files to keep.
db_log_level min_log_level
Minimum log level to output.
Monitoring and metrics configuration.
bool enable_prometheus_export
Enable Prometheus metrics export.
std::uint16_t prometheus_port
Port for Prometheus metrics server.
bool enable_profiling
Enable performance profiling.
bool enable_metrics
Enable metrics collection.
std::chrono::seconds metrics_interval
Interval for collecting metrics.
std::chrono::milliseconds query_latency_warning
Warn when query latency exceeds this threshold.
bool enable_health_checks
Enable health check endpoints.
double connection_usage_warning_threshold
Warn when connection pool usage exceeds this percentage (0.0-1.0)
std::string prometheus_endpoint
HTTP endpoint for Prometheus scraping.
Thread pool configuration for async operations.
thread_pool_type pool_type
Thread pool implementation type.
std::string pool_name
Name for this thread pool (for logging and monitoring)
bool enable_priority_scheduling
Enable priority-based task scheduling.
std::size_t max_queue_size
Maximum queued tasks (0 = unlimited)
std::size_t thread_count
Number of worker threads (0 = auto-detect from hardware)
Connection pool configuration.
std::string pool_name
Unique name for this pool (for logging and monitoring)
std::chrono::seconds health_check_interval
Interval between health checks.
std::size_t min_connections
Minimum number of connections to maintain.
std::chrono::seconds connection_timeout
Timeout for acquiring a connection from the pool.
std::chrono::seconds idle_timeout
Time before an idle connection is closed.
bool enable_health_checks
Enable periodic health checks on connections.
std::size_t max_connections
Maximum number of connections allowed.
bool enable_priority_queue
Enable priority-based connection acquisition.
unified_db_config & enable_slow_query_logging(bool enable=true, std::chrono::milliseconds threshold=std::chrono::milliseconds(1000))
Configure slow query detection.
unified_db_config & set_timeouts(std::chrono::seconds acquisition, std::chrono::seconds idle)
Set connection timeouts.
unified_db_config & set_pool_size(std::size_t min, std::size_t max)
Configure connection pool size.
unified_db_config & set_backend(backend_type type, const std::string &connection_str)
Set database backend type and connection string.
db_logger_config logger
Logger configuration.
unified_db_config & set_credentials(const std::string &user, const std::string &pass)
Set database credentials.
unified_db_config & enable_ssl(bool enable=true, const std::string &cert_path="", const std::string &key_path="")
Enable SSL/TLS for database connections.
unified_db_config & enable_monitoring(bool enable=true)
Enable/disable monitoring.
unified_db_config & set_thread_count(std::size_t count)
Set thread pool size.
unified_db_config & enable_prometheus(bool enable=true, std::uint16_t port=9090, const std::string &endpoint="/metrics")
Configure Prometheus metrics export.
pool_config connection_pool
Connection pool configuration.
unified_db_config & set_pool_name(const std::string &name)
Set connection pool name.
unified_db_config & set_log_level(db_log_level level)
Set minimum logging level.
unified_db_config & enable_priority_scheduling(bool enable=true)
Enable priority-based scheduling.
bool enable_thread_system_integration
Enable thread_system integration (typed thread pools)
db_monitoring_config monitoring
Monitoring configuration.
bool enable_monitoring_system_integration
Enable monitoring_system integration.
unified_db_config & enable_file_logging(bool enable=true, const std::string &directory="./logs")
Enable file logging.
unified_db_config & enable_query_logging(bool enable=true)
Enable/disable query logging.
bool enable_common_system_integration
Enable common_system integration (Result pattern, ILogger, LOG_* macros)
db_thread_config thread
Thread pool configuration.
database_config database
Database connection configuration.