added sqlite connection class (progress)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
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<create_func>(reinterpret_cast<std::uintptr_t>(lib.function("create_database")));
|
||||
destroy_connection = reinterpret_cast<destroy_func>(reinterpret_cast<std::uintptr_t>(lib.function("destroy_database")));
|
||||
get_dialect = reinterpret_cast<dialect_func >(reinterpret_cast<std::uintptr_t>(lib.function("get_dialect")));
|
||||
}
|
||||
|
||||
backend_provider::backend_context::~backend_context()
|
||||
{
|
||||
lib.unload();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,26 @@
|
||||
#include "matador/utils/string.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
dialect::dialect(const dialect::token_to_string_map &token_replace_map, const dialect::data_type_to_string_map &data_type_replace_map)
|
||||
{
|
||||
for (const auto &token : token_replace_map) {
|
||||
tokens_[token.first] = token.second;
|
||||
}
|
||||
|
||||
for (const auto &data_type : data_type_replace_map) {
|
||||
data_types_[data_type.first] = data_type.second;
|
||||
}
|
||||
}
|
||||
|
||||
dialect::dialect(const dialect::data_type_to_string_map &data_type_replace_map)
|
||||
: dialect({}, data_type_replace_map)
|
||||
{}
|
||||
|
||||
dialect::dialect(const dialect::token_to_string_map &token_replace_map)
|
||||
: dialect(token_replace_map, {})
|
||||
{}
|
||||
|
||||
const std::string& dialect::token_at(dialect::token_t token) const
|
||||
{
|
||||
return tokens_.at(token);
|
||||
|
||||
Reference in New Issue
Block a user