added mysql backend
This commit is contained in:
@@ -32,7 +32,7 @@ public:
|
||||
[[nodiscard]] const connection_info& info() const;
|
||||
|
||||
[[nodiscard]] record describe(const std::string &table_name) const;
|
||||
[[nodiscard]] bool exists(const std::string &table_name) const;
|
||||
[[nodiscard]] bool exists(const std::string &schema_name, const std::string &table_name) const;
|
||||
|
||||
[[nodiscard]] std::unique_ptr<query_result_impl> fetch(const std::string &sql) const;
|
||||
[[nodiscard]] size_t execute(const std::string &sql) const;
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
virtual std::unique_ptr<statement_impl> prepare(query_context context) = 0;
|
||||
|
||||
virtual record describe(const std::string &table) = 0;
|
||||
virtual bool exists(const std::string &table_name) = 0;
|
||||
virtual bool exists(const std::string &schema_name, const std::string &table_name) = 0;
|
||||
|
||||
protected:
|
||||
explicit connection_impl(const connection_info &info);
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
#ifndef QUERY_OBJECT_BINDER_HPP
|
||||
#define QUERY_OBJECT_BINDER_HPP
|
||||
#ifndef QUERY_OBJECT_PARAMETER_BINDER_HPP
|
||||
#define QUERY_OBJECT_PARAMETER_BINDER_HPP
|
||||
|
||||
#include "matador/sql/parameter_binder.hpp"
|
||||
#include "matador/sql/types.hpp"
|
||||
@@ -49,10 +49,10 @@ private:
|
||||
|
||||
}
|
||||
|
||||
class object_binder
|
||||
class object_parameter_binder
|
||||
{
|
||||
public:
|
||||
explicit object_binder(parameter_binder &binder);
|
||||
explicit object_parameter_binder(parameter_binder &binder);
|
||||
|
||||
void reset();
|
||||
|
||||
@@ -101,4 +101,4 @@ void fk_binder::on_primary_key(const char *id, ValueType &value, typename std::e
|
||||
|
||||
}
|
||||
}
|
||||
#endif //QUERY_OBJECT_BINDER_HPP
|
||||
#endif //QUERY_OBJECT_PARAMETER_BINDER_HPP
|
||||
@@ -11,7 +11,7 @@ struct query_context
|
||||
std::string command_name;
|
||||
std::string table_name;
|
||||
record prototype;
|
||||
std::vector<any_type> host_vars;
|
||||
std::vector<std::string> result_vars;
|
||||
std::vector<std::string> bind_vars;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
#ifndef QUERY_RESULT_PARAMETER_BINDER_HPP
|
||||
#define QUERY_RESULT_PARAMETER_BINDER_HPP
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/cascade_type.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
|
||||
#include "matador/sql/any_type.hpp"
|
||||
#include "matador/sql/types.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
class result_parameter_binder;
|
||||
|
||||
namespace detail {
|
||||
class fk_result_binder
|
||||
{
|
||||
public:
|
||||
explicit fk_result_binder(result_parameter_binder &result_binder);
|
||||
|
||||
template<class Type>
|
||||
void bind_result(Type &obj, size_t column_index)
|
||||
{
|
||||
column_index_ = column_index;
|
||||
utils::access::process(*this, obj);
|
||||
}
|
||||
|
||||
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);
|
||||
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) {}
|
||||
template < class Pointer >
|
||||
void on_belongs_to(const char * /*id*/, Pointer &/*x*/, utils::cascade_type) {}
|
||||
template < class Pointer >
|
||||
void on_has_one(const char * /*id*/, Pointer &/*x*/, utils::cascade_type) {}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char *, ContainerType &, const char *, const char *, utils::cascade_type) {}
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char *, ContainerType &, utils::cascade_type) {}
|
||||
|
||||
private:
|
||||
size_t column_index_{};
|
||||
result_parameter_binder &result_binder_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class result_parameter_binder
|
||||
{
|
||||
public:
|
||||
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)
|
||||
{
|
||||
data_type_traits<ValueType>::bind_result_value(*this, 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)
|
||||
{
|
||||
data_type_traits<Type>::bind_result_value(*this, 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_attribute(const char *id, any_type &value, data_type_t type, const utils::field_attributes &attr = utils::null_attributes);
|
||||
|
||||
template < class Pointer >
|
||||
void on_belongs_to(const char * /*id*/, Pointer &x, utils::cascade_type)
|
||||
{
|
||||
if (!x.get()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
fk_result_binder_.bind_result(*x, column_index_++);
|
||||
}
|
||||
template < class Pointer >
|
||||
void on_has_one(const char * /*id*/, Pointer &x, utils::cascade_type)
|
||||
{
|
||||
if (!x.get()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
fk_result_binder_.bind_result(*x, column_index_++);
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char *, ContainerType &, const char *, const char *, utils::cascade_type) {}
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char *, ContainerType &, utils::cascade_type) {}
|
||||
|
||||
virtual void bind_result_value(size_t index, char &value) {}
|
||||
virtual void bind_result_value(size_t index, short &value) {}
|
||||
virtual void bind_result_value(size_t index, int &value) {}
|
||||
virtual void bind_result_value(size_t index, long &value) {}
|
||||
virtual void bind_result_value(size_t index, long long &value) {}
|
||||
virtual void bind_result_value(size_t index, unsigned char &value) {}
|
||||
virtual void bind_result_value(size_t index, unsigned short &value) {}
|
||||
virtual void bind_result_value(size_t index, unsigned int &value) {}
|
||||
virtual void bind_result_value(size_t index, unsigned long &value) {}
|
||||
virtual void bind_result_value(size_t index, unsigned long long &value) {}
|
||||
virtual void bind_result_value(size_t index, bool &value) {}
|
||||
virtual void bind_result_value(size_t index, float &value) {}
|
||||
virtual void bind_result_value(size_t index, double &value) {}
|
||||
// virtual void bind_result_value(size_t index, matador::time &value) {}
|
||||
// virtual void bind_result_value(size_t index, matador::date &value) {}
|
||||
virtual void bind_result_value(size_t index, char *value, size_t s) {}
|
||||
virtual void bind_result_value(size_t index, std::string &value) {}
|
||||
virtual void bind_result_value(size_t index, std::string &value, size_t s) {}
|
||||
virtual void bind_result_value(size_t index, any_type &value, data_type_t type, size_t size) {}
|
||||
|
||||
private:
|
||||
size_t column_index_{};
|
||||
detail::fk_result_binder fk_result_binder_;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename ValueType>
|
||||
void fk_result_binder::on_primary_key(const char * /*id*/, ValueType &value, typename std::enable_if<std::is_integral<ValueType>::value && !std::is_same<bool, ValueType>::value>::type *)
|
||||
{
|
||||
data_type_traits<ValueType>::bind_result_value(result_binder_, column_index_++, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //QUERY_RESULT_PARAMETER_BINDER_HPP
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef QUERY_STATEMENT_HPP
|
||||
#define QUERY_STATEMENT_HPP
|
||||
|
||||
#include "matador/sql/object_binder.hpp"
|
||||
#include "matador/sql/object_parameter_binder.hpp"
|
||||
#include "matador/sql/query_result.hpp"
|
||||
#include "matador/sql/statement_impl.hpp"
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
private:
|
||||
std::unique_ptr<statement_impl> statement_;
|
||||
const utils::logger &logger_;
|
||||
object_binder object_binder_;
|
||||
object_parameter_binder object_binder_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace matador::sql {
|
||||
|
||||
class query_result_reader;
|
||||
class parameter_binder;
|
||||
class result_parameter_binder;
|
||||
|
||||
/**
|
||||
* @brief Enumeration type of all supported builtin data types
|
||||
@@ -65,6 +66,7 @@ template <> struct data_type_traits<char, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_char; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, char &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, char &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, char &value);
|
||||
inline static any_type create_value(char &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -73,6 +75,7 @@ template <> struct data_type_traits<short, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_short; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, short &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, short &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, short &value);
|
||||
inline static any_type create_value(short &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -81,6 +84,7 @@ template <> struct data_type_traits<int, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_int; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, int &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, int &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, int &value);
|
||||
inline static any_type create_value(int &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -89,6 +93,7 @@ template <> struct data_type_traits<long, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_long; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, long &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, long &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, long &value);
|
||||
inline static any_type create_value(long &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -97,6 +102,7 @@ template <> struct data_type_traits<long long, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_long_long; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, long long &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, long long &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, long long &value);
|
||||
inline static any_type create_value(long long &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -105,6 +111,7 @@ template <> struct data_type_traits<unsigned char, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_unsigned_char; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, unsigned char &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, unsigned char &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, unsigned char &value);
|
||||
inline static any_type create_value(unsigned char &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -113,6 +120,7 @@ template <> struct data_type_traits<unsigned short, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_unsigned_short; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, unsigned short &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, unsigned short &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, unsigned short &value);
|
||||
inline static any_type create_value(unsigned short &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -121,6 +129,7 @@ template <> struct data_type_traits<unsigned int, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_unsigned_int; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, unsigned int &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, unsigned int &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, unsigned int &value);
|
||||
inline static any_type create_value(unsigned int &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -129,6 +138,7 @@ template <> struct data_type_traits<unsigned long, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/ = 0) { return data_type_t::type_unsigned_long; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, unsigned long &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, unsigned long &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, unsigned long &value);
|
||||
inline static any_type create_value(unsigned long &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -137,6 +147,7 @@ template <> struct data_type_traits<unsigned long long, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_unsigned_long_long; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, unsigned long long &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, unsigned long long &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, unsigned long long &value);
|
||||
inline static any_type create_value(unsigned long long &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -145,6 +156,7 @@ template <> struct data_type_traits<bool, void>
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_bool; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, bool &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, bool &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, bool &value);
|
||||
inline static any_type create_value(bool &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -152,6 +164,7 @@ template <> struct data_type_traits<float, void>
|
||||
{
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_float; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, float &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, float &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, float &value);
|
||||
inline static any_type create_value(float &value) { return value; }
|
||||
};
|
||||
@@ -160,6 +173,7 @@ template <> struct data_type_traits<double, void>
|
||||
{
|
||||
inline static data_type_t builtin_type(std::size_t /*size*/) { return data_type_t::type_double; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, double &value);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, double &value);
|
||||
static void bind_value(parameter_binder &binder, size_t index, double &value);
|
||||
inline static any_type create_value(double &value) { return value; }
|
||||
};
|
||||
@@ -169,6 +183,7 @@ template <> struct data_type_traits<const char*, void>
|
||||
inline static data_type_t builtin_type(std::size_t size) { return size == 0 ? data_type_t::type_text : data_type_t::type_char_pointer; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, const char* value, size_t size);
|
||||
static void bind_value(parameter_binder &binder, size_t index, const char *value, size_t size = 0);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, const char *value, size_t size = 0);
|
||||
inline static any_type create_value(const char *value) { return value; }
|
||||
};
|
||||
|
||||
@@ -177,6 +192,7 @@ template <> struct data_type_traits<char*, void>
|
||||
inline static data_type_t builtin_type(std::size_t size) { return size == 0 ? data_type_t::type_text : data_type_t::type_varchar; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, char *value, size_t size);
|
||||
static void bind_value(parameter_binder &binder, size_t index, char *value, size_t size = 0);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, char *value, size_t size = 0);
|
||||
inline static any_type create_value(const char *value) { return value; }
|
||||
};
|
||||
|
||||
@@ -185,6 +201,7 @@ template <> struct data_type_traits<std::string, void>
|
||||
inline static data_type_t builtin_type(std::size_t size) { return size == 0 ? data_type_t::type_text : data_type_t::type_varchar; }
|
||||
static void read_value(query_result_reader &reader, const char *id, size_t index, std::string &value, size_t size);
|
||||
static void bind_value(parameter_binder &binder, size_t index, std::string &value, size_t size = 0);
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, std::string &value, size_t size = 0);
|
||||
inline static any_type create_value(std::string &value) { return value; }
|
||||
};
|
||||
|
||||
@@ -216,6 +233,10 @@ struct data_type_traits<EnumType, typename std::enable_if<std::is_enum<EnumType>
|
||||
{
|
||||
data_type_traits<int>::bind_value(binder, index, (int&)value);
|
||||
}
|
||||
static void bind_result_value(result_parameter_binder &binder, size_t index, EnumType &value)
|
||||
{
|
||||
data_type_traits<int>::bind_result_value(binder, index, (int&)value);
|
||||
}
|
||||
inline static any_type create_value(EnumType &value) { return (int)value; }
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
Reference in New Issue
Block a user