query/include/matador/sql/backend_provider.hpp

44 lines
1.1 KiB
C++

#ifndef QUERY_BACKEND_PROVIDER_HPP
#define QUERY_BACKEND_PROVIDER_HPP
#include "matador/utils/library.hpp"
#include <string>
#include <unordered_map>
namespace matador::sql {
class connection_impl;
class dialect;
class backend_provider
{
public:
explicit backend_provider(std::string backends_path);
connection_impl* create_connection(const std::string &connection_type);
const dialect& connection_dialect(const std::string &connection_type);
private:
struct backend_context {
backend_context(const std::string &connection_type,
const std::string &backends_path);
~backend_context();
typedef connection_impl*(*create_func)();
typedef void (*destroy_func)(connection_impl*);
typedef const dialect*(*dialect_func)();
create_func create_connection{};
destroy_func destroy_connection{};
dialect_func get_dialect{};
utils::library lib;
};
private:
using backends_t = std::unordered_map<std::string, backend_context>;
backends_t backends_;
std::string backends_path_;
};
}
#endif //QUERY_BACKEND_PROVIDER_HPP