49#include <StormByte/logger/log.hxx>
50#include <StormByte/safe/pointers.hxx>
51#include <StormByte/size.hxx>
193 template <
typename... Args>
201 telemetry.Complete(result.has_value(), result ?
static_cast<std::uint64_t
>(result->Count()) : std::uint64_t{0});
326 void PrepareSTMT(std::string_view name, std::string_view query)
noexcept;
354 void LockOperation() const noexcept;
359 void UnlockOperation() const noexcept;
365 struct PreparedStatements;
367 StormByte::
Safe::Unique<PreparedStatements> m_prepared_stmts;
RAII ownership of the connection operation gate.
Definition database.hxx:86
OperationGuard(const Database &database) noexcept
Acquire the connection operation gate.
OperationGuard(const OperationGuard &other)=delete
Copying a lock guard is disabled.
~OperationGuard() noexcept
Release the connection operation gate.
void SslMode(StormByte::Database::SslMode mode) noexcept
TLS policy for the next Connect().
Definition database.hxx:172
virtual void DoPostConnect() noexcept
Post-connect hook.
Definition database.hxx:294
Expected< Transaction, TransactionError > BeginTransaction(IsolationLevel level=IsolationLevel::Default)
Begin a transaction.
virtual void DoPreConnect() noexcept
Pre-connect hook.
Definition database.hxx:283
virtual void DoPreDisconnect() noexcept
Pre-disconnect hook.
Definition database.hxx:299
StormByte::Safe::Shared< OperationMutex > m_operation_mutex
Base-heap owner of the private reentrant operation gate.
Definition database.hxx:238
void ClearPreparedSTMTs() noexcept
Destroy all registered statements inside the Database module.
StormByte::Safe::Shared< class Telemetry > Telemetry() const noexcept
Obtain the cumulative connection telemetry handle.
virtual void DoBeginTransaction(IsolationLevel level)=0
Backend BEGIN with isolation.
StormByte::Database::Telemetry::OperationScope TrackOperation(Operation operation) const noexcept
Start timing a Database operation without invoking user callbacks.
Definition database.hxx:260
Database(const StormByte::Safe::Shared< Logger::Log > &logger)
Construct with an optional logger.
void DoPrepareSTMT(std::string_view name, std::string_view query) noexcept
Same as PrepareSTMT; kept for hook symmetry.
void RecordBackendEvent(BackendEvent event) noexcept
Record a categorized event reported by the active backend.
Definition database.hxx:251
virtual void DoDisconnect() noexcept=0
Backend disconnect.
friend class Transaction
Definition database.hxx:237
void Disconnect() noexcept
Disconnect.
virtual ExpectedRows Query(std::string_view query)=0
Execute a query that returns rows.
StormByte::Safe::Shared< class Telemetry > m_telemetry
Shared cumulative counters for this connection.
Definition database.hxx:239
virtual bool SilentQuery(std::string_view query) noexcept=0
Execute a query that does not return rows.
void Telemetry(StormByte::Safe::Shared< class Telemetry > telemetry) noexcept
Replace the telemetry implementation, normally in a concrete backend constructor.
void PrepareSTMT(std::string_view name, std::string_view query) noexcept
Register a prepared statement under name.
void CommitTransaction()
Commit the current transaction.
void RollbackTransaction()
Roll back the current transaction.
ExpectedRows ExecuteSTMT(std::string_view name, Args &&...args)
Execute a prepared statement by name.
Definition database.hxx:194
virtual void DoPostDisconnect() noexcept
Post-disconnect hook.
Definition database.hxx:309
StormByte::Safe::Shared< Logger::Log > m_logger
Shared logger, safe across the DLL boundary.
Definition database.hxx:267
virtual bool DoSilentQuery(std::string_view query) noexcept=0
Backend silent query.
StormByte::Database::SslMode m_ssl_mode
TLS policy for network backends.
Definition database.hxx:265
bool m_connected
Connection state.
Definition database.hxx:264
virtual StormByte::Safe::Unique< PreparedSTMT > CreatePreparedSTMT(std::string_view name, std::string_view query) noexcept=0
Create a backend prepared statement.
bool Connect() noexcept
Connect.
bool IsConnected() const noexcept
Whether the connection is open.
Definition database.hxx:163
virtual bool DoConnect() noexcept=0
Backend connect.
StormByte::Database::SslMode SslMode() const noexcept
Current TLS policy.
Definition database.hxx:181
Abstract prepared statement.
Definition prepared_stmt.hxx:69
ExpectedRows Execute(Args &&...args)
Bind arguments and execute.
Definition prepared_stmt.hxx:121
Records one operation and its elapsed time on destruction.
Definition telemetry.hxx:136
Prepared statement name is not registered.
Definition exception.hxx:414
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Logger::Exception)
Database module of the StormByte suite.
BackendEvent
Shared error and warning categories for backend-specific telemetry.
Definition telemetry.hxx:88
SslMode
TLS policy for MariaDB / PostgreSQL.
Definition typedefs.hxx:87
Expected< Rows, QueryException > ExpectedRows
Query result: Rows or QueryException.
Definition typedefs.hxx:81
Operation
Database operation categories measured by telemetry.
Definition telemetry.hxx:71
@ PreparedStatement
Prepared-statement execution attempts.
Definition telemetry.hxx:77
IsolationLevel
Isolation for BeginTransaction().
Definition typedefs.hxx:98
@ Default
Backend default.
Definition typedefs.hxx:99
Root namespace of the StormByte C++ suite.
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, Safe::Shared< E > >, std::expected< T, Safe::Shared< E > > > Expected
auto Unexpected(Safe::Shared< E > error)
#define STORMBYTE_DATABASE_PUBLIC
Definition visibility.h:54