initial matador ng commit
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
@@ -20,28 +19,31 @@ private:
|
||||
backend_provider();
|
||||
|
||||
public:
|
||||
struct basic_backend_service {
|
||||
virtual ~basic_backend_service() = default;
|
||||
[[nodiscard]] virtual connection_impl* create(const connection_info&) = 0;
|
||||
virtual void destroy(connection_impl*) = 0;
|
||||
[[nodiscard]] virtual const sql::dialect* dialect() const = 0;
|
||||
};
|
||||
|
||||
static backend_provider& instance();
|
||||
|
||||
connection_impl* create_connection(const std::string &connection_type, const connection_info &info);
|
||||
void destroy_connection(const std::string &connection_type, connection_impl *c);
|
||||
const dialect& connection_dialect(const std::string &connection_type);
|
||||
|
||||
private:
|
||||
struct basic_backend_context {
|
||||
virtual ~basic_backend_context() = default;
|
||||
[[nodiscard]] virtual connection_impl* create(const connection_info&) = 0;
|
||||
virtual void destroy(connection_impl*) = 0;
|
||||
[[nodiscard]] virtual const sql::dialect* dialect() const = 0;
|
||||
};
|
||||
void register_backend(const std::string &connection_type, std::unique_ptr<basic_backend_service> &&service);
|
||||
|
||||
class backend_context final : public basic_backend_context {
|
||||
private:
|
||||
|
||||
class backend_service final : public basic_backend_service {
|
||||
public:
|
||||
explicit backend_context(const std::string &connection_type);
|
||||
backend_context(const backend_context&) = delete;
|
||||
backend_context& operator=(const backend_context&) = delete;
|
||||
backend_context(backend_context&&) noexcept = default;
|
||||
backend_context& operator=(backend_context&&) noexcept = default;
|
||||
~backend_context() override;
|
||||
explicit backend_service(const std::string &connection_type);
|
||||
backend_service(const backend_service&) = delete;
|
||||
backend_service& operator=(const backend_service&) = delete;
|
||||
backend_service(backend_service&&) noexcept = default;
|
||||
backend_service& operator=(backend_service&&) noexcept = default;
|
||||
~backend_service() override;
|
||||
|
||||
[[nodiscard]] connection_impl* create(const connection_info&) override;
|
||||
void destroy(connection_impl *conn) override;
|
||||
@@ -58,18 +60,8 @@ private:
|
||||
utils::library lib;
|
||||
};
|
||||
|
||||
class noop_backend_context final : public basic_backend_context {
|
||||
public:
|
||||
connection_impl *create(const connection_info &info) override;
|
||||
void destroy(connection_impl *impl) override;
|
||||
[[nodiscard]] const sql::dialect *dialect() const override;
|
||||
|
||||
private:
|
||||
std::unordered_set<std::unique_ptr<connection_impl>> noop_connections_;
|
||||
};
|
||||
|
||||
private:
|
||||
using backends_t = std::unordered_map<std::string, std::unique_ptr<basic_backend_context>>;
|
||||
using backends_t = std::unordered_map<std::string, std::unique_ptr<basic_backend_service>>;
|
||||
backends_t backends_;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user