|
Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
|
Manages PostgreSQL database operations. More...
#include <postgres_manager.h>


Public Member Functions | |
| postgres_manager (void) | |
| Default constructor. | |
| virtual | ~postgres_manager (void) |
| Destructor. | |
| database_types | type () const override |
| Returns the specific type of the database. | |
| kcenon::common::VoidResult | initialize (const core::connection_config &config) override |
| Initialize the database backend. | |
| kcenon::common::VoidResult | shutdown () override |
| Shutdown the database backend gracefully. | |
| bool | is_initialized () const override |
| Check if backend is initialized and ready. | |
| kcenon::common::Result< core::database_result > | select_query (const std::string &query_string) override |
| Executes a SELECT query on the connected PostgreSQL database and returns the resulting data. | |
| kcenon::common::VoidResult | execute_query (const std::string &query_string) override |
| Executes a general SQL query (DDL, DML) on PostgreSQL. | |
| kcenon::common::VoidResult | begin_transaction () override |
| Begin a transaction. | |
| kcenon::common::VoidResult | commit_transaction () override |
| Commit the current transaction. | |
| kcenon::common::VoidResult | rollback_transaction () override |
| Rollback the current transaction. | |
| bool | in_transaction () const override |
| Check if backend is currently in a transaction. | |
| std::string | last_error () const override |
| Get last error message from backend. | |
| std::map< std::string, std::string > | connection_info () const override |
| Get backend-specific connection information. | |
Public Member Functions inherited from database::core::database_backend | |
| virtual | ~database_backend ()=default |
| virtual kcenon::common::Result< database_result > | select_prepared (const std::string &query, const std::vector< database_value > ¶ms) |
| Execute a parameterized SELECT query (prepared statement) | |
| virtual kcenon::common::VoidResult | execute_prepared (const std::string &query, const std::vector< database_value > ¶ms) |
| Execute a parameterized DML/DDL query (prepared statement) | |
Private Member Functions | |
| kcenon::common::Result< uint64_t > | execute_modification_query (const std::string &query_string) |
| Common implementation for INSERT, UPDATE, and DELETE queries. | |
Private Attributes | |
| void * | connection_ |
| Pointer to the underlying PostgreSQL connection object. | |
| bool | initialized_ |
| Whether the backend is initialized. | |
| bool | in_transaction_ |
| Whether a transaction is active. | |
| std::string | last_error_ |
| Last error message. | |
| std::string | connection_string_ |
| Connection string for connection_info. | |
Additional Inherited Members | |
Static Protected Member Functions inherited from database::core::database_backend | |
| static std::string | expand_params (const std::string &query, const std::vector< database_value > ¶ms) |
| Expand positional parameters into a SQL string (fallback) | |
Manages PostgreSQL database operations.
This class provides an implementation of the database_backend interface for PostgreSQL databases. It defines methods for connecting, querying, and disconnecting from a PostgreSQL database.
Definition at line 19 of file postgres_manager.h.
| database::postgres_manager::postgres_manager | ( | void | ) |
Default constructor.
Definition at line 37 of file postgres_manager.cpp.
|
virtual |
Destructor.
Definition at line 44 of file postgres_manager.cpp.
References shutdown().

|
overridevirtual |
Begin a transaction.
Implements database::core::database_backend.
Definition at line 347 of file postgres_manager.cpp.
References execute_query(), in_transaction_, and initialized_.

|
overridevirtual |
Commit the current transaction.
Implements database::core::database_backend.
Definition at line 364 of file postgres_manager.cpp.
References execute_query(), in_transaction_, and initialized_.

|
overridevirtual |
Get backend-specific connection information.
Implements database::core::database_backend.
Definition at line 408 of file postgres_manager.cpp.
References connection_, in_transaction_, and initialized_.
|
private |
Common implementation for INSERT, UPDATE, and DELETE queries.
| query_string | The SQL query to be executed. |
Definition at line 162 of file postgres_manager.cpp.
References connection_, initialized_, last_error_, POSTGRES_LOG_ERROR, and POSTGRES_LOG_WARNING.
|
overridevirtual |
Executes a general SQL query (DDL, DML) on PostgreSQL.
| query_string | The SQL query string to execute. |
Implements database::core::database_backend.
Definition at line 304 of file postgres_manager.cpp.
References connection_, initialized_, last_error_, POSTGRES_LOG_ERROR, POSTGRES_LOG_INFO, and database::success.
Referenced by begin_transaction(), commit_transaction(), and rollback_transaction().

|
overridevirtual |
Check if backend is currently in a transaction.
Implements database::core::database_backend.
Definition at line 398 of file postgres_manager.cpp.
References in_transaction_.
|
overridevirtual |
Initialize the database backend.
| config | Connection configuration |
Implements database::core::database_backend.
Definition at line 54 of file postgres_manager.cpp.
References connection_, connection_string_, database::core::connection_config::database, database::core::connection_config::host, initialized_, last_error_, database::core::connection_config::options, database::core::connection_config::password, database::core::connection_config::port, POSTGRES_LOG_ERROR, POSTGRES_LOG_WARNING, and database::core::connection_config::username.
|
overridevirtual |
Check if backend is initialized and ready.
Implements database::core::database_backend.
Definition at line 157 of file postgres_manager.cpp.
References initialized_.
|
overridevirtual |
Get last error message from backend.
Implements database::core::database_backend.
Definition at line 403 of file postgres_manager.cpp.
References last_error_.
|
overridevirtual |
Rollback the current transaction.
Implements database::core::database_backend.
Definition at line 381 of file postgres_manager.cpp.
References execute_query(), in_transaction_, and initialized_.
Referenced by shutdown().


|
overridevirtual |
Executes a SELECT query on the connected PostgreSQL database and returns the resulting data.
| query_string | The SQL SELECT query to be executed. |
Implements database::core::database_backend.
Definition at line 206 of file postgres_manager.cpp.
References connection_, initialized_, last_error_, POSTGRES_LOG_ERROR, POSTGRES_LOG_WARNING, and type().

|
overridevirtual |
Shutdown the database backend gracefully.
Implements database::core::database_backend.
Definition at line 118 of file postgres_manager.cpp.
References connection_, in_transaction_, initialized_, last_error_, POSTGRES_LOG_ERROR, POSTGRES_LOG_WARNING, and rollback_transaction().
Referenced by ~postgres_manager().


|
overridevirtual |
Returns the specific type of the database.
database_types indicating that this is a PostgreSQL database. Implements database::core::database_backend.
Definition at line 49 of file postgres_manager.cpp.
References database::postgres.
Referenced by select_query().

|
private |
Pointer to the underlying PostgreSQL connection object.
Definition at line 122 of file postgres_manager.h.
Referenced by connection_info(), execute_modification_query(), execute_query(), initialize(), select_query(), and shutdown().
|
private |
Connection string for connection_info.
Definition at line 126 of file postgres_manager.h.
Referenced by initialize().
|
private |
Whether a transaction is active.
Definition at line 124 of file postgres_manager.h.
Referenced by begin_transaction(), commit_transaction(), connection_info(), in_transaction(), rollback_transaction(), and shutdown().
|
private |
Whether the backend is initialized.
Definition at line 123 of file postgres_manager.h.
Referenced by begin_transaction(), commit_transaction(), connection_info(), execute_modification_query(), execute_query(), initialize(), is_initialized(), rollback_transaction(), select_query(), and shutdown().
|
private |
Last error message.
Definition at line 125 of file postgres_manager.h.
Referenced by execute_modification_query(), execute_query(), initialize(), last_error(), select_query(), and shutdown().