Compare commits
No commits in common. "ae236746ada299da1ab84ec4bbd9f36ce06a96c9" and "715f4dff8f678e06c514922a3dfb64c67d5867e4" have entirely different histories.
ae236746ad
...
715f4dff8f
|
|
@ -1,14 +1,11 @@
|
||||||
set(HEADER
|
set(HEADER
|
||||||
include/sqlite_connection.hpp
|
include/sqlite_connection.hpp
|
||||||
include/sqlite_error.hpp
|
include/sqlite_error.hpp
|
||||||
include/sqlite_dialect.hpp
|
|
||||||
include/sqlite_query_result.hpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/sqlite_connection.cpp
|
src/sqlite_connection.cpp
|
||||||
src/sqlite_error.cpp
|
src/sqlite_error.cpp
|
||||||
src/sqlite_dialect.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(matador-sqlite SHARED ${SOURCES} ${HEADER})
|
add_library(matador-sqlite SHARED ${SOURCES} ${HEADER})
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
#ifndef QUERY_SQLITE_CONNECTION_HPP
|
#ifndef QUERY_SQLITE_CONNECTION_HPP
|
||||||
#define QUERY_SQLITE_CONNECTION_HPP
|
#define QUERY_SQLITE_CONNECTION_HPP
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#ifdef matador_sqlite_EXPORTS
|
|
||||||
#define MATADOR_SQLITE_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define MATADOR_SQLITE_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#pragma warning(disable: 4355)
|
|
||||||
#else
|
|
||||||
#define MATADOR_SQLITE_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "matador/sql/connection_impl.hpp"
|
#include "matador/sql/connection_impl.hpp"
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
@ -21,7 +10,7 @@ namespace matador::backends::sqlite {
|
||||||
class sqlite_connection : public matador::sql::connection_impl
|
class sqlite_connection : public matador::sql::connection_impl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit sqlite_connection(const sql::connection_info &info);
|
explicit sqlite_connection(sql::connection_info info);
|
||||||
void open() override;
|
void open() override;
|
||||||
void close() override;
|
void close() override;
|
||||||
bool is_open() override;
|
bool is_open() override;
|
||||||
|
|
@ -34,12 +23,4 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
MATADOR_SQLITE_API matador::sql::connection_impl* create_database(const matador::sql::connection_info &info);
|
|
||||||
|
|
||||||
MATADOR_SQLITE_API void destroy_database(matador::sql::connection_impl *db);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //QUERY_SQLITE_CONNECTION_HPP
|
#endif //QUERY_SQLITE_CONNECTION_HPP
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef QUERY_SQLITE_DIALECT_HPP
|
|
||||||
#define QUERY_SQLITE_DIALECT_HPP
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#ifdef matador_sqlite_EXPORTS
|
|
||||||
#define MATADOR_SQLITE_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define MATADOR_SQLITE_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#pragma warning(disable: 4355)
|
|
||||||
#else
|
|
||||||
#define MATADOR_SQLITE_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "matador/sql/dialect.hpp"
|
|
||||||
|
|
||||||
extern "C" [[maybe_unused]] MATADOR_SQLITE_API const matador::sql::dialect* get_dialect();
|
|
||||||
|
|
||||||
#endif //QUERY_SQLITE_DIALECT_HPP
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
#ifndef QUERY_SQLITE_QUERY_RESULT_HPP
|
|
||||||
#define QUERY_SQLITE_QUERY_RESULT_HPP
|
|
||||||
|
|
||||||
namespace matador::backends::sqlite {
|
|
||||||
|
|
||||||
class sqlite_query_result {
|
|
||||||
public:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //QUERY_SQLITE_QUERY_RESULT_HPP
|
|
||||||
|
|
@ -5,8 +5,9 @@
|
||||||
|
|
||||||
namespace matador::backends::sqlite {
|
namespace matador::backends::sqlite {
|
||||||
|
|
||||||
sqlite_connection::sqlite_connection(const sql::connection_info &info)
|
sqlite_connection::sqlite_connection(sql::connection_info info)
|
||||||
: connection_impl(info) {
|
: connection_impl(std::move(info)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sqlite_connection::open()
|
void sqlite_connection::open()
|
||||||
|
|
@ -29,7 +30,7 @@ void sqlite_connection::close()
|
||||||
|
|
||||||
bool sqlite_connection::is_open()
|
bool sqlite_connection::is_open()
|
||||||
{
|
{
|
||||||
return sqlite_db_ != nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sqlite_connection::execute(const std::string &stmt)
|
void sqlite_connection::execute(const std::string &stmt)
|
||||||
|
|
@ -42,18 +43,4 @@ void sqlite_connection::prepare(const std::string &stmt)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
MATADOR_SQLITE_API matador::sql::connection_impl *create_database(const matador::sql::connection_info &info)
|
|
||||||
{
|
|
||||||
return new matador::backends::sqlite::sqlite_connection(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
MATADOR_SQLITE_API void destroy_database(matador::sql::connection_impl *db)
|
|
||||||
{
|
|
||||||
delete db;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
#include "sqlite_dialect.hpp"
|
|
||||||
|
|
||||||
[[maybe_unused]] const matador::sql::dialect* get_dialect() {
|
|
||||||
using namespace matador::sql;
|
|
||||||
const static dialect d{{
|
|
||||||
{ dialect::token_t::BEGIN, "BEGIN TRANSACTION"},
|
|
||||||
{ dialect::token_t::COMMIT, "COMMIT TRANSACTION"},
|
|
||||||
{ dialect::token_t::ROLLBACK, "ROLLBACK TRANSACTION"}
|
|
||||||
}};
|
|
||||||
return &d;
|
|
||||||
}
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
#ifndef QUERY_BACKEND_PROVIDER_HPP
|
|
||||||
#define QUERY_BACKEND_PROVIDER_HPP
|
|
||||||
|
|
||||||
#include "matador/utils/library.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace matador::sql {
|
|
||||||
|
|
||||||
class connection_impl;
|
|
||||||
struct connection_info;
|
|
||||||
class dialect;
|
|
||||||
|
|
||||||
class backend_provider
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
backend_provider();
|
|
||||||
|
|
||||||
public:
|
|
||||||
static backend_provider& instance();
|
|
||||||
|
|
||||||
connection_impl* create_connection(const std::string &connection_type, const connection_info &info);
|
|
||||||
void destroy_connection(const std::string &connection_type, connection_impl *c);
|
|
||||||
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(const backend_context&) = delete;
|
|
||||||
backend_context& operator=(const backend_context&) = delete;
|
|
||||||
backend_context(backend_context&&) noexcept = default;
|
|
||||||
backend_context& operator=(backend_context&&) noexcept = default;
|
|
||||||
~backend_context();
|
|
||||||
|
|
||||||
typedef connection_impl*(*create_func)(const connection_info&);
|
|
||||||
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, std::unique_ptr<backend_context>>;
|
|
||||||
backends_t backends_;
|
|
||||||
std::string backends_path_;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif //QUERY_BACKEND_PROVIDER_HPP
|
|
||||||
|
|
@ -1,36 +1,32 @@
|
||||||
#ifndef QUERY_CONNECTION_HPP
|
#ifndef QUERY_CONNECTION_HPP
|
||||||
#define QUERY_CONNECTION_HPP
|
#define QUERY_CONNECTION_HPP
|
||||||
|
|
||||||
#include "matador/sql/connection_info.hpp"
|
#include "matador/sql/query_intermediates.hpp"
|
||||||
#include "matador/sql/dialect.hpp"
|
#include "matador/sql/dialect.hpp"
|
||||||
#include "matador/sql/query_result.hpp"
|
#include "matador/sql/query_builder.hpp"
|
||||||
#include "matador/sql/record.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
class connection_impl;
|
|
||||||
|
|
||||||
class connection
|
class connection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit connection(connection_info info);
|
connection() = default;
|
||||||
explicit connection(const std::string& dns);
|
explicit connection(std::string dns);
|
||||||
~connection();
|
|
||||||
|
|
||||||
void open();
|
void open();
|
||||||
void close();
|
void close();
|
||||||
[[nodiscard]] bool is_open() const;
|
[[nodiscard]] bool is_open() const;
|
||||||
[[nodiscard]] const connection_info& info() const;
|
|
||||||
|
[[nodiscard]] const std::string& dns() const;
|
||||||
|
|
||||||
query_result<record> fetch(const std::string &sql);
|
query_result<record> fetch(const std::string &sql);
|
||||||
std::pair<size_t, std::string> execute(const std::string &sql);
|
std::pair<size_t, std::string> execute(const std::string &sql);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const connection_info connection_info_;
|
std::string dns_;
|
||||||
bool is_open_{false};
|
bool is_open_{false};
|
||||||
connection_impl *connection_{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@ public:
|
||||||
virtual void prepare(const std::string &stmt) = 0;
|
virtual void prepare(const std::string &stmt) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit connection_impl(const connection_info &info);
|
explicit connection_impl(connection_info info);
|
||||||
|
|
||||||
[[nodiscard]] const connection_info &info() const;
|
[[nodiscard]] const connection_info &info() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const connection_info & info_;
|
connection_info info_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,10 @@ template < class Connection >
|
||||||
class connection_pool
|
class connection_pool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
connection_pool(const std::string &dns, unsigned int count)
|
connection_pool(const std::string &db, unsigned int count) {
|
||||||
: info_(connection_info::parse(dns)) {
|
|
||||||
connection_repo_.reserve(count);
|
connection_repo_.reserve(count);
|
||||||
for (auto i = 0U; i < count; ++i) {
|
for (auto i = 0U; i < count; ++i) {
|
||||||
connection_repo_.emplace_back(info_);
|
connection_repo_.emplace_back(db + std::to_string(i+1));
|
||||||
idle_connections_.push(&connection_repo_.back());
|
idle_connections_.push(&connection_repo_.back());
|
||||||
idle_connections_.back()->open();
|
idle_connections_.back()->open();
|
||||||
}
|
}
|
||||||
|
|
@ -88,9 +87,6 @@ public:
|
||||||
return inuse_connections_.size();
|
return inuse_connections_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const connection_info &info() const {
|
|
||||||
return info_;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
std::vector<Connection> connection_repo_;
|
std::vector<Connection> connection_repo_;
|
||||||
|
|
@ -99,8 +95,6 @@ private:
|
||||||
using connection_set = std::unordered_set<pointer>;
|
using connection_set = std::unordered_set<pointer>;
|
||||||
connections idle_connections_;
|
connections idle_connections_;
|
||||||
connection_set inuse_connections_;
|
connection_set inuse_connections_;
|
||||||
|
|
||||||
const connection_info info_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Connection>
|
template<class Connection>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
class dialect
|
class [[nodiscard]] dialect
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class token_t : uint8_t
|
enum class token_t : uint8_t
|
||||||
|
|
@ -59,15 +59,7 @@ public:
|
||||||
ESCAPE_CLOSING_BRACKET /**< The escape quotes differ; escape the closing one */
|
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:
|
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& token_at(token_t token) const;
|
||||||
const std::string& data_type_at(data_type_t type) const;
|
const std::string& data_type_at(data_type_t type) const;
|
||||||
|
|
||||||
|
|
@ -132,6 +124,8 @@ public:
|
||||||
const std::vector<std::string>& columns() const;
|
const std::vector<std::string>& columns() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
using token_to_string_map = std::unordered_map<token_t, std::string>;
|
||||||
|
|
||||||
std::vector<std::string> host_vars_;
|
std::vector<std::string> host_vars_;
|
||||||
std::vector<std::string> columns_;
|
std::vector<std::string> columns_;
|
||||||
|
|
||||||
|
|
@ -173,6 +167,7 @@ private:
|
||||||
{token_t::NONE, ""}
|
{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_to_string_map data_types_ {
|
||||||
{data_type_t::type_char, "TINYINT"},
|
{data_type_t::type_char, "TINYINT"},
|
||||||
{data_type_t::type_short, "SMALLINT"},
|
{data_type_t::type_short, "SMALLINT"},
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
#ifndef QUERY_QUERY_RESULT_IMPL_HPP
|
|
||||||
#define QUERY_QUERY_RESULT_IMPL_HPP
|
|
||||||
|
|
||||||
#include "matador/utils/field_attributes.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace matador::sql {
|
|
||||||
|
|
||||||
class query_result_impl
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void read_value(const char *id, size_t index, char &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, short &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, int &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, long &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, long long &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, unsigned char &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, unsigned short &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, unsigned int &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, unsigned long &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, unsigned long long &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, bool &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, float &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, double &value) = 0;
|
|
||||||
// virtual void read_value(const char *id, size_t index, matador::time &value) = 0;
|
|
||||||
// virtual void read_value(const char *id, size_t index, matador::date &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, char *value, size_t s) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, std::string &value) = 0;
|
|
||||||
virtual void read_value(const char *id, size_t index, std::string &value, size_t s) = 0;
|
|
||||||
|
|
||||||
template<typename ValueType>
|
|
||||||
void on_primary_key(const char *id, ValueType &value, typename std::enable_if<std::is_integral<ValueType>::value && !std::is_same<bool, ValueType>::value>::type* = 0)
|
|
||||||
{
|
|
||||||
read_value(id, column_index_++, value);
|
|
||||||
}
|
|
||||||
void on_primary_key(const char *id, std::string &value, size_t size);
|
|
||||||
void on_revision(const char *id, unsigned long long &rev);
|
|
||||||
|
|
||||||
template < class Type >
|
|
||||||
void on_attribute(const char *id, Type &x, const utils::field_attributes &/*attr*/ = utils::null_attributes)
|
|
||||||
{
|
|
||||||
read_value(id, column_index_++, x);
|
|
||||||
}
|
|
||||||
void on_attribute(const char *id, char *value, const utils::field_attributes &attr = utils::null_attributes);
|
|
||||||
void on_attribute(const char *id, std::string &value, const utils::field_attributes &attr = utils::null_attributes);
|
|
||||||
|
|
||||||
// void on_belongs_to(const char *id, matador::identifiable_holder &x, cascade_type);
|
|
||||||
// void on_has_one(const char *id, matador::identifiable_holder &x, cascade_type);
|
|
||||||
|
|
||||||
// void on_has_many(const char *, abstract_container &, const char *, const char *, cascade_type) {}
|
|
||||||
// void on_has_many(const char *, abstract_container &, cascade_type) {}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
size_t column_index_ = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //QUERY_QUERY_RESULT_IMPL_HPP
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "matador/sql/connection.hpp"
|
#include "matador/sql/connection.hpp"
|
||||||
#include "matador/sql/connection_pool.hpp"
|
#include "matador/sql/connection_pool.hpp"
|
||||||
#include "matador/sql/query_builder.hpp"
|
|
||||||
#include "matador/sql/query_intermediates.hpp"
|
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
|
|
@ -25,6 +23,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
connection_pool<connection> &pool_;
|
connection_pool<connection> &pool_;
|
||||||
|
dialect dialect_;
|
||||||
query_builder query_;
|
query_builder query_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#ifndef QUERY_OS_HPP
|
|
||||||
#define QUERY_OS_HPP
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace matador::utils::os {
|
|
||||||
|
|
||||||
std::string error_string(unsigned long error);
|
|
||||||
|
|
||||||
std::string getenv(const char* name);
|
|
||||||
|
|
||||||
[[maybe_unused]] std::string getenv(const std::string &name);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //QUERY_OS_HPP
|
|
||||||
26
main.cpp
26
main.cpp
|
|
@ -1,17 +1,21 @@
|
||||||
#include <cstdlib>
|
#include <matador/sql/dialect.hpp>
|
||||||
|
#include <matador/sql/query_builder.hpp>
|
||||||
|
#include <matador/sql/types.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
|
using namespace matador;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const std::string env_var {"MATADOR_BACKENDS_PATH"};
|
sql::dialect d;
|
||||||
|
|
||||||
|
sql::query_builder query(d);
|
||||||
|
|
||||||
|
std::cout << query.create().table("person", {
|
||||||
|
{ "id", sql::data_type_traits<unsigned long>::builtin_type() },
|
||||||
|
{ "name", sql::data_type_traits<std::string>::builtin_type(255), 255 },
|
||||||
|
{ "id", sql::data_type_traits<unsigned long>::builtin_type() }
|
||||||
|
}).compile();
|
||||||
|
|
||||||
// char var[1024];
|
|
||||||
// size_t len{};
|
|
||||||
// const auto error = getenv_s(&len, var, 1024, env_var.c_str());
|
|
||||||
// if (error > 0) {
|
|
||||||
// std::cout << "error: unknown env var " << env_var << "\n";
|
|
||||||
// } else {
|
|
||||||
// std::cout << "env var: " << var << "\n";
|
|
||||||
// }
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,7 @@ set(SQL_SOURCES
|
||||||
sql/record.cpp
|
sql/record.cpp
|
||||||
sql/connection_info.cpp
|
sql/connection_info.cpp
|
||||||
sql/connection_impl.cpp
|
sql/connection_impl.cpp
|
||||||
sql/session.cpp
|
sql/session.cpp)
|
||||||
sql/backend_provider.cpp
|
|
||||||
sql/query_result_impl.cpp)
|
|
||||||
|
|
||||||
set(SQL_HEADER
|
set(SQL_HEADER
|
||||||
../include/matador/sql/dialect.hpp
|
../include/matador/sql/dialect.hpp
|
||||||
|
|
@ -29,23 +27,19 @@ set(SQL_HEADER
|
||||||
../include/matador/sql/connection_impl.hpp
|
../include/matador/sql/connection_impl.hpp
|
||||||
../include/matador/sql/connection_info.hpp
|
../include/matador/sql/connection_info.hpp
|
||||||
../include/matador/sql/connection_pool.hpp
|
../include/matador/sql/connection_pool.hpp
|
||||||
../include/matador/sql/session.hpp
|
../include/matador/sql/session.hpp)
|
||||||
../include/matador/sql/backend_provider.hpp
|
|
||||||
../include/matador/sql/query_result_impl.hpp)
|
|
||||||
|
|
||||||
set(UTILS_HEADER
|
set(UTILS_HEADER
|
||||||
../include/matador/utils/field_attributes.hpp
|
../include/matador/utils/field_attributes.hpp
|
||||||
../include/matador/utils/string.hpp
|
../include/matador/utils/string.hpp
|
||||||
../include/matador/utils/constraints.hpp
|
../include/matador/utils/constraints.hpp
|
||||||
../include/matador/utils/library.hpp
|
../include/matador/utils/library.hpp)
|
||||||
../include/matador/utils/os.hpp)
|
|
||||||
|
|
||||||
set(UTILS_SOURCES
|
set(UTILS_SOURCES
|
||||||
utils/field_attributes.cpp
|
utils/field_attributes.cpp
|
||||||
utils/string.cpp
|
utils/string.cpp
|
||||||
sql/condition.cpp
|
sql/condition.cpp
|
||||||
utils/library.cpp
|
utils/library.cpp)
|
||||||
utils/os.cpp)
|
|
||||||
|
|
||||||
add_library(matador STATIC ${SQL_SOURCES} ${SQL_HEADER} ${UTILS_SOURCES} ${UTILS_HEADER})
|
add_library(matador STATIC ${SQL_SOURCES} ${SQL_HEADER} ${UTILS_SOURCES} ${UTILS_HEADER})
|
||||||
target_include_directories(matador PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
target_include_directories(matador PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||||
|
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
#include "matador/sql/backend_provider.hpp"
|
|
||||||
|
|
||||||
#include "matador/utils/os.hpp"
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace matador::sql {
|
|
||||||
backend_provider::backend_provider()
|
|
||||||
: backends_path_(utils::os::getenv("MATADOR_BACKENDS_PATH"))
|
|
||||||
{}
|
|
||||||
|
|
||||||
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, std::make_unique<backend_context>(connection_type, backends_path_)).first;
|
|
||||||
}
|
|
||||||
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, std::make_unique<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("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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +1,30 @@
|
||||||
#include "matador/sql/connection.hpp"
|
|
||||||
|
|
||||||
#include "matador/sql/backend_provider.hpp"
|
|
||||||
#include "matador/sql/connection_impl.hpp"
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "matador/sql/connection.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
connection::connection(connection_info info)
|
connection::connection(std::string dns)
|
||||||
: connection_info_(std::move(info))
|
: dns_(std::move(dns)) {}
|
||||||
{
|
|
||||||
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()
|
void connection::open()
|
||||||
{
|
{
|
||||||
connection_->open();
|
is_open_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void connection::close()
|
void connection::close()
|
||||||
{
|
{
|
||||||
connection_->close();
|
is_open_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool connection::is_open() const
|
bool connection::is_open() const
|
||||||
{
|
{
|
||||||
return connection_->is_open();
|
return is_open_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const connection_info &connection::info() const
|
const std::string &connection::dns() const
|
||||||
{
|
{
|
||||||
return connection_info_;
|
return dns_;
|
||||||
}
|
}
|
||||||
|
|
||||||
query_result<record> connection::fetch(const std::string &sql)
|
query_result<record> connection::fetch(const std::string &sql)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "matador/sql/connection_impl.hpp"
|
#include "matador/sql/connection_impl.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
connection_impl::connection_impl(const connection_info &info)
|
connection_impl::connection_impl(connection_info info)
|
||||||
: info_(info){}
|
: info_(std::move(info)){}
|
||||||
|
|
||||||
const connection_info &connection_impl::info() const {
|
const connection_info &connection_impl::info() const {
|
||||||
return info_;
|
return info_;
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,6 @@
|
||||||
#include "matador/utils/string.hpp"
|
#include "matador/utils/string.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
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
|
const std::string& dialect::token_at(dialect::token_t token) const
|
||||||
{
|
{
|
||||||
return tokens_.at(token);
|
return tokens_.at(token);
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
#include "matador/sql/session.hpp"
|
#include "matador/sql/session.hpp"
|
||||||
|
|
||||||
#include "matador/sql/backend_provider.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
session::session(connection_pool<connection> &pool)
|
session::session(connection_pool<connection> &pool)
|
||||||
: pool_(pool)
|
: pool_(pool)
|
||||||
, query_(backend_provider::instance().connection_dialect(pool.info().type)) {}
|
, query_(dialect_) {}
|
||||||
|
|
||||||
query_create_intermediate session::create()
|
query_create_intermediate session::create()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include "matador/utils/library.hpp"
|
#include "matador/utils/library.hpp"
|
||||||
#include "matador/utils/os.hpp"
|
|
||||||
|
|
||||||
namespace matador::utils {
|
namespace matador::utils {
|
||||||
|
|
||||||
|
|
@ -14,20 +13,16 @@ library::~library()
|
||||||
|
|
||||||
bool library::load()
|
bool library::load()
|
||||||
{
|
{
|
||||||
auto path = os::getenv("MATADOR_BACKENDS_PATH");
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
auto cookie = AddDllDirectory(std::wstring(path.begin(), path.end()).c_str());
|
handle_ = LoadLibrary((lib_ + ".dll").c_str());
|
||||||
handle_ = LoadLibraryExA((lib_ + ".dll").c_str(), nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
|
|
||||||
RemoveDllDirectory(cookie);
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
handle_ = dlopen(std::string("lib" + lib_ + ".dylib").c_str(), RTLD_LAZY);
|
handle_ = dlopen(std::string("lib" + lib_ + ".dylib").c_str(), RTLD_LAZY);
|
||||||
#else
|
#else
|
||||||
handle_ = dlopen((path + "/lib" + lib_ + ".so").c_str(), RTLD_LAZY);
|
handle_ = dlopen(std::string("./lib" + lib_ + ".so").c_str(), RTLD_LAZY);
|
||||||
#endif
|
#endif
|
||||||
if (!handle_) {
|
if (!handle_) {
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
DWORD errorMessageID = ::GetLastError();
|
DWORD errorMessageID = ::GetLastError();
|
||||||
auto errstr = utils::os::error_string(errorMessageID);
|
|
||||||
#else
|
#else
|
||||||
// TODO: handle win32 and linux error
|
// TODO: handle win32 and linux error
|
||||||
fprintf(stdout, "dlopen error: %s", dlerror());
|
fprintf(stdout, "dlopen error: %s", dlerror());
|
||||||
|
|
@ -66,8 +61,7 @@ bool library::unload()
|
||||||
func_ptr library::function(const std::string &f) const
|
func_ptr library::function(const std::string &f) const
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
auto *addr = GetProcAddress(handle_, f.c_str());
|
return GetProcAddress(handle_, f.c_str());
|
||||||
return addr;
|
|
||||||
#else
|
#else
|
||||||
return dlsym(handle_, f.c_str());
|
return dlsym(handle_, f.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
#include "matador/utils/os.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace matador::utils::os {
|
|
||||||
|
|
||||||
std::string getenv(const char *name) {
|
|
||||||
#ifdef _WIN32
|
|
||||||
char var[1024];
|
|
||||||
size_t len{};
|
|
||||||
const auto error = getenv_s(&len, var, 1024, name);
|
|
||||||
if (error > 0) {
|
|
||||||
throw std::logic_error(error_string(error));
|
|
||||||
};
|
|
||||||
|
|
||||||
return var;
|
|
||||||
#else
|
|
||||||
return ::getenv(name);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
[[maybe_unused]] std::string getenv(const std::string &name) {
|
|
||||||
return getenv(name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::string error_string(unsigned long error) {
|
|
||||||
char* lpMsgBuf;
|
|
||||||
auto bufLen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
nullptr,
|
|
||||||
error,
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
||||||
(LPTSTR) &lpMsgBuf,
|
|
||||||
0,
|
|
||||||
nullptr);
|
|
||||||
std::string result;
|
|
||||||
if (bufLen) {
|
|
||||||
result.append(lpMsgBuf, lpMsgBuf+bufLen);
|
|
||||||
LocalFree(lpMsgBuf);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
@ -12,11 +12,6 @@ add_executable(tests builder.cpp
|
||||||
session.cpp
|
session.cpp
|
||||||
record.cpp
|
record.cpp
|
||||||
connection_pool.cpp
|
connection_pool.cpp
|
||||||
query.cpp
|
query.cpp)
|
||||||
backend_provider.cpp)
|
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain matador)
|
||||||
target_link_libraries(tests PRIVATE
|
|
||||||
Catch2::Catch2WithMain
|
|
||||||
matador
|
|
||||||
${CMAKE_DL_LIBS}
|
|
||||||
${SQLite3_LIBRARIES})
|
|
||||||
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
target_include_directories(tests PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>/include)
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
|
|
||||||
#include "matador/sql/connection_info.hpp"
|
|
||||||
#include "matador/sql/backend_provider.hpp"
|
|
||||||
|
|
||||||
#include "matador/utils/os.hpp"
|
|
||||||
|
|
||||||
using namespace matador::sql;
|
|
||||||
|
|
||||||
TEST_CASE("Load backend", "[backend provider]") {
|
|
||||||
auto path = matador::utils::os::getenv("MATADOR_BACKENDS_PATH");
|
|
||||||
if (path.back() != '\\') {
|
|
||||||
path.push_back('\\');
|
|
||||||
}
|
|
||||||
|
|
||||||
REQUIRE(!path.empty());
|
|
||||||
|
|
||||||
connection_info ci{};
|
|
||||||
const auto &d = backend_provider::instance().connection_dialect("sqlite");
|
|
||||||
auto *connection = backend_provider::instance().create_connection("sqlite", ci);
|
|
||||||
REQUIRE(connection != nullptr);
|
|
||||||
backend_provider::instance().destroy_connection("sqlite", connection);
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,7 @@ using namespace matador::sql;
|
||||||
TEST_CASE("Create connection pool", "[connection pool]") {
|
TEST_CASE("Create connection pool", "[connection pool]") {
|
||||||
using pool_t = connection_pool<connection>;
|
using pool_t = connection_pool<connection>;
|
||||||
|
|
||||||
pool_t pool("sqlite://sqlite.db", 4);
|
pool_t pool("db", 4);
|
||||||
|
|
||||||
REQUIRE(pool.size() == 4);
|
REQUIRE(pool.size() == 4);
|
||||||
REQUIRE(pool.idle() == 4);
|
REQUIRE(pool.idle() == 4);
|
||||||
|
|
@ -17,7 +17,7 @@ TEST_CASE("Create connection pool", "[connection pool]") {
|
||||||
auto ptr = pool.acquire();
|
auto ptr = pool.acquire();
|
||||||
REQUIRE(ptr.valid());
|
REQUIRE(ptr.valid());
|
||||||
REQUIRE(ptr->is_open());
|
REQUIRE(ptr->is_open());
|
||||||
// REQUIRE(!ptr->dns().empty());
|
REQUIRE(!ptr->dns().empty());
|
||||||
|
|
||||||
REQUIRE(pool.idle() == 3);
|
REQUIRE(pool.idle() == 3);
|
||||||
REQUIRE(pool.inuse() == 1);
|
REQUIRE(pool.inuse() == 1);
|
||||||
|
|
@ -31,7 +31,7 @@ TEST_CASE("Create connection pool", "[connection pool]") {
|
||||||
auto ptr2 = pool.acquire();
|
auto ptr2 = pool.acquire();
|
||||||
REQUIRE(ptr2.valid());
|
REQUIRE(ptr2.valid());
|
||||||
REQUIRE(ptr2->is_open());
|
REQUIRE(ptr2->is_open());
|
||||||
// REQUIRE(!ptr2->dns().empty());
|
REQUIRE(!ptr2->dns().empty());
|
||||||
|
|
||||||
REQUIRE(pool.idle() == 3);
|
REQUIRE(pool.idle() == 3);
|
||||||
REQUIRE(pool.inuse() == 1);
|
REQUIRE(pool.inuse() == 1);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
using namespace matador::sql;
|
using namespace matador::sql;
|
||||||
|
|
||||||
TEST_CASE("Execute create table statement", "[connection]") {
|
TEST_CASE("Execute create table statement", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
const auto res = s.create()
|
const auto res = s.create()
|
||||||
|
|
@ -22,7 +22,7 @@ TEST_CASE("Execute create table statement", "[connection]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute drop table statement", "[connection]") {
|
TEST_CASE("Execute drop table statement", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
const auto res = s.drop()
|
const auto res = s.drop()
|
||||||
|
|
@ -33,7 +33,7 @@ TEST_CASE("Execute drop table statement", "[connection]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute select statement with where clause", "[connection]") {
|
TEST_CASE("Execute select statement with where clause", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
auto res = s.select({"id", "name", "color"})
|
auto res = s.select({"id", "name", "color"})
|
||||||
|
|
@ -45,7 +45,7 @@ TEST_CASE("Execute select statement with where clause", "[connection]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute select statement with order by", "[connection]") {
|
TEST_CASE("Execute select statement with order by", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
auto res = s.select({"id", "name", "color"})
|
auto res = s.select({"id", "name", "color"})
|
||||||
|
|
@ -58,7 +58,7 @@ TEST_CASE("Execute select statement with order by", "[connection]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute select statement with group by and order by", "[connection]") {
|
TEST_CASE("Execute select statement with group by and order by", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
auto res = s.select({"id", "name", "color"})
|
auto res = s.select({"id", "name", "color"})
|
||||||
|
|
@ -72,7 +72,7 @@ TEST_CASE("Execute select statement with group by and order by", "[connection]")
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute insert statement", "[connection]") {
|
TEST_CASE("Execute insert statement", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
auto res = s.insert()
|
auto res = s.insert()
|
||||||
|
|
@ -84,7 +84,7 @@ TEST_CASE("Execute insert statement", "[connection]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute update statement", "[connection]") {
|
TEST_CASE("Execute update statement", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
auto res = s.update("person")
|
auto res = s.update("person")
|
||||||
|
|
@ -99,7 +99,7 @@ TEST_CASE("Execute update statement", "[connection]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Execute delete statement", "[connection]") {
|
TEST_CASE("Execute delete statement", "[connection]") {
|
||||||
connection_pool<connection> pool("sqlite://sqlite.db", 4);
|
connection_pool<connection> pool("dns", 4);
|
||||||
session s(pool);
|
session s(pool);
|
||||||
|
|
||||||
auto res = s.remove()
|
auto res = s.remove()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue