added sqlite connection class (progress)

This commit is contained in:
2023-11-09 19:48:29 +01:00
parent 715f4dff8f
commit 8b5859d858
13 changed files with 227 additions and 25 deletions
+43
View File
@@ -0,0 +1,43 @@
#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
+9 -4
View File
@@ -10,7 +10,7 @@
namespace matador::sql {
class [[nodiscard]] dialect
class dialect
{
public:
enum class token_t : uint8_t
@@ -59,7 +59,15 @@ public:
ESCAPE_CLOSING_BRACKET /**< The escape quotes differ; escape the closing one */
};
using token_to_string_map = std::unordered_map<token_t, std::string>;
using data_type_to_string_map = std::unordered_map<data_type_t, std::string>;
public:
dialect() = default;
dialect(const token_to_string_map &token_replace_map, const data_type_to_string_map &data_type_replace_map);
explicit dialect(const data_type_to_string_map &data_type_replace_map);
explicit dialect(const token_to_string_map &token_replace_map);
const std::string& token_at(token_t token) const;
const std::string& data_type_at(data_type_t type) const;
@@ -124,8 +132,6 @@ public:
const std::vector<std::string>& columns() const;
private:
using token_to_string_map = std::unordered_map<token_t, std::string>;
std::vector<std::string> host_vars_;
std::vector<std::string> columns_;
@@ -167,7 +173,6 @@ private:
{token_t::NONE, ""}
};
using data_type_to_string_map = std::unordered_map<data_type_t, std::string>;
data_type_to_string_map data_types_ {
{data_type_t::type_char, "TINYINT"},
{data_type_t::type_short, "SMALLINT"},
+14
View File
@@ -0,0 +1,14 @@
#ifndef QUERY_OS_HPP
#define QUERY_OS_HPP
#include <string>
namespace matador::utils::os {
std::string getenv(const char* name);
[[maybe_unused]] std::string getenv(const std::string &name);
}
#endif //QUERY_OS_HPP