#include "matador/sql/backend_provider.hpp" #include #include #include namespace matador::sql { backend_provider::backend_provider(std::string backends_path) : backends_path_(std::move(backends_path)) {} connection_impl *backend_provider::create_connection(const std::string &connection_type) { auto it = backends_.find(connection_type); if (it == backends_.end()) { it = backends_.emplace(connection_type, backend_context{connection_type, backends_path_}).first; } return (*it->second.create_connection)(); } const dialect &backend_provider::connection_dialect(const std::string &connection_type) { auto it = backends_.find(connection_type); if (it == backends_.end()) { it = backends_.emplace(connection_type, backend_context{connection_type, backends_path_}).first; } return *(*it->second.get_dialect)(); } backend_provider::backend_context::backend_context(const std::string &connection_type, const std::string &backends_path) { if (!lib.load(backends_path + "matador-" + connection_type)) { throw std::runtime_error("couldn't load library '" + connection_type + "'"); } create_connection = reinterpret_cast(reinterpret_cast(lib.function("create_database"))); destroy_connection = reinterpret_cast(reinterpret_cast(lib.function("destroy_database"))); get_dialect = reinterpret_cast(reinterpret_cast(lib.function("get_dialect"))); } backend_provider::backend_context::~backend_context() { lib.unload(); } }