Created an interface for the Db class

This commit is contained in:
emeric
2025-07-09 00:29:16 +02:00
parent ecdfa8d68d
commit 764c92698c
106 changed files with 315 additions and 284 deletions
+79
View File
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2019 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <mutex>
#include <vector>
#include <Wt/Dbo/SqlConnectionPool.h>
#include "core/RecursiveSharedMutex.hpp"
#include "database/IDb.hpp"
namespace lms::db
{
class Db : public IDb
{
public:
Db(const std::filesystem::path& dbPath, std::size_t connectionCount);
Session& getTLSSession() override;
void executeSql(const std::string& sql) override;
private:
Db(const Db&) = delete;
Db& operator=(const Db&) = delete;
friend class Session;
core::RecursiveSharedMutex& getMutex() { return _sharedMutex; }
Wt::Dbo::SqlConnectionPool& getConnectionPool() { return *_connectionPool; }
void performQuickCheck();
void performIntegrityCheck();
void performForeignKeyConstraintsCheck();
class ScopedConnection
{
public:
ScopedConnection(Wt::Dbo::SqlConnectionPool& pool);
~ScopedConnection();
Wt::Dbo::SqlConnection* operator->() const;
Wt::Dbo::SqlConnection& operator*() const { return *_connection; }
private:
ScopedConnection(const ScopedConnection&) = delete;
ScopedConnection& operator=(const ScopedConnection&) = delete;
Wt::Dbo::SqlConnectionPool& _connectionPool;
std::unique_ptr<Wt::Dbo::SqlConnection> _connection;
};
core::RecursiveSharedMutex _sharedMutex;
std::unique_ptr<Wt::Dbo::SqlConnectionPool> _connectionPool;
std::mutex _tlsSessionsMutex;
std::vector<std::unique_ptr<Session>> _tlsSessions;
};
} // namespace lms::db