added sqlite db backend progress
This commit is contained in:
@@ -1,35 +1,51 @@
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
|
||||
#include "matador/utils/os.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace matador::sql {
|
||||
backend_provider::backend_provider(std::string backends_path)
|
||||
: backends_path_(std::move(backends_path)) {}
|
||||
backend_provider::backend_provider()
|
||||
: backends_path_(utils::os::getenv("MATADOR_BACKENDS_PATH"))
|
||||
{}
|
||||
|
||||
connection_impl *backend_provider::create_connection(const std::string &connection_type)
|
||||
backend_provider &backend_provider::instance() {
|
||||
static backend_provider provider;
|
||||
return provider;
|
||||
}
|
||||
|
||||
connection_impl *backend_provider::create_connection(const std::string &connection_type, const connection_info &info)
|
||||
{
|
||||
auto it = backends_.find(connection_type);
|
||||
if (it == backends_.end()) {
|
||||
it = backends_.emplace(connection_type, backend_context{connection_type, backends_path_}).first;
|
||||
it = backends_.emplace(connection_type, std::make_unique<backend_context>(connection_type, backends_path_)).first;
|
||||
}
|
||||
return (*it->second.create_connection)();
|
||||
return (*it->second->create_connection)(info);
|
||||
}
|
||||
|
||||
void backend_provider::destroy_connection(const std::string &connection_type, connection_impl *c)
|
||||
{
|
||||
auto it = backends_.find(connection_type);
|
||||
if (it == backends_.end()) {
|
||||
it = backends_.emplace(connection_type, std::make_unique<backend_context>(connection_type, backends_path_)).first;
|
||||
}
|
||||
(*it->second->destroy_connection)(c);
|
||||
}
|
||||
|
||||
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;
|
||||
it = backends_.emplace(connection_type, std::make_unique<backend_context>(connection_type, backends_path_)).first;
|
||||
}
|
||||
return *(*it->second.get_dialect)();
|
||||
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)) {
|
||||
if (!lib.load("matador-" + connection_type)) {
|
||||
throw std::runtime_error("couldn't load library '" + connection_type + "'");
|
||||
}
|
||||
|
||||
|
||||
+28
-9
@@ -1,30 +1,49 @@
|
||||
#include <utility>
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
#include "matador/sql/connection_impl.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
connection::connection(std::string dns)
|
||||
: dns_(std::move(dns)) {}
|
||||
connection::connection(connection_info info)
|
||||
: connection_info_(std::move(info))
|
||||
{
|
||||
connection_ = backend_provider::instance().create_connection(connection_info_.type, connection_info_);
|
||||
}
|
||||
|
||||
connection::connection(const std::string& dns)
|
||||
: connection(connection_info::parse(dns))
|
||||
{}
|
||||
|
||||
connection::~connection()
|
||||
{
|
||||
if (connection_->is_open()) {
|
||||
connection_->close();
|
||||
}
|
||||
backend_provider::instance().destroy_connection(connection_info_.type, connection_);
|
||||
connection_ = nullptr;
|
||||
}
|
||||
|
||||
void connection::open()
|
||||
{
|
||||
is_open_ = true;
|
||||
connection_->open();
|
||||
}
|
||||
|
||||
void connection::close()
|
||||
{
|
||||
is_open_ = false;
|
||||
connection_->close();
|
||||
}
|
||||
|
||||
bool connection::is_open() const
|
||||
{
|
||||
return is_open_;
|
||||
return connection_->is_open();
|
||||
}
|
||||
|
||||
const std::string &connection::dns() const
|
||||
const connection_info &connection::info() const
|
||||
{
|
||||
return dns_;
|
||||
return connection_info_;
|
||||
}
|
||||
|
||||
query_result<record> connection::fetch(const std::string &sql)
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include <utility>
|
||||
|
||||
#include "matador/sql/connection_impl.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
connection_impl::connection_impl(connection_info info)
|
||||
: info_(std::move(info)){}
|
||||
connection_impl::connection_impl(const connection_info &info)
|
||||
: info_(info){}
|
||||
|
||||
const connection_info &connection_impl::info() const {
|
||||
return info_;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "matador/sql/query_result_impl.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
void query_result_impl::on_primary_key(const char *id, std::string &value, size_t size)
|
||||
{
|
||||
read_value(id, column_index_++, value, size);
|
||||
}
|
||||
|
||||
void query_result_impl::on_revision(const char *id, unsigned long long int &rev)
|
||||
{
|
||||
read_value(id, column_index_++, rev);
|
||||
}
|
||||
|
||||
void query_result_impl::on_attribute(const char *id, char *value, const utils::field_attributes &attr)
|
||||
{
|
||||
read_value(id, column_index_++, value, attr.size());
|
||||
}
|
||||
|
||||
void query_result_impl::on_attribute(const char *id, std::string &value, const utils::field_attributes &attr)
|
||||
{
|
||||
read_value(id, column_index_++, value, attr.size());
|
||||
}
|
||||
|
||||
}
|
||||
+3
-1
@@ -1,12 +1,14 @@
|
||||
#include "matador/sql/session.hpp"
|
||||
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
session::session(connection_pool<connection> &pool)
|
||||
: pool_(pool)
|
||||
, query_(dialect_) {}
|
||||
, query_(backend_provider::instance().connection_dialect(pool.info().type)) {}
|
||||
|
||||
query_create_intermediate session::create()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user