Compare commits
2 Commits
263c202c69
...
108eca4e53
| Author | SHA1 | Date |
|---|---|---|
|
|
108eca4e53 | |
|
|
d4ef97ef5a |
|
|
@ -154,61 +154,61 @@ utils::result<size_t, utils::error> postgres_connection::execute(const std::stri
|
||||||
utils::basic_type oid2type(const Oid oid) {
|
utils::basic_type oid2type(const Oid oid) {
|
||||||
switch (oid) {
|
switch (oid) {
|
||||||
case 16:
|
case 16:
|
||||||
return utils::basic_type::type_bool;
|
return utils::basic_type::Boolean;
|
||||||
case 17:
|
case 17:
|
||||||
return utils::basic_type::type_blob;
|
return utils::basic_type::Blob;
|
||||||
case 18:
|
case 18:
|
||||||
return utils::basic_type::type_int8;
|
return utils::basic_type::Int8;
|
||||||
case 21:
|
case 21:
|
||||||
return utils::basic_type::type_int16;
|
return utils::basic_type::Int16;
|
||||||
case 23:
|
case 23:
|
||||||
return utils::basic_type::type_int32;
|
return utils::basic_type::Int32;
|
||||||
case 20:
|
case 20:
|
||||||
return utils::basic_type::type_int64;
|
return utils::basic_type::Int64;
|
||||||
case 25:
|
case 25:
|
||||||
return utils::basic_type::type_text;
|
return utils::basic_type::Text;
|
||||||
case 1043:
|
case 1043:
|
||||||
return utils::basic_type::type_varchar;
|
return utils::basic_type::Varchar;
|
||||||
case 700:
|
case 700:
|
||||||
return utils::basic_type::type_float;
|
return utils::basic_type::Float;
|
||||||
case 701:
|
case 701:
|
||||||
return utils::basic_type::type_double;
|
return utils::basic_type::Double;
|
||||||
case 1082:
|
case 1082:
|
||||||
return utils::basic_type::type_date;
|
return utils::basic_type::Date;
|
||||||
case 1114:
|
case 1114:
|
||||||
return utils::basic_type::type_time;
|
return utils::basic_type::Time;
|
||||||
default:
|
default:
|
||||||
return utils::basic_type::type_null;
|
return utils::basic_type::Null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils::basic_type string2type(const char *type) {
|
utils::basic_type string2type(const char *type) {
|
||||||
if (strcmp(type, "int2") == 0) {
|
if (strcmp(type, "int2") == 0) {
|
||||||
return utils::basic_type::type_int16;
|
return utils::basic_type::Int16;
|
||||||
} else if (strcmp(type, "int4") == 0) {
|
} else if (strcmp(type, "int4") == 0) {
|
||||||
return utils::basic_type::type_int32;
|
return utils::basic_type::Int32;
|
||||||
} else if (strcmp(type, "int8") == 0) {
|
} else if (strcmp(type, "int8") == 0) {
|
||||||
return utils::basic_type::type_int64;
|
return utils::basic_type::Int64;
|
||||||
} else if (strcmp(type, "bool") == 0) {
|
} else if (strcmp(type, "bool") == 0) {
|
||||||
return utils::basic_type::type_bool;
|
return utils::basic_type::Boolean;
|
||||||
} else if (strcmp(type, "date") == 0) {
|
} else if (strcmp(type, "date") == 0) {
|
||||||
return utils::basic_type::type_date;
|
return utils::basic_type::Date;
|
||||||
} else if (strcmp(type, "timestamp") == 0) {
|
} else if (strcmp(type, "timestamp") == 0) {
|
||||||
return utils::basic_type::type_time;
|
return utils::basic_type::Time;
|
||||||
} else if (strcmp(type, "float4") == 0) {
|
} else if (strcmp(type, "float4") == 0) {
|
||||||
return utils::basic_type::type_float;
|
return utils::basic_type::Float;
|
||||||
} else if (strcmp(type, "float8") == 0) {
|
} else if (strcmp(type, "float8") == 0) {
|
||||||
return utils::basic_type::type_double;
|
return utils::basic_type::Double;
|
||||||
} else if (strncmp(type, "varchar", 7) == 0) {
|
} else if (strncmp(type, "varchar", 7) == 0) {
|
||||||
return utils::basic_type::type_varchar;
|
return utils::basic_type::Varchar;
|
||||||
} else if (strcmp(type, "character varying") == 0) {
|
} else if (strcmp(type, "character varying") == 0) {
|
||||||
return utils::basic_type::type_varchar;
|
return utils::basic_type::Varchar;
|
||||||
} else if (strcmp(type, "text") == 0) {
|
} else if (strcmp(type, "text") == 0) {
|
||||||
return utils::basic_type::type_text;
|
return utils::basic_type::Text;
|
||||||
} else if (strcmp(type, "bytea") == 0) {
|
} else if (strcmp(type, "bytea") == 0) {
|
||||||
return utils::basic_type::type_blob;
|
return utils::basic_type::Blob;
|
||||||
} else {
|
} else {
|
||||||
return utils::basic_type::type_null;
|
return utils::basic_type::Null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,12 @@
|
||||||
{dialect_token::BeginBinaryData, "'\\x"}
|
{dialect_token::BeginBinaryData, "'\\x"}
|
||||||
})
|
})
|
||||||
.with_data_type_replace_map({
|
.with_data_type_replace_map({
|
||||||
{matador::utils::basic_type::type_int8, "SMALLINT"},
|
{matador::utils::basic_type::Int8, "SMALLINT"},
|
||||||
{matador::utils::basic_type::type_uint8, "SMALLINT"},
|
{matador::utils::basic_type::UInt8, "SMALLINT"},
|
||||||
{matador::utils::basic_type::type_float, "REAL"},
|
{matador::utils::basic_type::Float, "REAL"},
|
||||||
{matador::utils::basic_type::type_double, "DOUBLE PRECISION"},
|
{matador::utils::basic_type::Double, "DOUBLE PRECISION"},
|
||||||
{matador::utils::basic_type::type_time, "TIMESTAMP"},
|
{matador::utils::basic_type::Time, "TIMESTAMP"},
|
||||||
{matador::utils::basic_type::type_blob, "BYTEA"}
|
{matador::utils::basic_type::Blob, "BYTEA"}
|
||||||
})
|
})
|
||||||
.with_bool_strings("TRUE", "FALSE")
|
.with_bool_strings("TRUE", "FALSE")
|
||||||
.with_default_schema_name("public")
|
.with_default_schema_name("public")
|
||||||
|
|
|
||||||
|
|
@ -172,41 +172,41 @@ void set_value<utils::blob>(const char* str, utils::value& value) {
|
||||||
|
|
||||||
void postgres_result_reader::read_value(const char * /*id*/, const size_t index, utils::value &val, size_t) {
|
void postgres_result_reader::read_value(const char * /*id*/, const size_t index, utils::value &val, size_t) {
|
||||||
switch (val.type()) {
|
switch (val.type()) {
|
||||||
case utils::basic_type::type_int8:
|
case utils::basic_type::Int8:
|
||||||
set_value<int8_t>(column(index), val);
|
set_value<int8_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_int16:
|
case utils::basic_type::Int16:
|
||||||
set_value<int16_t>(column(index), val);
|
set_value<int16_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_int32:
|
case utils::basic_type::Int32:
|
||||||
set_value<int32_t>(column(index), val);
|
set_value<int32_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_int64:
|
case utils::basic_type::Int64:
|
||||||
set_value<int64_t>(column(index), val);
|
set_value<int64_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_uint8:
|
case utils::basic_type::UInt8:
|
||||||
set_value<uint8_t>(column(index), val);
|
set_value<uint8_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_uint16:
|
case utils::basic_type::UInt16:
|
||||||
set_value<uint16_t>(column(index), val);
|
set_value<uint16_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_uint32:
|
case utils::basic_type::UInt32:
|
||||||
set_value<uint32_t>(column(index), val);
|
set_value<uint32_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_uint64:
|
case utils::basic_type::UInt64:
|
||||||
set_value<uint64_t>(column(index), val);
|
set_value<uint64_t>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_float:
|
case utils::basic_type::Float:
|
||||||
set_value<float>(column(index), val);
|
set_value<float>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_double:
|
case utils::basic_type::Double:
|
||||||
set_value<double>(column(index), val);
|
set_value<double>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_bool:
|
case utils::basic_type::Boolean:
|
||||||
set_value<bool>(column(index), val);
|
set_value<bool>(column(index), val);
|
||||||
break;
|
break;
|
||||||
case utils::basic_type::type_text:
|
case utils::basic_type::Text:
|
||||||
case utils::basic_type::type_varchar: {
|
case utils::basic_type::Varchar: {
|
||||||
if (const auto *column_value = column(index); column_value == nullptr) {
|
if (const auto *column_value = column(index); column_value == nullptr) {
|
||||||
val = std::string{};
|
val = std::string{};
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -214,16 +214,16 @@ void postgres_result_reader::read_value(const char * /*id*/, const size_t index,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case utils::basic_type::type_time:
|
case utils::basic_type::Time:
|
||||||
case utils::basic_type::type_date: {
|
case utils::basic_type::Date: {
|
||||||
val = std::string{column(index)};
|
val = std::string{column(index)};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case utils::basic_type::type_null: {
|
case utils::basic_type::Null: {
|
||||||
val = nullptr_t{};
|
val = nullptr_t{};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case utils::basic_type::type_blob: {
|
case utils::basic_type::Blob: {
|
||||||
set_value<utils::blob>(column(index), val);
|
set_value<utils::blob>(column(index), val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ CPMAddPackage("gh:catchorg/Catch2@3.7.1")
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||||
|
|
||||||
set(POSTGRES_CONNECTION_STRING "postgres://test:test123!@127.0.0.1:15442/matador")
|
#set(POSTGRES_CONNECTION_STRING "postgres://test:test123!@127.0.0.1:15442/matador")
|
||||||
#set(POSTGRES_CONNECTION_STRING "postgres://test:test123!@127.0.0.1:5432/matador")
|
set(POSTGRES_CONNECTION_STRING "postgres://test:test123!@127.0.0.1:5432/matador")
|
||||||
|
|
||||||
configure_file(Connection.hpp.in ${PROJECT_BINARY_DIR}/backends/postgres/test/connection.hpp @ONLY IMMEDIATE)
|
configure_file(Connection.hpp.in ${PROJECT_BINARY_DIR}/backends/postgres/test/connection.hpp @ONLY IMMEDIATE)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,22 +41,22 @@ public:
|
||||||
[[nodiscard]] bool is_nullable() const { return null_option_type_ == null_option_type::Nullable; }
|
[[nodiscard]] bool is_nullable() const { return null_option_type_ == null_option_type::Nullable; }
|
||||||
[[nodiscard]] utils::basic_type type() const { return type_; }
|
[[nodiscard]] utils::basic_type type() const { return type_; }
|
||||||
|
|
||||||
[[nodiscard]] bool is_integer() const { return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64; }
|
[[nodiscard]] bool is_integer() const { return type_ >= utils::basic_type::Int8 && type_ <= utils::basic_type::UInt64; }
|
||||||
[[nodiscard]] bool is_floating_point() const { return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double; }
|
[[nodiscard]] bool is_floating_point() const { return type_ == utils::basic_type::Float || type_ == utils::basic_type::Double; }
|
||||||
[[nodiscard]] bool is_bool() const { return type_ == utils::basic_type::type_bool; }
|
[[nodiscard]] bool is_bool() const { return type_ == utils::basic_type::Boolean; }
|
||||||
[[nodiscard]] bool is_string() const { return type_ == utils::basic_type::type_text; }
|
[[nodiscard]] bool is_string() const { return type_ == utils::basic_type::Text; }
|
||||||
[[nodiscard]] bool is_varchar() const { return type_ == utils::basic_type::type_varchar; }
|
[[nodiscard]] bool is_varchar() const { return type_ == utils::basic_type::Varchar; }
|
||||||
[[nodiscard]] bool is_date() const { return type_ == utils::basic_type::type_date; }
|
[[nodiscard]] bool is_date() const { return type_ == utils::basic_type::Date; }
|
||||||
[[nodiscard]] bool is_time() const { return type_ == utils::basic_type::type_time; }
|
[[nodiscard]] bool is_time() const { return type_ == utils::basic_type::Time; }
|
||||||
[[nodiscard]] bool is_blob() const { return type_ == utils::basic_type::type_blob; }
|
[[nodiscard]] bool is_blob() const { return type_ == utils::basic_type::Blob; }
|
||||||
[[nodiscard]] bool is_null() const { return type_ == utils::basic_type::type_null; }
|
[[nodiscard]] bool is_null() const { return type_ == utils::basic_type::Null; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class object;
|
friend class object;
|
||||||
|
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::string alias_;
|
std::string alias_;
|
||||||
utils::basic_type type_{utils::basic_type::type_null};
|
utils::basic_type type_{utils::basic_type::Null};
|
||||||
utils::field_attributes options_;
|
utils::field_attributes options_;
|
||||||
null_option_type null_option_type_{null_option_type::NotNull};
|
null_option_type null_option_type_{null_option_type::NotNull};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
#include "matador/orm/session.hpp"
|
#include "matador/orm/session.hpp"
|
||||||
|
|
||||||
template <> struct matador::utils::data_type_traits<work::core::timestamp, void> {
|
template <> struct matador::utils::data_type_traits<work::core::timestamp, void> {
|
||||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; }
|
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
|
||||||
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ template <> struct matador::utils::data_type_traits<work::core::timestamp, void>
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
|
template <> struct matador::utils::data_type_traits<work::core::UserInfo, void> {
|
||||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_uint64; }
|
static basic_type type(std::size_t /*size*/) { return basic_type::UInt64; }
|
||||||
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
static void read_value(attribute_reader &/*reader*/, const char * /*id*/, size_t /*index*/, nullptr_t &/*value*/) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "matador/utils/field_attributes.hpp"
|
#include "matador/utils/field_attributes.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
|
|
||||||
|
|
@ -60,6 +61,8 @@ public:
|
||||||
return type() == utils::data_type_traits<Type>::type(attributes().size());
|
return type() == utils::data_type_traits<Type>::type(attributes().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const attribute& attr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class object;
|
friend class object;
|
||||||
friend class attribute_generator;
|
friend class attribute_generator;
|
||||||
|
|
@ -67,7 +70,7 @@ private:
|
||||||
|
|
||||||
std::string name_;
|
std::string name_;
|
||||||
object *owner_{nullptr};
|
object *owner_{nullptr};
|
||||||
utils::basic_type type_{utils::basic_type::type_null};
|
utils::basic_type type_{utils::basic_type::Null};
|
||||||
utils::field_attributes options_{};
|
utils::field_attributes options_{};
|
||||||
null_option_type null_option_{null_option_type::NotNull};
|
null_option_type null_option_{null_option_type::NotNull};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] std::type_index type_index() const;
|
[[nodiscard]] std::type_index type_index() const;
|
||||||
[[nodiscard]] std::string name() const;
|
[[nodiscard]] std::string name() const;
|
||||||
|
[[nodiscard]] const class object& object() const;
|
||||||
[[nodiscard]] const std::list<attribute>& attributes() const;
|
[[nodiscard]] const std::list<attribute>& attributes() const;
|
||||||
[[nodiscard]] const std::list<class constraint>& constraints() const;
|
[[nodiscard]] const std::list<class constraint>& constraints() const;
|
||||||
|
|
||||||
|
|
@ -54,10 +55,10 @@ public:
|
||||||
[[nodiscard]] bool endpoints_empty() const;
|
[[nodiscard]] bool endpoints_empty() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<object> &&obj);
|
basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<class object> &&obj);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<object> object_;
|
std::unique_ptr<class object> object_;
|
||||||
std::shared_ptr<repository_node> node_; /**< prototype node of the represented object type */
|
std::shared_ptr<repository_node> node_; /**< prototype node of the represented object type */
|
||||||
t_endpoint_map relation_endpoints_;
|
t_endpoint_map relation_endpoints_;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "matador/utils/constraints.hpp"
|
#include "matador/utils/constraints.hpp"
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
|
|
@ -28,6 +29,8 @@ public:
|
||||||
[[nodiscard]] const std::string& ref_table_name() const;
|
[[nodiscard]] const std::string& ref_table_name() const;
|
||||||
[[nodiscard]] const std::string& ref_column_name() const;
|
[[nodiscard]] const std::string& ref_column_name() const;
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const constraint& c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class constraint_builder;
|
friend class constraint_builder;
|
||||||
friend class constraints_generator;
|
friend class constraints_generator;
|
||||||
|
|
|
||||||
|
|
@ -115,13 +115,13 @@ private:
|
||||||
return std::make_unique<relation_value_type>(join_column, inverse_join_column);
|
return std::make_unique<relation_value_type>(join_column, inverse_join_column);
|
||||||
};
|
};
|
||||||
|
|
||||||
result = repository_node::make_relation_node<relation_value_type>(repo_.repo(), name, std::move(creator));
|
auto node = repository_node::make_node<relation_value_type>(repo_.repo(), name, std::move(creator));
|
||||||
|
result = repo_.attach_node(node);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// Todo: throw internal error
|
// Todo: throw internal error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& node = result.value();
|
|
||||||
complete<relation_value_type>(result.value());
|
complete<relation_value_type>(result.value());
|
||||||
|
|
||||||
// auto& node = result.value();
|
// auto& node = result.value();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "matador/utils/identifier.hpp"
|
#include "matador/utils/identifier.hpp"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
|
|
||||||
|
|
@ -38,6 +39,8 @@ public:
|
||||||
[[nodiscard]] size_t constraint_count() const;
|
[[nodiscard]] size_t constraint_count() const;
|
||||||
[[nodiscard]] const std::list<class constraint>& constraints() const;
|
[[nodiscard]] const std::list<class constraint>& constraints() const;
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const object& obj);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class constraints_generator;
|
friend class constraints_generator;
|
||||||
friend class attribute_generator;
|
friend class attribute_generator;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public:
|
||||||
using create_func = std::function<std::unique_ptr<Type>()>;
|
using create_func = std::function<std::unique_ptr<Type>()>;
|
||||||
|
|
||||||
object_info(const std::shared_ptr<repository_node>& node,
|
object_info(const std::shared_ptr<repository_node>& node,
|
||||||
std::unique_ptr<object> &&obj,
|
std::unique_ptr<class object> &&obj,
|
||||||
create_func&& creator)
|
create_func&& creator)
|
||||||
: basic_object_info(node, std::move(obj))
|
: basic_object_info(node, std::move(obj))
|
||||||
, creator_(std::move(creator)){
|
, creator_(std::move(creator)){
|
||||||
|
|
|
||||||
|
|
@ -186,28 +186,28 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &,
|
||||||
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, foreign_node);
|
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, foreign_node);
|
||||||
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
|
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
|
||||||
} else {
|
} else {
|
||||||
// A relation table is necessary
|
// A relation table is necessary
|
||||||
// Endpoint was not found.
|
// Endpoint was not found.
|
||||||
// Always attach a many-to-many relation type. If later a
|
// Always attach a many-to-many relation type. If later a
|
||||||
// belongs-to relation handles this relation, the many-to-many
|
// belongs-to relation handles this relation, the many-to-many
|
||||||
// relation is maybe detached.
|
// relation is maybe detached.
|
||||||
log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column);
|
log_.debug("node '%s' has has many foreign keys '%s' mapped by '%s'", nodes_.top()->name().c_str(), id, join_column);
|
||||||
result = repository_node::make_relation_node<relation_value_type>(
|
auto node = repository_node::make_node<relation_value_type>(schema_.repo(), id, [join_column] {
|
||||||
schema_.repo(), id, [join_column] {
|
return std::make_unique<relation_value_type>("id", join_column);
|
||||||
return std::make_unique<relation_value_type>("id", join_column);
|
});
|
||||||
});
|
result = schema_.attach_node(node);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// Todo: throw internal error
|
// Todo: throw internal error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, result.value());
|
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
|
||||||
const auto foreign_endpoint = std::make_shared<relation_endpoint>("id", relation_type::BelongsTo, nodes_.top());
|
const auto foreign_endpoint = std::make_shared<relation_endpoint>("id", relation_type::BelongsTo, nodes_.top());
|
||||||
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
|
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
|
||||||
result.value()->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
|
node->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
|
||||||
link_relation_endpoints(local_endpoint, foreign_endpoint);
|
link_relation_endpoints(local_endpoint, foreign_endpoint);
|
||||||
|
|
||||||
const auto foreign_value_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, foreign_node);
|
const auto foreign_value_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, foreign_node);
|
||||||
result.value()->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint);
|
node->info_->register_relation_endpoint(typeid(value_type), foreign_value_endpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,21 +220,20 @@ void relation_completer<Type>::on_has_many(const char *id, CollectionType &, con
|
||||||
using value_type = typename CollectionType::value_type;
|
using value_type = typename CollectionType::value_type;
|
||||||
using relation_value_type = many_to_relation<Type, value_type>;
|
using relation_value_type = many_to_relation<Type, value_type>;
|
||||||
|
|
||||||
const auto result = repository_node::make_relation_node<relation_value_type>(
|
auto node = repository_node::make_node<relation_value_type>(schema_.repo(), id, [join_column] {
|
||||||
schema_.repo(), id, [join_column] {
|
return std::make_unique<relation_value_type>(join_column, "value");
|
||||||
return std::make_unique<relation_value_type>(join_column, "value");
|
});
|
||||||
});
|
const auto result = schema_.attach_node(node);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// Todo: throw internal exception
|
// Todo: throw internal exception
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, result.value());
|
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
|
||||||
const auto foreign_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, nodes_.top());
|
const auto foreign_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, nodes_.top());
|
||||||
|
|
||||||
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
|
nodes_.top()->info_->register_relation_endpoint(typeid(value_type), local_endpoint);
|
||||||
result.value()->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
|
node->info_->register_relation_endpoint(nodes_.top()->type_index(), foreign_endpoint);
|
||||||
link_relation_endpoints(local_endpoint, foreign_endpoint);
|
link_relation_endpoints(local_endpoint, foreign_endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,13 +264,13 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
|
||||||
return std::make_unique<relation_value_type>(join_column, inverse_join_column);
|
return std::make_unique<relation_value_type>(join_column, inverse_join_column);
|
||||||
};
|
};
|
||||||
|
|
||||||
result = repository_node::make_relation_node<relation_value_type>(schema_.repo(), id, std::move(creator));
|
auto node = repository_node::make_node<relation_value_type>(schema_.repo(), id, std::move(creator));
|
||||||
|
result = schema_.attach_node(node);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// Todo: throw internal error
|
// Todo: throw internal error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& node = result.value();
|
|
||||||
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
|
const auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HasMany, node);
|
||||||
const auto join_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, nodes_.top());
|
const auto join_endpoint = std::make_shared<relation_endpoint>(join_column, relation_type::BelongsTo, nodes_.top());
|
||||||
const auto inverse_join_endpoint = std::make_shared<relation_endpoint>(inverse_join_column, relation_type::BelongsTo, foreign_node);
|
const auto inverse_join_endpoint = std::make_shared<relation_endpoint>(inverse_join_column, relation_type::BelongsTo, foreign_node);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include "matador/object/attribute_generator.hpp"
|
#include "matador/object/attribute_generator.hpp"
|
||||||
#include "matador/object/object_generator.hpp"
|
#include "matador/object/object_generator.hpp"
|
||||||
#include "matador/object/object_info.hpp"
|
#include "matador/object/object_info.hpp"
|
||||||
#include "matador/object/primary_key_resolver.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
@ -16,42 +15,24 @@ class repository;
|
||||||
class repository_node final {
|
class repository_node final {
|
||||||
public:
|
public:
|
||||||
using node_ptr = std::shared_ptr<repository_node>;
|
using node_ptr = std::shared_ptr<repository_node>;
|
||||||
|
template< typename Type>
|
||||||
|
using creator_func = std::function<std::unique_ptr<Type>()>;
|
||||||
|
|
||||||
template < typename Type >
|
template < typename Type >
|
||||||
static std::shared_ptr<repository_node> make_node(repository& repo, const std::string& name) {
|
static std::shared_ptr<repository_node> make_node(repository& repo, const std::string& name, creator_func<Type> creator = []{ return std::make_unique<Type>(); }) {
|
||||||
auto node = std::shared_ptr<repository_node>(new repository_node(repo, name, typeid(Type)));
|
auto node = std::shared_ptr<repository_node>(new repository_node(repo, name, typeid(Type)));
|
||||||
|
|
||||||
primary_key_resolver resolver;
|
auto obj = object_generator::generate<Type>(creator(), repo, name);
|
||||||
auto pk_info = resolver.resolve<Type>();
|
|
||||||
auto obj = object_generator::generate<Type>(repo, name);
|
|
||||||
auto info = std::make_unique<object_info<Type>>(
|
auto info = std::make_unique<object_info<Type>>(
|
||||||
node,
|
node,
|
||||||
std::move(obj),
|
std::move(obj),
|
||||||
[]{ return std::make_unique<Type>(); }
|
std::forward<creator_func<Type>>(creator)
|
||||||
);
|
);
|
||||||
node->info_ = std::move(info);
|
node->info_ = std::move(info);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename Type, typename CreatorFunc >
|
|
||||||
static utils::result<node_ptr, utils::error> make_relation_node(repository& repo, const std::string& name, CreatorFunc &&creator) {
|
|
||||||
const auto result = make_and_attach_node(repo, name, typeid(Type));
|
|
||||||
if (!result) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto obj = object_generator::generate(creator(), repo, name);
|
|
||||||
auto info = std::make_unique<object_info<Type>>(
|
|
||||||
result.value(),
|
|
||||||
std::move(obj),
|
|
||||||
std::forward<CreatorFunc>(creator)
|
|
||||||
);
|
|
||||||
result.value()->info_ = std::move(info);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::shared_ptr<repository_node> make_null_node(repository& repo);
|
static std::shared_ptr<repository_node> make_null_node(repository& repo);
|
||||||
|
|
||||||
repository_node(const repository_node& other) = delete;
|
repository_node(const repository_node& other) = delete;
|
||||||
|
|
@ -87,10 +68,6 @@ private:
|
||||||
void unlink();
|
void unlink();
|
||||||
|
|
||||||
static utils::result<node_ptr, utils::error> make_and_attach_node(repository& repo, const std::string& name, const std::type_index& ti);
|
static utils::result<node_ptr, utils::error> make_and_attach_node(repository& repo, const std::string& name, const std::type_index& ti);
|
||||||
static attribute* determine_reference_column(const std::type_index& ti,
|
|
||||||
const std::string& table_name,
|
|
||||||
const primary_key_info& pk_info,
|
|
||||||
repository& repo);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class repository;
|
friend class repository;
|
||||||
|
|
|
||||||
|
|
@ -243,23 +243,23 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
data_type_to_string_map data_types_ {
|
data_type_to_string_map data_types_ {
|
||||||
{utils::basic_type::type_int8, "TINYINT"},
|
{utils::basic_type::Int8, "TINYINT"},
|
||||||
{utils::basic_type::type_int16, "SMALLINT"},
|
{utils::basic_type::Int16, "SMALLINT"},
|
||||||
{utils::basic_type::type_int32, "INTEGER"},
|
{utils::basic_type::Int32, "INTEGER"},
|
||||||
{utils::basic_type::type_int64, "BIGINT"},
|
{utils::basic_type::Int64, "BIGINT"},
|
||||||
{utils::basic_type::type_uint8, "TINYINT"},
|
{utils::basic_type::UInt8, "TINYINT"},
|
||||||
{utils::basic_type::type_uint16, "INTEGER"},
|
{utils::basic_type::UInt16, "INTEGER"},
|
||||||
{utils::basic_type::type_uint32, "BIGINT"},
|
{utils::basic_type::UInt32, "BIGINT"},
|
||||||
{utils::basic_type::type_uint64, "BIGINT"},
|
{utils::basic_type::UInt64, "BIGINT"},
|
||||||
{utils::basic_type::type_float, "FLOAT"},
|
{utils::basic_type::Float, "FLOAT"},
|
||||||
{utils::basic_type::type_double, "DOUBLE"},
|
{utils::basic_type::Double, "DOUBLE"},
|
||||||
{utils::basic_type::type_bool, "BOOLEAN"},
|
{utils::basic_type::Boolean, "BOOLEAN"},
|
||||||
{utils::basic_type::type_varchar, "VARCHAR"},
|
{utils::basic_type::Varchar, "VARCHAR"},
|
||||||
{utils::basic_type::type_text, "TEXT"},
|
{utils::basic_type::Text, "TEXT"},
|
||||||
{utils::basic_type::type_date, "DATE"},
|
{utils::basic_type::Date, "DATE"},
|
||||||
{utils::basic_type::type_time, "DATETIME"},
|
{utils::basic_type::Time, "DATETIME"},
|
||||||
{utils::basic_type::type_blob, "BLOB"},
|
{utils::basic_type::Blob, "BLOB"},
|
||||||
{utils::basic_type::type_null, "NULL"}
|
{utils::basic_type::Null, "NULL"}
|
||||||
};
|
};
|
||||||
|
|
||||||
sql_func_to_string_map sql_func_map_ {
|
sql_func_to_string_map sql_func_map_ {
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,24 @@ namespace matador::utils {
|
||||||
* @brief Enumeration type of all supported basic data types
|
* @brief Enumeration type of all supported basic data types
|
||||||
*/
|
*/
|
||||||
enum class basic_type : uint8_t {
|
enum class basic_type : uint8_t {
|
||||||
type_int8 = 0, /*!< Data type int8 */
|
Int8 = 0, /*!< Data type int8 */
|
||||||
type_int16, /*!< Data type int16 */
|
Int16, /*!< Data type int16 */
|
||||||
type_int32, /*!< Data type int32 */
|
Int32, /*!< Data type int32 */
|
||||||
type_int64, /*!< Data type int64 */
|
Int64, /*!< Data type int64 */
|
||||||
type_uint8, /*!< Data type unsigned int8 */
|
UInt8, /*!< Data type unsigned int8 */
|
||||||
type_uint16, /*!< Data type unsigned int16 */
|
UInt16, /*!< Data type unsigned int16 */
|
||||||
type_uint32, /*!< Data type unsigned int32 */
|
UInt32, /*!< Data type unsigned int32 */
|
||||||
type_uint64, /*!< Data type unsigned int64 */
|
UInt64, /*!< Data type unsigned int64 */
|
||||||
type_float, /*!< Data type float */
|
Float, /*!< Data type float */
|
||||||
type_double, /*!< Data type double */
|
Double, /*!< Data type double */
|
||||||
type_bool, /*!< Data type bool */
|
Boolean, /*!< Data type bool */
|
||||||
type_varchar, /*!< Data type varchar */
|
Varchar, /*!< Data type varchar */
|
||||||
type_text, /*!< Data type text */
|
Text, /*!< Data type text */
|
||||||
type_date, /*!< Data type date */
|
Date, /*!< Data type date */
|
||||||
type_time, /*!< Data type time */
|
Time, /*!< Data type time */
|
||||||
type_blob, /*!< Data type blob */
|
Blob, /*!< Data type blob */
|
||||||
type_null, /*!< Data type null */
|
Null, /*!< Data type null */
|
||||||
type_unknown /*!< Data type unknown */
|
Unknown /*!< Data type unknown */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class attribute_writer;
|
||||||
*/
|
*/
|
||||||
template < class Type, class Enable = void >
|
template < class Type, class Enable = void >
|
||||||
struct data_type_traits {
|
struct data_type_traits {
|
||||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_unknown; }
|
static basic_type type(std::size_t /*size*/) { return basic_type::Unknown; }
|
||||||
static void read_value(attribute_reader &/*reader*/, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0) {}
|
static void read_value(attribute_reader &/*reader*/, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0) {}
|
||||||
static void bind_value(attribute_writer &/*binder*/, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0) {}
|
static void bind_value(attribute_writer &/*binder*/, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0) {}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,105 +12,105 @@ namespace matador::utils {
|
||||||
/// @cond MATADOR_DEV
|
/// @cond MATADOR_DEV
|
||||||
template <> struct data_type_traits<nullptr_t, void>
|
template <> struct data_type_traits<nullptr_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_null; }
|
static basic_type type(std::size_t /*size*/) { return basic_type::Null; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, nullptr_t &/*value*/, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<int8_t, void>
|
template <> struct data_type_traits<int8_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int8; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int8; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int8_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, int8_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const int8_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const int8_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<int16_t, void>
|
template <> struct data_type_traits<int16_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int16; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int16; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int16_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, int16_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const int16_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const int16_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<int32_t, void>
|
template <> struct data_type_traits<int32_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int32; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int32; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int32_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, int32_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const int32_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const int32_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<int64_t, void>
|
template <> struct data_type_traits<int64_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int64; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int64; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, int64_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, int64_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const int64_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const int64_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<uint8_t, void>
|
template <> struct data_type_traits<uint8_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint8; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt8; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint8_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, uint8_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const uint8_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const uint8_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<uint16_t, void>
|
template <> struct data_type_traits<uint16_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint16; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt16; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint16_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, uint16_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const uint16_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const uint16_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<uint32_t, void>
|
template <> struct data_type_traits<uint32_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint32; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt32; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint32_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, uint32_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const uint32_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const uint32_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<uint64_t, void>
|
template <> struct data_type_traits<uint64_t, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_uint64; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::UInt64; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, uint64_t &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, uint64_t &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const uint64_t &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const uint64_t &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<bool, void>
|
template <> struct data_type_traits<bool, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_bool; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Boolean; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, bool &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, bool &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const bool &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const bool &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<float, void>
|
template <> struct data_type_traits<float, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_float; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Float; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, float &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, float &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const float &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const float &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<double, void>
|
template <> struct data_type_traits<double, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_double; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Double; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, double &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, double &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const double &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const double &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<const char*, void>
|
template <> struct data_type_traits<const char*, void>
|
||||||
{
|
{
|
||||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, const char* value, size_t size);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, const char* value, size_t size);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const char *value, size_t size = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const char *value, size_t size = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<char*, void>
|
template <> struct data_type_traits<char*, void>
|
||||||
{
|
{
|
||||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, char *value, size_t size);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, char *value, size_t size);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, const char *value, size_t size = 0);
|
static void bind_value(attribute_writer &binder, size_t index, const char *value, size_t size = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<char[], void>
|
template <> struct data_type_traits<char[], void>
|
||||||
{
|
{
|
||||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||||
template < int N >
|
template < int N >
|
||||||
static void read_value(attribute_reader &reader, const char *id, const size_t index, char (&value)[N], const size_t size) {
|
static void read_value(attribute_reader &reader, const char *id, const size_t index, char (&value)[N], const size_t size) {
|
||||||
data_type_traits<const char*>::read_value(reader, id, index, value, size);
|
data_type_traits<const char*>::read_value(reader, id, index, value, size);
|
||||||
|
|
@ -123,14 +123,14 @@ template <> struct data_type_traits<char[], void>
|
||||||
|
|
||||||
template <> struct data_type_traits<std::string, void>
|
template <> struct data_type_traits<std::string, void>
|
||||||
{
|
{
|
||||||
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::type_text : basic_type::type_varchar; }
|
static basic_type type(const std::size_t size) { return size == 0 ? basic_type::Text : basic_type::Varchar; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, std::string &value, size_t size);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, std::string &value, size_t size);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, std::string &value, size_t size = 0);
|
static void bind_value(attribute_writer &binder, size_t index, std::string &value, size_t size = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct data_type_traits<utils::blob, void>
|
template <> struct data_type_traits<utils::blob, void>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/) { return basic_type::type_blob; }
|
static basic_type type(std::size_t /*size*/) { return basic_type::Blob; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob &value, size_t /*size*/ = 0);
|
static void read_value(attribute_reader &reader, const char *id, size_t index, utils::blob &value, size_t /*size*/ = 0);
|
||||||
static void bind_value(attribute_writer &binder, size_t index, utils::blob &value, size_t /*size*/ = 0);
|
static void bind_value(attribute_writer &binder, size_t index, utils::blob &value, size_t /*size*/ = 0);
|
||||||
};
|
};
|
||||||
|
|
@ -152,7 +152,7 @@ template <> struct data_type_traits<utils::blob, void>
|
||||||
template < typename EnumType >
|
template < typename EnumType >
|
||||||
struct data_type_traits<EnumType, std::enable_if_t<std::is_enum_v<EnumType>>>
|
struct data_type_traits<EnumType, std::enable_if_t<std::is_enum_v<EnumType>>>
|
||||||
{
|
{
|
||||||
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::type_int32; }
|
static basic_type type(std::size_t /*size*/ = 0) { return basic_type::Int32; }
|
||||||
static void read_value(attribute_reader &reader, const char *id, const size_t index, EnumType &value, const size_t size = 0) {
|
static void read_value(attribute_reader &reader, const char *id, const size_t index, EnumType &value, const size_t size = 0) {
|
||||||
data_type_traits<int>::read_value(reader, id, index, reinterpret_cast<int&>(value), size);
|
data_type_traits<int>::read_value(reader, id, index, reinterpret_cast<int&>(value), size);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ private:
|
||||||
[[nodiscard]] virtual size_t hash() const = 0;
|
[[nodiscard]] virtual size_t hash() const = 0;
|
||||||
|
|
||||||
std::type_index type_index_;
|
std::type_index type_index_;
|
||||||
basic_type type_{basic_type::type_null};
|
basic_type type_{basic_type::Null};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class IdType>
|
template<class IdType>
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ public:
|
||||||
private:
|
private:
|
||||||
utils::database_type value_;
|
utils::database_type value_;
|
||||||
size_t size_{};
|
size_t size_{};
|
||||||
basic_type type_{basic_type::type_null};
|
basic_type type_{basic_type::Null};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
attribute::attribute(std::string name)
|
attribute::attribute(std::string name)
|
||||||
: attribute(std::move(name), utils::basic_type::type_null, {}, null_option_type::NotNull) {
|
: attribute(std::move(name), utils::basic_type::Null, {}, null_option_type::NotNull) {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute::attribute(std::string name,
|
attribute::attribute(std::string name,
|
||||||
|
|
@ -57,80 +57,44 @@ void attribute::change_type(const utils::basic_type type, const utils::field_att
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_integer() const {
|
bool attribute::is_integer() const {
|
||||||
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
|
return type_ >= utils::basic_type::Int8 && type_ <= utils::basic_type::UInt64;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_floating_point() const {
|
bool attribute::is_floating_point() const {
|
||||||
return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double;
|
return type_ == utils::basic_type::Float || type_ == utils::basic_type::Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_bool() const {
|
bool attribute::is_bool() const {
|
||||||
return type_ == utils::basic_type::type_bool;
|
return type_ == utils::basic_type::Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_string() const {
|
bool attribute::is_string() const {
|
||||||
return type_ == utils::basic_type::type_text;
|
return type_ == utils::basic_type::Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_varchar() const {
|
bool attribute::is_varchar() const {
|
||||||
return type_ == utils::basic_type::type_varchar;
|
return type_ == utils::basic_type::Varchar;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_date() const {
|
bool attribute::is_date() const {
|
||||||
return type_ == utils::basic_type::type_date;
|
return type_ == utils::basic_type::Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_time() const {
|
bool attribute::is_time() const {
|
||||||
return type_ == utils::basic_type::type_time;
|
return type_ == utils::basic_type::Time;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_blob() const {
|
bool attribute::is_blob() const {
|
||||||
return type_ == utils::basic_type::type_blob;
|
return type_ == utils::basic_type::Blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool attribute::is_null() const {
|
bool attribute::is_null() const {
|
||||||
return type_ == utils::basic_type::type_null;
|
return type_ == utils::basic_type::Null;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream & operator<<(std::ostream &os, const attribute &attr) {
|
||||||
|
os << attr.name_;
|
||||||
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
// attribute make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr,
|
|
||||||
// null_option_type null_opt) {
|
|
||||||
// return {name, type, attr, null_opt};
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template<>
|
|
||||||
// attribute make_column<std::string>(const std::string &name, utils::field_attributes attr,
|
|
||||||
// null_option_type null_opt) {
|
|
||||||
// return make_column(name, utils::data_type_traits<std::string>::type(attr.size()), attr, null_opt);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template<>
|
|
||||||
// attribute make_pk_column<std::string>(const std::string &name, size_t size) {
|
|
||||||
// return make_column<std::string>(name, {size, utils::constraints::PrimaryKey});
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template<>
|
|
||||||
// attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column) {
|
|
||||||
// return {
|
|
||||||
// name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
|
||||||
// {size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template<>
|
|
||||||
// attribute make_fk_column<std::string>( const std::string& name, const std::string& ref_table_name, const std::string& ref_column_name ) {
|
|
||||||
// return {
|
|
||||||
// name, utils::basic_type::type_varchar, 0,
|
|
||||||
// std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey}),
|
|
||||||
// { 0, utils::constraints::ForeignKey }, null_option_type::NOT_NULL
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// template<>
|
|
||||||
// attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
|
|
||||||
// const auto ref_column = std::make_shared<attribute>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::ForeignKey});
|
|
||||||
// return {
|
|
||||||
// name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
|
||||||
// {size, utils::constraints::ForeignKey}, null_option_type::NOT_NULL
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace matador::object {
|
||||||
// : node_(std::move(node))
|
// : node_(std::move(node))
|
||||||
// , attributes_(attributes) {}
|
// , attributes_(attributes) {}
|
||||||
|
|
||||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<object>&& obj)
|
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<class object>&& obj)
|
||||||
: object_(std::move(obj))
|
: object_(std::move(obj))
|
||||||
, node_(std::move(node)) {}
|
, node_(std::move(node)) {}
|
||||||
|
|
||||||
|
|
@ -32,6 +32,10 @@ std::string basic_object_info::name() const {
|
||||||
return node_->name();
|
return node_->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const class object & basic_object_info::object() const {
|
||||||
|
return *object_;
|
||||||
|
}
|
||||||
|
|
||||||
const std::list<attribute>& basic_object_info::attributes() const {
|
const std::list<attribute>& basic_object_info::attributes() const {
|
||||||
return object_->attributes();
|
return object_->attributes();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,11 @@ const std::string& constraint::ref_column_name() const {
|
||||||
return ref_column_name_;
|
return ref_column_name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream & operator<<(std::ostream &os, const class constraint &c) {
|
||||||
|
os << "constraint " << c.name_ << " for column " << c.column_name();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
constraint_builder & constraint_builder::constraint(std::string name) {
|
constraint_builder & constraint_builder::constraint(std::string name) {
|
||||||
constraint_name = std::move(name);
|
constraint_name = std::move(name);
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
||||||
|
|
@ -75,4 +75,17 @@ size_t object::constraint_count() const {
|
||||||
const std::list<class constraint>& object::constraints() const {
|
const std::list<class constraint>& object::constraints() const {
|
||||||
return constraints_;
|
return constraints_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream & operator<<(std::ostream &os, const object &obj) {
|
||||||
|
os << "Object " << obj.name_ << "\nAttributes:\n";
|
||||||
|
for (const auto &attr : obj.attributes_) {
|
||||||
|
os << " " << attr << "\n";
|
||||||
|
}
|
||||||
|
os << "Constraints:\n";
|
||||||
|
for (const auto &con : obj.constraints_) {
|
||||||
|
os << " " << con << "\n";
|
||||||
|
}
|
||||||
|
os << "\n";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ repository_node::repository_node(repository &repo, std::string name, const std::
|
||||||
|
|
||||||
std::shared_ptr<repository_node> repository_node::make_null_node(repository &repo) {
|
std::shared_ptr<repository_node> repository_node::make_null_node(repository &repo) {
|
||||||
auto node = std::shared_ptr<repository_node>(new repository_node(repo));
|
auto node = std::shared_ptr<repository_node>(new repository_node(repo));
|
||||||
node->info_ = std::make_unique<null_info>(node/*, std::shared_ptr<attribute_definition>{}*/);
|
node->info_ = std::make_unique<null_info>(node);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
@ -101,27 +101,4 @@ utils::result<repository_node::node_ptr, utils::error> repository_node::make_and
|
||||||
|
|
||||||
return repo.attach_node(node, "");
|
return repo.attach_node(node, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute* repository_node::determine_reference_column(const std::type_index& ti,
|
|
||||||
const std::string& table_name,
|
|
||||||
const primary_key_info& pk_info,
|
|
||||||
repository& repo) {
|
|
||||||
const auto it = repo.missing_references_.find(ti);
|
|
||||||
if (it == repo.missing_references_.end()) {
|
|
||||||
return new attribute(pk_info.pk_column_name, pk_info.type, {utils::constraints::ForeignKey}, null_option_type::NotNull);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ref_column = it->second;
|
|
||||||
repo.missing_references_.erase(it);
|
|
||||||
ref_column->name(pk_info.pk_column_name);
|
|
||||||
ref_column->owner()->update_name(table_name);
|
|
||||||
ref_column->change_type(pk_info.type);
|
|
||||||
ref_column->attributes() = utils::constraints::ForeignKey;
|
|
||||||
|
|
||||||
if (table_name.empty()) {
|
|
||||||
repo.missing_references_.insert({ti, ref_column});
|
|
||||||
}
|
|
||||||
|
|
||||||
return ref_column;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ identifier::base::base(const std::type_index &ti, const basic_type type)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
identifier::null_pk::null_pk()
|
identifier::null_pk::null_pk()
|
||||||
: base(std::type_index(typeid(null_type_t)), basic_type::type_null)
|
: base(std::type_index(typeid(null_type_t)), basic_type::Null)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
identifier::base* identifier::null_pk::copy() const
|
identifier::base* identifier::null_pk::copy() const
|
||||||
|
|
@ -134,31 +134,31 @@ size_t identifier::use_count() const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_integer() const {
|
bool identifier::is_integer() const {
|
||||||
return id_->type_ >= basic_type::type_int8 && id_->type_ <= basic_type::type_uint64;
|
return id_->type_ >= basic_type::Int8 && id_->type_ <= basic_type::UInt64;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_floating_point() const {
|
bool identifier::is_floating_point() const {
|
||||||
return id_->type_ == basic_type::type_float || id_->type_ == basic_type::type_double;
|
return id_->type_ == basic_type::Float || id_->type_ == basic_type::Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_bool() const {
|
bool identifier::is_bool() const {
|
||||||
return id_->type_ == basic_type::type_bool;
|
return id_->type_ == basic_type::Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_varchar() const {
|
bool identifier::is_varchar() const {
|
||||||
return id_->type_ == basic_type::type_varchar;
|
return id_->type_ == basic_type::Varchar;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_date() const {
|
bool identifier::is_date() const {
|
||||||
return id_->type_ == basic_type::type_date;
|
return id_->type_ == basic_type::Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_time() const {
|
bool identifier::is_time() const {
|
||||||
return id_->type_ == basic_type::type_time;
|
return id_->type_ == basic_type::Time;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_blob() const {
|
bool identifier::is_blob() const {
|
||||||
return id_->type_ == basic_type::type_blob;
|
return id_->type_ == basic_type::Blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool identifier::is_null() const
|
bool identifier::is_null() const
|
||||||
|
|
|
||||||
|
|
@ -6,41 +6,41 @@ namespace matador::utils {
|
||||||
void initialize_by_basic_type(const basic_type type, database_type &val)
|
void initialize_by_basic_type(const basic_type type, database_type &val)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case basic_type::type_int8:
|
case basic_type::Int8:
|
||||||
val.emplace<int8_t>();
|
val.emplace<int8_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_int16:
|
case basic_type::Int16:
|
||||||
val.emplace<int16_t>();
|
val.emplace<int16_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_int32:
|
case basic_type::Int32:
|
||||||
val.emplace<int32_t>();
|
val.emplace<int32_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_int64:
|
case basic_type::Int64:
|
||||||
val.emplace<int64_t>();
|
val.emplace<int64_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint8:
|
case basic_type::UInt8:
|
||||||
val.emplace<uint8_t>();
|
val.emplace<uint8_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint16:
|
case basic_type::UInt16:
|
||||||
val.emplace<uint16_t>();
|
val.emplace<uint16_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint32:
|
case basic_type::UInt32:
|
||||||
val.emplace<uint32_t>();
|
val.emplace<uint32_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint64:
|
case basic_type::UInt64:
|
||||||
val.emplace<uint64_t>();
|
val.emplace<uint64_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_bool:
|
case basic_type::Boolean:
|
||||||
val.emplace<bool>();
|
val.emplace<bool>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_float:
|
case basic_type::Float:
|
||||||
val.emplace<float>();
|
val.emplace<float>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_double:
|
case basic_type::Double:
|
||||||
val.emplace<double>();
|
val.emplace<double>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_varchar:
|
case basic_type::Varchar:
|
||||||
case basic_type::type_text:
|
case basic_type::Text:
|
||||||
val.emplace<std::string>();
|
val.emplace<std::string>();
|
||||||
break;
|
break;
|
||||||
// case basic_type::type_date:
|
// case basic_type::type_date:
|
||||||
|
|
@ -49,7 +49,7 @@ void initialize_by_basic_type(const basic_type type, database_type &val)
|
||||||
// case basic_type::type_time:
|
// case basic_type::type_time:
|
||||||
// val.emplace<time>();
|
// val.emplace<time>();
|
||||||
// break;
|
// break;
|
||||||
case basic_type::type_blob:
|
case basic_type::Blob:
|
||||||
val.emplace<utils::blob>();
|
val.emplace<utils::blob>();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ value::value(value &&x) noexcept
|
||||||
, type_(x.type_)
|
, type_(x.type_)
|
||||||
{
|
{
|
||||||
x.value_ = nullptr;
|
x.value_ = nullptr;
|
||||||
x.type_ = basic_type::type_null;
|
x.type_ = basic_type::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
value &value::operator=(value &&x) noexcept
|
value &value::operator=(value &&x) noexcept
|
||||||
|
|
@ -40,7 +40,7 @@ value &value::operator=(value &&x) noexcept
|
||||||
value_ = std::move(x.value_);
|
value_ = std::move(x.value_);
|
||||||
type_ = x.type_;
|
type_ = x.type_;
|
||||||
x.value_ = nullptr;
|
x.value_ = nullptr;
|
||||||
x.type_ = basic_type::type_null;
|
x.type_ = basic_type::Null;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -66,87 +66,87 @@ void value::type(const basic_type t) {
|
||||||
|
|
||||||
bool value::is_integer() const
|
bool value::is_integer() const
|
||||||
{
|
{
|
||||||
return type_ >= basic_type::type_int8 && type_ <= basic_type::type_uint64;
|
return type_ >= basic_type::Int8 && type_ <= basic_type::UInt64;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_floating_point() const
|
bool value::is_floating_point() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_float || type_ == basic_type::type_double;
|
return type_ == basic_type::Float || type_ == basic_type::Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_bool() const
|
bool value::is_bool() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_bool;
|
return type_ == basic_type::Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_string() const
|
bool value::is_string() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_text;
|
return type_ == basic_type::Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_varchar() const
|
bool value::is_varchar() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_varchar;
|
return type_ == basic_type::Varchar;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_date() const
|
bool value::is_date() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_date;
|
return type_ == basic_type::Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_time() const
|
bool value::is_time() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_time;
|
return type_ == basic_type::Time;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_blob() const
|
bool value::is_blob() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_blob;
|
return type_ == basic_type::Blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value::is_null() const
|
bool value::is_null() const
|
||||||
{
|
{
|
||||||
return type_ == basic_type::type_null;
|
return type_ == basic_type::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
void initialize_by_basic_type(const basic_type type, database_type &val) {
|
void initialize_by_basic_type(const basic_type type, database_type &val) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case basic_type::type_int8:
|
case basic_type::Int8:
|
||||||
val.emplace<int8_t>();
|
val.emplace<int8_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_int16:
|
case basic_type::Int16:
|
||||||
val.emplace<int16_t>();
|
val.emplace<int16_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_int32:
|
case basic_type::Int32:
|
||||||
val.emplace<int32_t>();
|
val.emplace<int32_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_int64:
|
case basic_type::Int64:
|
||||||
val.emplace<int64_t>();
|
val.emplace<int64_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint8:
|
case basic_type::UInt8:
|
||||||
val.emplace<uint8_t>();
|
val.emplace<uint8_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint16:
|
case basic_type::UInt16:
|
||||||
val.emplace<uint16_t>();
|
val.emplace<uint16_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint32:
|
case basic_type::UInt32:
|
||||||
val.emplace<uint32_t>();
|
val.emplace<uint32_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_uint64:
|
case basic_type::UInt64:
|
||||||
val.emplace<uint64_t>();
|
val.emplace<uint64_t>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_bool:
|
case basic_type::Boolean:
|
||||||
val.emplace<bool>();
|
val.emplace<bool>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_float:
|
case basic_type::Float:
|
||||||
val.emplace<float>();
|
val.emplace<float>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_double:
|
case basic_type::Double:
|
||||||
val.emplace<double>();
|
val.emplace<double>();
|
||||||
break;
|
break;
|
||||||
case basic_type::type_varchar:
|
case basic_type::Varchar:
|
||||||
case basic_type::type_text:
|
case basic_type::Text:
|
||||||
val.emplace<std::string>();
|
val.emplace<std::string>();
|
||||||
break;
|
break;
|
||||||
// case basic_type::type_date:
|
// case basic_type::type_date:
|
||||||
|
|
@ -155,7 +155,7 @@ void initialize_by_basic_type(const basic_type type, database_type &val) {
|
||||||
// case basic_type::type_time:
|
// case basic_type::type_time:
|
||||||
// val.emplace<time>();
|
// val.emplace<time>();
|
||||||
// break;
|
// break;
|
||||||
case basic_type::type_blob:
|
case basic_type::Blob:
|
||||||
val.emplace<utils::blob>();
|
val.emplace<utils::blob>();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ sql::query_context query_compiler::compile(const query_data &data,
|
||||||
std::string handle_column(sql::query_context &ctx, const sql::dialect *d, const query_data &data, const column &col) {
|
std::string handle_column(sql::query_context &ctx, const sql::dialect *d, const query_data &data, const column &col) {
|
||||||
if (col.is_function()) {
|
if (col.is_function()) {
|
||||||
ctx.prototype.emplace_back(col.has_alias() ? col.alias() : col.name());
|
ctx.prototype.emplace_back(col.has_alias() ? col.alias() : col.name());
|
||||||
ctx.prototype.back().change_type(utils::basic_type::type_int32);
|
ctx.prototype.back().change_type(utils::basic_type::Int32);
|
||||||
} else {
|
} else {
|
||||||
ctx.prototype.emplace_back(col.name());
|
ctx.prototype.emplace_back(col.name());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ utils::result<size_t, utils::error> connection::execute(const std::string &sql)
|
||||||
|
|
||||||
bool has_unknown_columns(const std::vector<object::attribute> &columns) {
|
bool has_unknown_columns(const std::vector<object::attribute> &columns) {
|
||||||
return std::any_of(std::begin(columns), std::end(columns), [](const auto &col) {
|
return std::any_of(std::begin(columns), std::end(columns), [](const auto &col) {
|
||||||
return col.type() == utils::basic_type::type_null;
|
return col.type() == utils::basic_type::Null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,7 +228,7 @@ utils::result<std::unique_ptr<statement_impl>, utils::error> connection::perform
|
||||||
std::end(*result),
|
std::end(*result),
|
||||||
[&col](const auto &value) { return value.name() == col.name(); }
|
[&col](const auto &value) { return value.name() == col.name(); }
|
||||||
);
|
);
|
||||||
if (col.type() == utils::basic_type::type_null && rit != result->end()) {
|
if (col.type() == utils::basic_type::Null && rit != result->end()) {
|
||||||
const_cast<object::attribute&>(col).change_type(rit->type());
|
const_cast<object::attribute&>(col).change_type(rit->type());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,8 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("quotes")
|
.table("quotes")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("from", basic_type::type_varchar, 255),
|
attribute("from", basic_type::Varchar, 255),
|
||||||
attribute("to", basic_type::type_varchar, 255)
|
attribute("to", basic_type::Varchar, 255)
|
||||||
})
|
})
|
||||||
.execute(db);
|
.execute(db);
|
||||||
REQUIRE(res.is_ok());
|
REQUIRE(res.is_ok());
|
||||||
|
|
@ -126,7 +126,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted identifier", "[query][quotes][ident
|
||||||
|
|
||||||
// check table description
|
// check table description
|
||||||
std::vector<std::string> column_names = { "from", "to"};
|
std::vector<std::string> column_names = { "from", "to"};
|
||||||
std::vector types = {basic_type::type_varchar, basic_type::type_varchar};
|
std::vector types = {basic_type::Varchar, basic_type::Varchar};
|
||||||
const auto columns = db.describe("quotes");
|
const auto columns = db.describe("quotes");
|
||||||
REQUIRE(columns.is_ok());
|
REQUIRE(columns.is_ok());
|
||||||
|
|
||||||
|
|
@ -192,7 +192,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("quotes")
|
.table("quotes")
|
||||||
.columns({
|
.columns({
|
||||||
attribute(name, basic_type::type_varchar, 255)
|
attribute(name, basic_type::Varchar, 255)
|
||||||
})
|
})
|
||||||
.execute(db);
|
.execute(db);
|
||||||
REQUIRE(res.is_ok());
|
REQUIRE(res.is_ok());
|
||||||
|
|
@ -203,7 +203,7 @@ TEST_CASE_METHOD( QueryFixture, "Test quoted column names", "[query][quotes][col
|
||||||
|
|
||||||
for (const auto &col : *columns) {
|
for (const auto &col : *columns) {
|
||||||
REQUIRE(col.name() == name);
|
REQUIRE(col.name() == name);
|
||||||
REQUIRE(col.type() == basic_type::type_varchar);
|
REQUIRE(col.type() == basic_type::Varchar);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = query::drop()
|
res = query::drop()
|
||||||
|
|
@ -221,7 +221,7 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted literals", "[query][quotes][literals
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("escapes")
|
.table("escapes")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("name", basic_type::type_varchar, 255)
|
attribute("name", basic_type::Varchar, 255)
|
||||||
})
|
})
|
||||||
.execute(db);
|
.execute(db);
|
||||||
REQUIRE(res.is_ok());
|
REQUIRE(res.is_ok());
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,23 @@ TEST_CASE_METHOD(QueryFixture, "Test all data types for record", "[query][record
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("types")
|
.table("types")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("val_char", basic_type::type_int8),
|
attribute("val_char", basic_type::Int8),
|
||||||
attribute("val_short", basic_type::type_int16),
|
attribute("val_short", basic_type::Int16),
|
||||||
attribute("val_int", basic_type::type_int32),
|
attribute("val_int", basic_type::Int32),
|
||||||
attribute("val_long_long", basic_type::type_int64),
|
attribute("val_long_long", basic_type::Int64),
|
||||||
attribute("val_uchar", basic_type::type_uint8),
|
attribute("val_uchar", basic_type::UInt8),
|
||||||
attribute("val_ushort", basic_type::type_uint16),
|
attribute("val_ushort", basic_type::UInt16),
|
||||||
attribute("val_uint", basic_type::type_uint32),
|
attribute("val_uint", basic_type::UInt32),
|
||||||
attribute("val_ulong_long", basic_type::type_uint64),
|
attribute("val_ulong_long", basic_type::UInt64),
|
||||||
attribute("val_bool", basic_type::type_bool),
|
attribute("val_bool", basic_type::Boolean),
|
||||||
attribute("val_float", basic_type::type_float),
|
attribute("val_float", basic_type::Float),
|
||||||
attribute("val_double", basic_type::type_double),
|
attribute("val_double", basic_type::Double),
|
||||||
attribute("val_string", basic_type::type_text),
|
attribute("val_string", basic_type::Text),
|
||||||
attribute("val_varchar", basic_type::type_varchar, 63),
|
attribute("val_varchar", basic_type::Varchar, 63),
|
||||||
// attribute("val_date", basic_type::type_date),
|
// attribute("val_date", basic_type::type_date),
|
||||||
// attribute("val_time", basic_type::type_time),
|
// attribute("val_time", basic_type::type_time),
|
||||||
attribute("val_blob", basic_type::type_blob),
|
attribute("val_blob", basic_type::Blob),
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_types").primary_key("id")
|
constraint("PK_types").primary_key("id")
|
||||||
|
|
@ -126,9 +126,9 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement", "[query][recor
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -154,9 +154,9 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("airplane")
|
.table("airplane")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("brand", basic_type::type_varchar, 255),
|
attribute("brand", basic_type::Varchar, 255),
|
||||||
attribute("model", basic_type::type_varchar, 255),
|
attribute("model", basic_type::Varchar, 255),
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_airplane").primary_key("id"),
|
constraint("PK_airplane").primary_key("id"),
|
||||||
|
|
@ -171,9 +171,9 @@ TEST_CASE_METHOD(QueryFixture, "Create and drop table statement with foreign key
|
||||||
res = query::create()
|
res = query::create()
|
||||||
.table("flight")
|
.table("flight")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("airplane_id", basic_type::type_uint32),
|
attribute("airplane_id", basic_type::UInt32),
|
||||||
attribute("pilot_name", basic_type::type_varchar, 255)
|
attribute("pilot_name", basic_type::Varchar, 255)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_flight").primary_key("id"),
|
constraint("PK_flight").primary_key("id"),
|
||||||
|
|
@ -208,9 +208,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement", "[query][recor
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -251,9 +251,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("airplane")
|
.table("airplane")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("brand", basic_type::type_varchar, 255),
|
attribute("brand", basic_type::Varchar, 255),
|
||||||
attribute("model", basic_type::type_varchar, 255),
|
attribute("model", basic_type::Varchar, 255),
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_airplane").primary_key("id"),
|
constraint("PK_airplane").primary_key("id"),
|
||||||
|
|
@ -266,9 +266,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert record statement with foreign key
|
||||||
res = query::create()
|
res = query::create()
|
||||||
.table("flight")
|
.table("flight")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("airplane_id", basic_type::type_uint32),
|
attribute("airplane_id", basic_type::UInt32),
|
||||||
attribute("pilot_name", basic_type::type_varchar, 255)
|
attribute("pilot_name", basic_type::Varchar, 255)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_flight").primary_key("id"),
|
constraint("PK_flight").primary_key("id"),
|
||||||
|
|
@ -314,9 +314,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute update record statement", "[query][recor
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -367,9 +367,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement", "[query][record]")
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -427,9 +427,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with order by", "[query
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -473,9 +473,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -526,9 +526,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute delete statement", "[query][record]") {
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -576,8 +576,8 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("quotes")
|
.table("quotes")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("from", basic_type::type_varchar, 255),
|
attribute("from", basic_type::Varchar, 255),
|
||||||
attribute("to", basic_type::type_varchar, 255)
|
attribute("to", basic_type::Varchar, 255)
|
||||||
})
|
})
|
||||||
.execute(db);
|
.execute(db);
|
||||||
REQUIRE(res.is_ok());
|
REQUIRE(res.is_ok());
|
||||||
|
|
@ -587,8 +587,8 @@ TEST_CASE_METHOD(QueryFixture, "Test quoted identifier record", "[query][record]
|
||||||
// check table description
|
// check table description
|
||||||
std::vector<std::string> columns = { "from", "to"};
|
std::vector<std::string> columns = { "from", "to"};
|
||||||
std::vector types = {
|
std::vector types = {
|
||||||
basic_type::type_varchar,
|
basic_type::Varchar,
|
||||||
basic_type::type_varchar
|
basic_type::Varchar
|
||||||
};
|
};
|
||||||
auto fields = db.describe("quotes");
|
auto fields = db.describe("quotes");
|
||||||
REQUIRE(fields.is_ok());
|
REQUIRE(fields.is_ok());
|
||||||
|
|
@ -637,9 +637,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create record", "[query][record][create]")
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -664,9 +664,9 @@ TEST_CASE_METHOD(QueryFixture, "Test insert record", "[query][record][insert]")
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -701,9 +701,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update record", "[query][record][update]")
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -755,9 +755,9 @@ TEST_CASE_METHOD(QueryFixture, "Test prepared record statement", "[query][record
|
||||||
auto stmt = query::create()
|
auto stmt = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
@ -785,7 +785,7 @@ TEST_CASE_METHOD(QueryFixture, "Test scalar result", "[query][record][scalar][re
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32)
|
attribute("id", basic_type::UInt32)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,9 @@ TEST_CASE_METHOD(QueryFixture, "Execute insert statement", "[query][insert]") {
|
||||||
auto res = query::create()
|
auto res = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", matador::utils::basic_type::type_uint32),
|
attribute("id", matador::utils::basic_type::UInt32),
|
||||||
attribute("name", matador::utils::basic_type::type_varchar, 255),
|
attribute("name", matador::utils::basic_type::Varchar, 255),
|
||||||
attribute("color", matador::utils::basic_type::type_varchar, 63)
|
attribute("color", matador::utils::basic_type::Varchar, 63)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key("id")
|
constraint("PK_person").primary_key("id")
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,15 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
|
||||||
auto columns = attribute_generator::generate<matador::test::product>(repo, obj);
|
auto columns = attribute_generator::generate<matador::test::product>(repo, obj);
|
||||||
|
|
||||||
const std::vector expected_columns = {
|
const std::vector expected_columns = {
|
||||||
attribute{"product_name", basic_type::type_varchar, constraints::PrimaryKey, null_option_type::NotNull },
|
attribute{"product_name", basic_type::Varchar, constraints::PrimaryKey, null_option_type::NotNull },
|
||||||
attribute{"supplier_id", basic_type::type_uint32, constraints::ForeignKey, null_option_type::NotNull },
|
attribute{"supplier_id", basic_type::UInt32, constraints::ForeignKey, null_option_type::NotNull },
|
||||||
attribute{"category_id", basic_type::type_uint32, constraints::ForeignKey, null_option_type::NotNull },
|
attribute{"category_id", basic_type::UInt32, constraints::ForeignKey, null_option_type::NotNull },
|
||||||
attribute{"quantity_per_unit", basic_type::type_varchar, null_attributes, null_option_type::NotNull },
|
attribute{"quantity_per_unit", basic_type::Varchar, null_attributes, null_option_type::NotNull },
|
||||||
attribute{"unit_price", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
attribute{"unit_price", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||||
attribute{"units_in_stock", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
attribute{"units_in_stock", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||||
attribute{"units_in_order", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
attribute{"units_in_order", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||||
attribute{"reorder_level", basic_type::type_uint32, null_attributes, null_option_type::NotNull },
|
attribute{"reorder_level", basic_type::UInt32, null_attributes, null_option_type::NotNull },
|
||||||
attribute{"discontinued", basic_type::type_bool, null_attributes, null_option_type::NotNull }
|
attribute{"discontinued", basic_type::Boolean, null_attributes, null_option_type::NotNull }
|
||||||
};
|
};
|
||||||
REQUIRE(!columns.empty());
|
REQUIRE(!columns.empty());
|
||||||
REQUIRE(columns.size() == expected_columns.size());
|
REQUIRE(columns.size() == expected_columns.size());
|
||||||
|
|
@ -49,9 +49,9 @@ TEST_CASE("Generate columns from object with nullable columns", "[column generat
|
||||||
auto columns = attribute_generator::generate<matador::test::optional>(repo, obj);
|
auto columns = attribute_generator::generate<matador::test::optional>(repo, obj);
|
||||||
|
|
||||||
const std::vector expected_columns = {
|
const std::vector expected_columns = {
|
||||||
attribute{"id", basic_type::type_uint32, constraints::PrimaryKey, null_option_type::NotNull },
|
attribute{"id", basic_type::UInt32, constraints::PrimaryKey, null_option_type::NotNull },
|
||||||
attribute{"name", basic_type::type_varchar, null_attributes, null_option_type::NotNull },
|
attribute{"name", basic_type::Varchar, null_attributes, null_option_type::NotNull },
|
||||||
attribute{"age", basic_type::type_uint32, null_attributes, null_option_type::NotNull }
|
attribute{"age", basic_type::UInt32, null_attributes, null_option_type::NotNull }
|
||||||
};
|
};
|
||||||
REQUIRE(!columns.empty());
|
REQUIRE(!columns.empty());
|
||||||
REQUIRE(columns.size() == expected_columns.size());
|
REQUIRE(columns.size() == expected_columns.size());
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,9 @@ TEST_CASE("Test one to many", "[relation][one-to-many]") {
|
||||||
REQUIRE(repo.size() == 2);
|
REQUIRE(repo.size() == 2);
|
||||||
REQUIRE(repo.contains("departments"));
|
REQUIRE(repo.contains("departments"));
|
||||||
REQUIRE(repo.contains("employees"));
|
REQUIRE(repo.contains("employees"));
|
||||||
|
|
||||||
|
std::cout << repo.basic_info("departments")->get().object();
|
||||||
|
std::cout << repo.basic_info("employees")->get().object();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test one to many reverse", "[relation][one-to-many][reverse]") {
|
TEST_CASE("Test one to many reverse", "[relation][one-to-many][reverse]") {
|
||||||
|
|
@ -117,6 +120,9 @@ TEST_CASE("Test one to many reverse", "[relation][one-to-many][reverse]") {
|
||||||
REQUIRE(repo.size() == 2);
|
REQUIRE(repo.size() == 2);
|
||||||
REQUIRE(repo.contains("departments"));
|
REQUIRE(repo.contains("departments"));
|
||||||
REQUIRE(repo.contains("employees"));
|
REQUIRE(repo.contains("employees"));
|
||||||
|
|
||||||
|
std::cout << repo.basic_info("departments")->get().object();
|
||||||
|
std::cout << repo.basic_info("employees")->get().object();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test many to many relation", "[relation][many-to-many]") {
|
TEST_CASE("Test many to many relation", "[relation][many-to-many]") {
|
||||||
|
|
@ -133,5 +139,7 @@ TEST_CASE("Test many to many relation", "[relation][many-to-many]") {
|
||||||
REQUIRE(repo.contains("recipes"));
|
REQUIRE(repo.contains("recipes"));
|
||||||
REQUIRE(repo.contains("recipe_ingredients"));
|
REQUIRE(repo.contains("recipe_ingredients"));
|
||||||
|
|
||||||
auto info = repo.basic_info("ingredients");
|
std::cout << repo.basic_info("ingredients")->get().object();
|
||||||
|
std::cout << repo.basic_info("recipes")->get().object();
|
||||||
|
std::cout << repo.basic_info("recipe_ingredients")->get().object();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,24 @@
|
||||||
using namespace matador::utils;
|
using namespace matador::utils;
|
||||||
|
|
||||||
TEST_CASE("Test default data types", "[data_types][type]") {
|
TEST_CASE("Test default data types", "[data_types][type]") {
|
||||||
REQUIRE(data_type_traits<int8_t>::type() == basic_type::type_int8);
|
REQUIRE(data_type_traits<int8_t>::type() == basic_type::Int8);
|
||||||
REQUIRE(data_type_traits<int16_t>::type() == basic_type::type_int16);
|
REQUIRE(data_type_traits<int16_t>::type() == basic_type::Int16);
|
||||||
REQUIRE(data_type_traits<int32_t>::type() == basic_type::type_int32);
|
REQUIRE(data_type_traits<int32_t>::type() == basic_type::Int32);
|
||||||
REQUIRE(data_type_traits<int64_t>::type() == basic_type::type_int64);
|
REQUIRE(data_type_traits<int64_t>::type() == basic_type::Int64);
|
||||||
REQUIRE(data_type_traits<uint8_t>::type() == basic_type::type_uint8);
|
REQUIRE(data_type_traits<uint8_t>::type() == basic_type::UInt8);
|
||||||
REQUIRE(data_type_traits<uint16_t>::type() == basic_type::type_uint16);
|
REQUIRE(data_type_traits<uint16_t>::type() == basic_type::UInt16);
|
||||||
REQUIRE(data_type_traits<uint32_t>::type() == basic_type::type_uint32);
|
REQUIRE(data_type_traits<uint32_t>::type() == basic_type::UInt32);
|
||||||
REQUIRE(data_type_traits<uint64_t>::type() == basic_type::type_uint64);
|
REQUIRE(data_type_traits<uint64_t>::type() == basic_type::UInt64);
|
||||||
REQUIRE(data_type_traits<bool>::type() == basic_type::type_bool);
|
REQUIRE(data_type_traits<bool>::type() == basic_type::Boolean);
|
||||||
REQUIRE(data_type_traits<float>::type() == basic_type::type_float);
|
REQUIRE(data_type_traits<float>::type() == basic_type::Float);
|
||||||
REQUIRE(data_type_traits<double>::type() == basic_type::type_double);
|
REQUIRE(data_type_traits<double>::type() == basic_type::Double);
|
||||||
REQUIRE(data_type_traits<const char*>::type(32) == basic_type::type_varchar);
|
REQUIRE(data_type_traits<const char*>::type(32) == basic_type::Varchar);
|
||||||
REQUIRE(data_type_traits<const char*>::type(0) == basic_type::type_text);
|
REQUIRE(data_type_traits<const char*>::type(0) == basic_type::Text);
|
||||||
REQUIRE(data_type_traits<char*>::type(32) == basic_type::type_varchar);
|
REQUIRE(data_type_traits<char*>::type(32) == basic_type::Varchar);
|
||||||
REQUIRE(data_type_traits<char*>::type(0) == basic_type::type_text);
|
REQUIRE(data_type_traits<char*>::type(0) == basic_type::Text);
|
||||||
REQUIRE(data_type_traits<char[]>::type(32) == basic_type::type_varchar);
|
REQUIRE(data_type_traits<char[]>::type(32) == basic_type::Varchar);
|
||||||
REQUIRE(data_type_traits<char[]>::type(0) == basic_type::type_text);
|
REQUIRE(data_type_traits<char[]>::type(0) == basic_type::Text);
|
||||||
REQUIRE(data_type_traits<std::string>::type(32) == basic_type::type_varchar);
|
REQUIRE(data_type_traits<std::string>::type(32) == basic_type::Varchar);
|
||||||
REQUIRE(data_type_traits<std::string>::type(0) == basic_type::type_text);
|
REQUIRE(data_type_traits<std::string>::type(0) == basic_type::Text);
|
||||||
REQUIRE(data_type_traits<blob>::type(0) == basic_type::type_blob);
|
REQUIRE(data_type_traits<blob>::type(0) == basic_type::Blob);
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +33,7 @@ TEST_CASE("Test assign value to identifier", "[identifier][assign]") {
|
||||||
REQUIRE(id.is_valid());
|
REQUIRE(id.is_valid());
|
||||||
REQUIRE(id.is_integer());
|
REQUIRE(id.is_integer());
|
||||||
REQUIRE(id.str() == "7");
|
REQUIRE(id.str() == "7");
|
||||||
REQUIRE(id.type() == basic_type::type_int32);
|
REQUIRE(id.type() == basic_type::Int32);
|
||||||
REQUIRE(id.type_index() == std::type_index(typeid(int)));
|
REQUIRE(id.type_index() == std::type_index(typeid(int)));
|
||||||
|
|
||||||
id = std::string{"UniqueId"};
|
id = std::string{"UniqueId"};
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
||||||
auto result = query::create()
|
auto result = query::create()
|
||||||
.table({"person"})
|
.table({"person"})
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("age", basic_type::type_uint16)
|
attribute("age", basic_type::UInt16)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key({"id"})
|
constraint("PK_person").primary_key({"id"})
|
||||||
|
|
@ -51,10 +51,10 @@ TEST_CASE_METHOD(QueryFixture, "Test create table sql statement string", "[query
|
||||||
auto ctx = query::create()
|
auto ctx = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, {255, constraints::Unique}),
|
attribute("name", basic_type::Varchar, {255, constraints::Unique}),
|
||||||
attribute("age", basic_type::type_uint16),
|
attribute("age", basic_type::UInt16),
|
||||||
attribute("address", basic_type::type_uint32)
|
attribute("address", basic_type::UInt32)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key({"id"}),
|
constraint("PK_person").primary_key({"id"}),
|
||||||
|
|
@ -219,9 +219,9 @@ TEST_CASE_METHOD(QueryFixture, "Test create, insert and select a blob column", "
|
||||||
auto result = query::create()
|
auto result = query::create()
|
||||||
.table("person")
|
.table("person")
|
||||||
.columns({
|
.columns({
|
||||||
attribute("id", basic_type::type_uint32),
|
attribute("id", basic_type::UInt32),
|
||||||
attribute("name", basic_type::type_varchar, 255),
|
attribute("name", basic_type::Varchar, 255),
|
||||||
attribute("data", basic_type::type_blob)
|
attribute("data", basic_type::Blob)
|
||||||
})
|
})
|
||||||
.constraints({
|
.constraints({
|
||||||
constraint("PK_person").primary_key({"id"})
|
constraint("PK_person").primary_key({"id"})
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,19 @@ TEST_CASE("Test create empty column", "[column]") {
|
||||||
attribute c("name");
|
attribute c("name");
|
||||||
|
|
||||||
REQUIRE(c.name() == "name");
|
REQUIRE(c.name() == "name");
|
||||||
REQUIRE(c.type() == basic_type::type_null);
|
REQUIRE(c.type() == basic_type::Null);
|
||||||
|
|
||||||
c.change_type<std::string>(255);
|
c.change_type<std::string>(255);
|
||||||
REQUIRE(c.type() == basic_type::type_varchar);
|
REQUIRE(c.type() == basic_type::Varchar);
|
||||||
|
|
||||||
c.change_type<int32_t>(7);
|
c.change_type<int32_t>(7);
|
||||||
REQUIRE(c.type() == basic_type::type_int32);
|
REQUIRE(c.type() == basic_type::Int32);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Test copy and move column", "[column]") {
|
TEST_CASE("Test copy and move column", "[column]") {
|
||||||
attribute c(
|
attribute c(
|
||||||
"name",
|
"name",
|
||||||
basic_type::type_varchar,
|
basic_type::Varchar,
|
||||||
// 2,
|
// 2,
|
||||||
// std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::ForeignKey}),
|
// std::make_shared<attribute>("author", basic_type::type_uint32, "books", attribute_options{constraints::ForeignKey}),
|
||||||
{255, constraints::ForeignKey},
|
{255, constraints::ForeignKey},
|
||||||
|
|
@ -32,7 +32,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
// REQUIRE(c.reference_column());
|
// REQUIRE(c.reference_column());
|
||||||
// REQUIRE(c.reference_column()->name() == "author");
|
// REQUIRE(c.reference_column()->name() == "author");
|
||||||
// REQUIRE(c.reference_column()->table_name() == "books");
|
// REQUIRE(c.reference_column()->table_name() == "books");
|
||||||
REQUIRE(c.type() == basic_type::type_varchar);
|
REQUIRE(c.type() == basic_type::Varchar);
|
||||||
REQUIRE(c.attributes().size() == 255);
|
REQUIRE(c.attributes().size() == 255);
|
||||||
|
|
||||||
auto c2 = c;
|
auto c2 = c;
|
||||||
|
|
@ -41,7 +41,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
// REQUIRE(c2.reference_column());
|
// REQUIRE(c2.reference_column());
|
||||||
// REQUIRE(c2.reference_column()->name() == "author");
|
// REQUIRE(c2.reference_column()->name() == "author");
|
||||||
// REQUIRE(c2.reference_column()->table_name() == "books");
|
// REQUIRE(c2.reference_column()->table_name() == "books");
|
||||||
REQUIRE(c2.type() == basic_type::type_varchar);
|
REQUIRE(c2.type() == basic_type::Varchar);
|
||||||
REQUIRE(c2.attributes().size() == 255);
|
REQUIRE(c2.attributes().size() == 255);
|
||||||
|
|
||||||
auto c3 = std::move(c2);
|
auto c3 = std::move(c2);
|
||||||
|
|
@ -50,7 +50,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
// REQUIRE(c3.reference_column());
|
// REQUIRE(c3.reference_column());
|
||||||
// REQUIRE(c3.reference_column()->name() == "author");
|
// REQUIRE(c3.reference_column()->name() == "author");
|
||||||
// REQUIRE(c3.reference_column()->table_name() == "books");
|
// REQUIRE(c3.reference_column()->table_name() == "books");
|
||||||
REQUIRE(c3.type() == basic_type::type_varchar);
|
REQUIRE(c3.type() == basic_type::Varchar);
|
||||||
REQUIRE(c3.attributes().size() == 255);
|
REQUIRE(c3.attributes().size() == 255);
|
||||||
|
|
||||||
REQUIRE(c2.name().empty());
|
REQUIRE(c2.name().empty());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue