fixed core- and orm-tests. postgres-tests needs some work
This commit is contained in:
parent
95c555d03a
commit
3f3773dc71
|
|
@ -110,7 +110,7 @@ utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> postgres_co
|
||||||
|
|
||||||
std::string postgres_connection::generate_statement_name(const sql::query_context &query) {
|
std::string postgres_connection::generate_statement_name(const sql::query_context &query) {
|
||||||
std::stringstream name;
|
std::stringstream name;
|
||||||
name << query.table_name.name() << "_" << query.command_name;
|
name << query.table_name << "_" << query.command_name;
|
||||||
auto result = postgres_connection::statement_name_map_.find(name.str());
|
auto result = postgres_connection::statement_name_map_.find(name.str());
|
||||||
|
|
||||||
if (result == postgres_connection::statement_name_map_.end()) {
|
if (result == postgres_connection::statement_name_map_.end()) {
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ enum class null_option_type : uint8_t {
|
||||||
NULLABLE, NOT_NULL
|
NULLABLE, NOT_NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
class object_definition;
|
|
||||||
|
|
||||||
struct attribute_options {
|
struct attribute_options {
|
||||||
utils::field_attributes attributes;
|
utils::field_attributes attributes;
|
||||||
null_option_type null_option{null_option_type::NOT_NULL};
|
null_option_type null_option{null_option_type::NOT_NULL};
|
||||||
|
|
@ -33,43 +31,53 @@ public:
|
||||||
|
|
||||||
attribute_definition() = default;
|
attribute_definition() = default;
|
||||||
|
|
||||||
template<typename Type>
|
// template<typename Type>
|
||||||
attribute_definition(std::string name, const utils::field_attributes& attr)
|
// attribute_definition(std::string name, const utils::field_attributes& attr)
|
||||||
: attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), attr)
|
// : attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), attr)
|
||||||
{}
|
// {}
|
||||||
|
//
|
||||||
|
// template<size_t SIZE>
|
||||||
|
// attribute_definition(std::string name, const char (&)[SIZE], const utils::field_attributes& attr, const null_option_type null_opt)
|
||||||
|
// : attribute_definition(std::move(name), utils::data_type_traits<const char*>::type(attr.size()), attr, null_opt)
|
||||||
|
// {}
|
||||||
|
|
||||||
template<typename Type>
|
attribute_definition(std::string name,
|
||||||
attribute_definition(std::string name, const Type &, const utils::field_attributes& attr, null_option_type null_opt)
|
utils::basic_type type,
|
||||||
: attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), attr, null_opt)
|
const utils::field_attributes&,
|
||||||
{}
|
null_option_type null_opt,
|
||||||
|
int index = 0);
|
||||||
|
|
||||||
template<size_t SIZE>
|
// template<typename Type>
|
||||||
attribute_definition(std::string name, const char (&)[SIZE], const utils::field_attributes& attr, const null_option_type null_opt)
|
// attribute_definition(std::string name, const std::shared_ptr<attribute_definition> &ref_column, const utils::field_attributes& attr, null_option_type null_opt)
|
||||||
: attribute_definition(std::move(name), utils::data_type_traits<const char*>::type(attr.size()), attr, null_opt)
|
// : attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), ref_column, attr, null_opt)
|
||||||
{}
|
// {}
|
||||||
|
//
|
||||||
|
attribute_definition(std::string name,
|
||||||
|
utils::basic_type type,
|
||||||
|
int index,
|
||||||
|
const std::shared_ptr<attribute_definition> &ref_column,
|
||||||
|
const utils::field_attributes& attr,
|
||||||
|
null_option_type null_opt);
|
||||||
|
|
||||||
attribute_definition(std::string name, utils::basic_type type, const utils::field_attributes&, null_option_type null_opt, int index = 0);
|
attribute_definition(std::string name,
|
||||||
|
utils::basic_type type,
|
||||||
template<typename Type>
|
const std::shared_ptr<attribute_definition> &ref_column = {});
|
||||||
attribute_definition(std::string name, const std::shared_ptr<attribute_definition> &ref_column, const utils::field_attributes& attr, null_option_type null_opt)
|
attribute_definition(std::string name,
|
||||||
: attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), ref_column, attr, null_opt)
|
utils::basic_type type,
|
||||||
{}
|
std::string table_name,
|
||||||
|
const attribute_options& options,
|
||||||
attribute_definition(std::string name, utils::basic_type type, int index, const std::shared_ptr<attribute_definition> &ref_column, const utils::field_attributes& attr, null_option_type null_opt);
|
const std::shared_ptr<attribute_definition> &ref_column = {});
|
||||||
|
|
||||||
attribute_definition(std::string name, utils::basic_type type, const std::shared_ptr<attribute_definition> &ref_column = {});
|
|
||||||
attribute_definition(std::string name, utils::basic_type type, const attribute_options& options, const std::shared_ptr<object_definition>& obj = {}, const std::shared_ptr<attribute_definition> &ref_column = {});
|
|
||||||
|
|
||||||
[[nodiscard]] const std::string& name() const;
|
[[nodiscard]] const std::string& name() const;
|
||||||
void name(const std::string& n);
|
void name(const std::string& n);
|
||||||
[[nodiscard]] std::string full_name() const;
|
[[nodiscard]] std::string full_name() const;
|
||||||
[[nodiscard]] std::shared_ptr<object_definition> object() const;
|
|
||||||
void object(const std::shared_ptr<object_definition> &obj);
|
|
||||||
[[nodiscard]] int index() const;
|
[[nodiscard]] int index() const;
|
||||||
[[nodiscard]] const utils::field_attributes& attributes() const;
|
[[nodiscard]] const utils::field_attributes& attributes() const;
|
||||||
[[nodiscard]] utils::field_attributes& attributes();
|
[[nodiscard]] utils::field_attributes& attributes();
|
||||||
[[nodiscard]] bool is_nullable() const;
|
[[nodiscard]] bool is_nullable() const;
|
||||||
[[nodiscard]] utils::basic_type type() const;
|
[[nodiscard]] utils::basic_type type() const;
|
||||||
|
[[nodiscard]] const std::string& table_name() const;
|
||||||
|
void table_name(const std::string& name);
|
||||||
void change_type(utils::basic_type type, const utils::field_attributes &attr = utils::null_attributes);
|
void change_type(utils::basic_type type, const utils::field_attributes &attr = utils::null_attributes);
|
||||||
template < typename Type >
|
template < typename Type >
|
||||||
void change_type(const utils::field_attributes &attr = utils::null_attributes) {
|
void change_type(const utils::field_attributes &attr = utils::null_attributes) {
|
||||||
|
|
@ -97,7 +105,8 @@ private:
|
||||||
friend class object_definition;
|
friend class object_definition;
|
||||||
|
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::shared_ptr<object_definition> object_{};
|
// std::shared_ptr<object_definition> object_{};
|
||||||
|
std::string table_name_;
|
||||||
attribute_options options_;
|
attribute_options options_;
|
||||||
utils::basic_type type_{utils::basic_type::type_null};
|
utils::basic_type type_{utils::basic_type::type_null};
|
||||||
|
|
||||||
|
|
@ -158,7 +167,7 @@ template < typename Type >
|
||||||
[[maybe_unused]] attribute_definition make_fk_column(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name) {
|
[[maybe_unused]] attribute_definition make_fk_column(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name) {
|
||||||
return {
|
return {
|
||||||
name, utils::data_type_traits<Type>::type(0), 0,
|
name, utils::data_type_traits<Type>::type(0), 0,
|
||||||
std::make_shared<attribute_definition>(ref_column_name, ref_table_name, utils::data_type_traits<Type>::type(0), utils::constraints::FOREIGN_KEY),
|
std::make_shared<attribute_definition>(ref_column_name, utils::data_type_traits<Type>::type(0), ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY}),
|
||||||
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
|
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,9 +138,8 @@ void attribute_definition_generator::on_primary_key(const char *id, ValueType &x
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
void attribute_definition_generator::on_attribute(const char *id, Type &x, const utils::field_attributes &attr)
|
void attribute_definition_generator::on_attribute(const char *id, Type &x, const utils::field_attributes &attr) {
|
||||||
{
|
columns_.emplace_back(id, utils::data_type_traits<Type>::type(attr.size()), attr, null_option_type::NOT_NULL);
|
||||||
columns_.emplace_back(id, x, attr, null_option_type::NOT_NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,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]] std::shared_ptr<object_definition> definition() const;
|
[[nodiscard]] const std::vector<attribute_definition>& attributes() const;
|
||||||
[[nodiscard]] std::shared_ptr<attribute_definition> reference_column() const;
|
[[nodiscard]] std::shared_ptr<attribute_definition> reference_column() const;
|
||||||
|
|
||||||
[[nodiscard]] bool has_primary_key() const;
|
[[nodiscard]] bool has_primary_key() const;
|
||||||
|
|
@ -49,15 +49,16 @@ public:
|
||||||
[[nodiscard]] bool endpoints_empty() const;
|
[[nodiscard]] bool endpoints_empty() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
basic_object_info(std::shared_ptr<repository_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column, const std::shared_ptr<object_definition> &definition);
|
// basic_object_info(std::shared_ptr<repository_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column, const std::shared_ptr<object_definition> &definition);
|
||||||
basic_object_info(std::shared_ptr<repository_node> node, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_column);
|
basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute_definition> &attributes, utils::identifier &&pk, const std::shared_ptr<attribute_definition> &pk_as_fk_column);
|
||||||
basic_object_info(std::shared_ptr<repository_node> node, const std::shared_ptr<object_definition> &definition);
|
basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute_definition> &attributes);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
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 */
|
||||||
std::shared_ptr<object_definition> definition_;
|
std::vector<attribute_definition> attributes_;
|
||||||
|
// std::shared_ptr<object_definition> definition_;
|
||||||
std::optional<utils::identifier> identifier_;
|
std::optional<utils::identifier> identifier_;
|
||||||
std::shared_ptr<attribute_definition> pk_column_;
|
std::shared_ptr<attribute_definition> pk_as_fk_column_;
|
||||||
t_endpoint_map relation_endpoints_;
|
t_endpoint_map relation_endpoints_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define OBJECT_INFO_HPP
|
#define OBJECT_INFO_HPP
|
||||||
|
|
||||||
#include "matador/object/basic_object_info.hpp"
|
#include "matador/object/basic_object_info.hpp"
|
||||||
#include "matador/object/object_definition.hpp"
|
// #include "matador/object/object_definition.hpp"
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
class repository_node;
|
class repository_node;
|
||||||
|
|
@ -12,32 +12,37 @@ class object_info final : public basic_object_info {
|
||||||
public:
|
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,
|
||||||
|
// const std::shared_ptr<attribute_definition> &ref_column)
|
||||||
|
// : basic_object_info(node, {}, ref_column, {})
|
||||||
|
// , creator_([]{return std::make_unique<Type>(); }){
|
||||||
|
// }
|
||||||
|
// object_info(const std::shared_ptr<repository_node>& node,
|
||||||
|
// utils::identifier &&pk,
|
||||||
|
// const std::shared_ptr<attribute_definition> &ref_column,
|
||||||
|
// object_definition &&definition)
|
||||||
|
// : basic_object_info(node, std::move(pk), ref_column, std::move(definition))
|
||||||
|
// , creator_([]{return std::make_unique<Type>(); }){
|
||||||
|
// }
|
||||||
object_info(const std::shared_ptr<repository_node>& node,
|
object_info(const std::shared_ptr<repository_node>& node,
|
||||||
const std::shared_ptr<attribute_definition> &ref_column)
|
const std::vector<attribute_definition> &attributes,
|
||||||
: basic_object_info(node, {}, ref_column, {})
|
|
||||||
, creator_([]{return std::make_unique<Type>(); }){
|
|
||||||
}
|
|
||||||
object_info(const std::shared_ptr<repository_node>& node,
|
|
||||||
utils::identifier &&pk,
|
utils::identifier &&pk,
|
||||||
const std::shared_ptr<attribute_definition> &ref_column,
|
const std::shared_ptr<attribute_definition> &ref_column,
|
||||||
object_definition &&definition)
|
// object_definition &&definition,
|
||||||
: basic_object_info(node, std::move(pk), ref_column, std::move(definition))
|
|
||||||
, creator_([]{return std::make_unique<Type>(); }){
|
|
||||||
}
|
|
||||||
object_info(const std::shared_ptr<repository_node>& node,
|
|
||||||
utils::identifier &&pk,
|
|
||||||
const std::shared_ptr<attribute_definition> &ref_column,
|
|
||||||
object_definition &&definition,
|
|
||||||
create_func&& creator)
|
create_func&& creator)
|
||||||
: basic_object_info(node, std::move(pk), ref_column, std::move(definition))
|
: basic_object_info(node, attributes, std::move(pk), ref_column/*, std::move(definition)*/)
|
||||||
, creator_(std::move(creator)){
|
, creator_(std::move(creator)){
|
||||||
}
|
}
|
||||||
object_info(const std::shared_ptr<repository_node>& node,
|
object_info(const std::shared_ptr<repository_node>& node,
|
||||||
object_definition &&definition,
|
const std::vector<attribute_definition> &attributes,
|
||||||
|
// object_definition &&definition,
|
||||||
create_func&& creator)
|
create_func&& creator)
|
||||||
: basic_object_info(node, std::move(definition))
|
: basic_object_info(node, attributes)
|
||||||
, creator_(std::move(creator)){
|
, creator_(std::move(creator)){
|
||||||
}
|
}
|
||||||
|
explicit object_info(const std::shared_ptr<repository_node>& node)
|
||||||
|
: basic_object_info(node, {}) {
|
||||||
|
}
|
||||||
|
|
||||||
const Type &prototype() const { return prototype_; }
|
const Type &prototype() const { return prototype_; }
|
||||||
std::unique_ptr<Type> create() const { return creator_(); }
|
std::unique_ptr<Type> create() const { return creator_(); }
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,19 @@ public:
|
||||||
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;
|
primary_key_resolver resolver;
|
||||||
auto obj = std::make_shared<object_definition>(name);
|
// auto obj = std::make_shared<object_definition>(name);
|
||||||
auto pk_info = resolver.resolve<Type>();
|
auto pk_info = resolver.resolve<Type>();
|
||||||
auto ref_column = determine_reference_column(typeid(Type), name, pk_info, repo);
|
auto ref_column = determine_reference_column(typeid(Type), name, pk_info, repo);
|
||||||
const auto attributes = attribute_definition_generator::generate<Type>(repo);
|
const auto attributes = attribute_definition_generator::generate<Type>(repo);
|
||||||
for (auto&& attr : attributes) {
|
// for (auto&& attr : attributes) {
|
||||||
obj->append(std::move(attr));
|
// obj->append(std::move(attr));
|
||||||
}
|
// }
|
||||||
auto info = std::make_unique<object_info<Type>>(
|
auto info = std::make_unique<object_info<Type>>(
|
||||||
node,
|
node,
|
||||||
|
attributes,
|
||||||
std::move(pk_info.pk),
|
std::move(pk_info.pk),
|
||||||
ref_column,
|
ref_column,
|
||||||
obj,
|
// obj,
|
||||||
[]{ return std::make_unique<Type>(); }
|
[]{ return std::make_unique<Type>(); }
|
||||||
);
|
);
|
||||||
node->info_ = std::move(info);
|
node->info_ = std::move(info);
|
||||||
|
|
@ -50,7 +51,7 @@ public:
|
||||||
auto obj = creator();
|
auto obj = creator();
|
||||||
auto info = std::make_unique<object_info<Type>>(
|
auto info = std::make_unique<object_info<Type>>(
|
||||||
result.value(),
|
result.value(),
|
||||||
std::make_shared<object_definition>(attribute_definition_generator::generate(*obj, repo)),
|
attribute_definition_generator::generate(*obj, repo),
|
||||||
std::move(creator)
|
std::move(creator)
|
||||||
);
|
);
|
||||||
result.value()->info_ = std::move(info);
|
result.value()->info_ = std::move(info);
|
||||||
|
|
@ -94,7 +95,7 @@ private:
|
||||||
|
|
||||||
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 std::shared_ptr<attribute_definition> determine_reference_column(const std::type_index& ti,
|
static std::shared_ptr<attribute_definition> determine_reference_column(const std::type_index& ti,
|
||||||
const std::shared_ptr<object_definition>& obj,
|
const std::string& table_name,
|
||||||
const primary_key_info& pk_info,
|
const primary_key_info& pk_info,
|
||||||
repository& repo);
|
repository& repo);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ private:
|
||||||
const sql::dialect &dialect_;
|
const sql::dialect &dialect_;
|
||||||
|
|
||||||
std::unique_ptr<object::repository> schema_;
|
std::unique_ptr<object::repository> schema_;
|
||||||
mutable std::unordered_map<std::string, object::object_definition> prototypes_;
|
mutable std::unordered_map<std::string, std::vector<object::attribute_definition>> prototypes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
|
|
|
||||||
|
|
@ -129,13 +129,12 @@ public:
|
||||||
access::process(*this , obj);
|
access::process(*this , obj);
|
||||||
table_info_stack_.pop();
|
table_info_stack_.pop();
|
||||||
|
|
||||||
auto pk = info->get().definition().primary_key();
|
if (!info->get().has_primary_key()) {
|
||||||
if (!pk) {
|
|
||||||
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
||||||
}
|
}
|
||||||
|
|
||||||
append_join(
|
append_join(
|
||||||
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
|
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().reference_column()->name()},
|
||||||
query::column{next->second, join_column}
|
query::column{next->second, join_column}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -166,18 +165,17 @@ public:
|
||||||
access::process(*this , obj);
|
access::process(*this , obj);
|
||||||
table_info_stack_.pop();
|
table_info_stack_.pop();
|
||||||
|
|
||||||
auto pk = info->get().definition().primary_key();
|
if (!info->get().has_primary_key()) {
|
||||||
if (!pk) {
|
|
||||||
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
||||||
}
|
}
|
||||||
|
|
||||||
append_join(
|
append_join(
|
||||||
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
|
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().reference_column()->name()},
|
||||||
query::column{relation->second, join_column}
|
query::column{relation->second, join_column}
|
||||||
);
|
);
|
||||||
append_join(
|
append_join(
|
||||||
query::column{relation->second, inverse_join_column},
|
query::column{relation->second, inverse_join_column},
|
||||||
query::column{next->second, pk->name()}
|
query::column{next->second, info->get().reference_column()->name()}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,20 +204,19 @@ public:
|
||||||
access::process(*this , obj);
|
access::process(*this , obj);
|
||||||
table_info_stack_.pop();
|
table_info_stack_.pop();
|
||||||
|
|
||||||
auto pk = info->get().definition().primary_key();
|
if (!info->get().has_primary_key()) {
|
||||||
if (!pk) {
|
|
||||||
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto join_columns = join_columns_collector_.collect<typename ContainerType::value_type::value_type>();
|
const auto join_columns = join_columns_collector_.collect<typename ContainerType::value_type::value_type>();
|
||||||
|
|
||||||
append_join(
|
append_join(
|
||||||
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().definition().primary_key()->name()},
|
query::column{table_info_stack_.top().table, table_info_stack_.top().info.get().reference_column()->name()},
|
||||||
query::column{relation->second, join_columns.inverse_join_column}
|
query::column{relation->second, join_columns.inverse_join_column}
|
||||||
);
|
);
|
||||||
append_join(
|
append_join(
|
||||||
query::column{relation->second, join_columns.join_column},
|
query::column{relation->second, join_columns.join_column},
|
||||||
query::column{next->second, pk->name()}
|
query::column{next->second, info->get().reference_column()->name()}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,8 +250,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw query_builder_exception{query_build_error::UnknownType};
|
throw query_builder_exception{query_build_error::UnknownType};
|
||||||
}
|
}
|
||||||
auto pk = info->get().definition().primary_key();
|
if (!info->get().has_primary_key()) {
|
||||||
if (!pk) {
|
|
||||||
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,7 +269,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
|
||||||
|
|
||||||
append_join(
|
append_join(
|
||||||
query::column{table_info_stack_.top().table, id},
|
query::column{table_info_stack_.top().table, id},
|
||||||
query::column{next->second, pk->name()}
|
query::column{next->second, info->get().reference_column()->name()}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
push(id);
|
push(id);
|
||||||
|
|
@ -282,7 +278,7 @@ void session_query_builder::on_foreign_object(const char *id, Pointer &, const u
|
||||||
// create select query
|
// create select query
|
||||||
auto result = matador::query::query::select(generator::columns<typename Pointer::value_type>(schema_, generator::column_generator_options::ForceLazy))
|
auto result = matador::query::query::select(generator::columns<typename Pointer::value_type>(schema_, generator::column_generator_options::ForceLazy))
|
||||||
.from(*foreign_table)
|
.from(*foreign_table)
|
||||||
.where(column(foreign_table, pk->name(), "") == _)
|
.where(column(foreign_table, info->get().reference_column()->name(), "") == _)
|
||||||
.prepare(executor_);
|
.prepare(executor_);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw query_builder_exception(query_build_error::QueryError, result.release_error());
|
throw query_builder_exception(query_build_error::QueryError, result.release_error());
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
attribute_definition::attribute_definition(const char *name)
|
attribute_definition::attribute_definition(const char *name)
|
||||||
: attribute_definition(name, utils::basic_type::type_null, {utils::null_attributes}) {
|
: attribute_definition(name, utils::basic_type::type_null, "", {utils::null_attributes}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_definition::attribute_definition(std::string name)
|
attribute_definition::attribute_definition(std::string name)
|
||||||
: attribute_definition(std::move(name), utils::basic_type::type_null, {utils::null_attributes}) {
|
: attribute_definition(std::move(name), utils::basic_type::type_null, "", {utils::null_attributes}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_definition::attribute_definition(std::string name,
|
attribute_definition::attribute_definition(std::string name,
|
||||||
|
|
@ -19,7 +19,7 @@ attribute_definition::attribute_definition(std::string name,
|
||||||
const utils::field_attributes &attr,
|
const utils::field_attributes &attr,
|
||||||
const null_option_type null_opt,
|
const null_option_type null_opt,
|
||||||
const int index)
|
const int index)
|
||||||
: attribute_definition(std::move(name), type, {attr, null_opt, index}) {
|
: attribute_definition(std::move(name), type, "", {attr, null_opt, index}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_definition::attribute_definition(std::string name,
|
attribute_definition::attribute_definition(std::string name,
|
||||||
|
|
@ -28,16 +28,20 @@ attribute_definition::attribute_definition(std::string name,
|
||||||
const std::shared_ptr<attribute_definition> &ref_column,
|
const std::shared_ptr<attribute_definition> &ref_column,
|
||||||
const utils::field_attributes &attr,
|
const utils::field_attributes &attr,
|
||||||
const null_option_type null_opt)
|
const null_option_type null_opt)
|
||||||
: attribute_definition(std::move(name), type, {attr, null_opt, index}, {}, ref_column) {
|
: attribute_definition(std::move(name), type, "", {attr, null_opt, index}, ref_column) {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_definition::attribute_definition( std::string name, const utils::basic_type type, const std::shared_ptr<attribute_definition>& ref_column )
|
attribute_definition::attribute_definition( std::string name, const utils::basic_type type, const std::shared_ptr<attribute_definition>& ref_column )
|
||||||
: attribute_definition(std::move(name), type, {}, {}, ref_column) {
|
: attribute_definition(std::move(name), type, {}, {}, ref_column) {
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute_definition::attribute_definition(std::string name, const utils::basic_type type, const attribute_options& options, const std::shared_ptr<object_definition>& obj, const std::shared_ptr<attribute_definition>& ref_column)
|
attribute_definition::attribute_definition(std::string name,
|
||||||
: name_( std::move( name ) )
|
const utils::basic_type type,
|
||||||
, object_( obj )
|
std::string table_name,
|
||||||
|
const attribute_options& options,
|
||||||
|
const std::shared_ptr<attribute_definition>& ref_column)
|
||||||
|
: name_(std::move(name))
|
||||||
|
, table_name_(std::move(table_name))
|
||||||
, options_( options )
|
, options_( options )
|
||||||
, type_( type )
|
, type_( type )
|
||||||
, reference_column_( ref_column ) {
|
, reference_column_( ref_column ) {
|
||||||
|
|
@ -52,17 +56,17 @@ void attribute_definition::name( const std::string& n ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string attribute_definition::full_name() const {
|
std::string attribute_definition::full_name() const {
|
||||||
return object_ ? object_->name() + "." + name_ : name_;
|
return !table_name_.empty() ? table_name_ + "." + name_ : name_;
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<object_definition> attribute_definition::object() const {
|
|
||||||
return object_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void attribute_definition::object(const std::shared_ptr<object_definition>& obj) {
|
|
||||||
object_ = obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// std::shared_ptr<object_definition> attribute_definition::object() const {
|
||||||
|
// return object_;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// void attribute_definition::object(const std::shared_ptr<object_definition>& obj) {
|
||||||
|
// object_ = obj;
|
||||||
|
// }
|
||||||
|
//
|
||||||
int attribute_definition::index() const {
|
int attribute_definition::index() const {
|
||||||
return options_.index;
|
return options_.index;
|
||||||
}
|
}
|
||||||
|
|
@ -83,6 +87,14 @@ utils::basic_type attribute_definition::type() const {
|
||||||
return type_;
|
return type_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& attribute_definition::table_name() const {
|
||||||
|
return table_name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void attribute_definition::table_name( const std::string& name ) {
|
||||||
|
table_name_ = name;
|
||||||
|
}
|
||||||
|
|
||||||
void attribute_definition::change_type(const utils::basic_type type, const utils::field_attributes& attr) {
|
void attribute_definition::change_type(const utils::basic_type type, const utils::field_attributes& attr) {
|
||||||
options_.attributes = attr;
|
options_.attributes = attr;
|
||||||
type_ = type;
|
type_ = type;
|
||||||
|
|
@ -160,14 +172,14 @@ template<>
|
||||||
attribute_definition make_fk_column<std::string>( const std::string& name, const std::string& ref_table_name, const std::string& ref_column_name ) {
|
attribute_definition make_fk_column<std::string>( const std::string& name, const std::string& ref_table_name, const std::string& ref_column_name ) {
|
||||||
return {
|
return {
|
||||||
name, utils::basic_type::type_varchar, 0,
|
name, utils::basic_type::type_varchar, 0,
|
||||||
std::make_shared<attribute_definition>(ref_column_name, std::make_shared<object_definition>(ref_table_name), utils::basic_type::type_varchar, utils::constraints::FOREIGN_KEY),
|
std::make_shared<attribute_definition>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY}),
|
||||||
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
|
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
attribute_definition make_fk_column<std::string>(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
|
attribute_definition 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_definition>(ref_column_name, ref_table_name, utils::basic_type::type_varchar, utils::constraints::FOREIGN_KEY);
|
const auto ref_column = std::make_shared<attribute_definition>(ref_column_name, utils::basic_type::type_varchar, ref_table_name, attribute_options{utils::constraints::FOREIGN_KEY});
|
||||||
return {
|
return {
|
||||||
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
|
||||||
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
|
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
|
||||||
|
|
|
||||||
|
|
@ -5,28 +5,30 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
|
// basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
||||||
|
// utils::identifier &&pk,
|
||||||
|
// const std::shared_ptr<attribute_definition> &pk_column,
|
||||||
|
// const std::shared_ptr<object_definition> &definition)
|
||||||
|
// : node_(std::move(node))
|
||||||
|
// , definition_(definition)
|
||||||
|
// , identifier_(std::move(pk))
|
||||||
|
// , pk_column_(pk_column) {
|
||||||
|
// }
|
||||||
|
|
||||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
||||||
|
const std::vector<attribute_definition> &attributes,
|
||||||
utils::identifier &&pk,
|
utils::identifier &&pk,
|
||||||
const std::shared_ptr<attribute_definition> &pk_column,
|
const std::shared_ptr<attribute_definition> &pk_as_fk_column)
|
||||||
const std::shared_ptr<object_definition> &definition)
|
|
||||||
: node_(std::move(node))
|
: node_(std::move(node))
|
||||||
, definition_(definition)
|
, attributes_(attributes)
|
||||||
, identifier_(std::move(pk))
|
, identifier_(std::move(pk))
|
||||||
, pk_column_(pk_column) {
|
, pk_as_fk_column_(pk_as_fk_column) {
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
||||||
utils::identifier &&pk,
|
const std::vector<attribute_definition> &attributes)
|
||||||
const std::shared_ptr<attribute_definition> &pk_column)
|
|
||||||
: node_(std::move(node))
|
: node_(std::move(node))
|
||||||
, identifier_(std::move(pk))
|
, attributes_(attributes) {}
|
||||||
, pk_column_(pk_column) {
|
|
||||||
}
|
|
||||||
|
|
||||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
|
||||||
const std::shared_ptr<object_definition> &definition)
|
|
||||||
: node_(std::move(node))
|
|
||||||
, definition_(definition) {}
|
|
||||||
|
|
||||||
std::type_index basic_object_info::type_index() const {
|
std::type_index basic_object_info::type_index() const {
|
||||||
return node_->type_index();
|
return node_->type_index();
|
||||||
|
|
@ -36,12 +38,12 @@ std::string basic_object_info::name() const {
|
||||||
return node_->name();
|
return node_->name();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<object_definition> basic_object_info::definition() const {
|
const std::vector<attribute_definition>& basic_object_info::attributes() const {
|
||||||
return definition_;
|
return attributes_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<attribute_definition> basic_object_info::reference_column() const {
|
std::shared_ptr<attribute_definition> basic_object_info::reference_column() const {
|
||||||
return pk_column_;
|
return pk_as_fk_column_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool basic_object_info::has_primary_key() const {
|
bool basic_object_info::has_primary_key() const {
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@
|
||||||
#include "matador/object/repository_node.hpp"
|
#include "matador/object/repository_node.hpp"
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
repository_node::repository_node(object::repository &repo)
|
repository_node::repository_node(repository &repo)
|
||||||
: repo_(repo)
|
: repo_(repo)
|
||||||
, type_index_(typeid(detail::null_type)){
|
, type_index_(typeid(detail::null_type)){
|
||||||
}
|
}
|
||||||
|
|
||||||
repository_node::repository_node(object::repository &repo, const std::type_index& ti)
|
repository_node::repository_node(repository &repo, const std::type_index& ti)
|
||||||
: repo_(repo)
|
: repo_(repo)
|
||||||
, type_index_(ti) {
|
, type_index_(ti) {
|
||||||
}
|
}
|
||||||
|
|
||||||
repository_node::repository_node(object::repository &repo, std::string name, const std::type_index& ti)
|
repository_node::repository_node(repository &repo, std::string name, const std::type_index& ti)
|
||||||
: repo_(repo)
|
: repo_(repo)
|
||||||
, type_index_(ti)
|
, type_index_(ti)
|
||||||
, first_child_(std::shared_ptr<repository_node>(new repository_node(repo)))
|
, first_child_(std::shared_ptr<repository_node>(new repository_node(repo)))
|
||||||
|
|
@ -24,9 +24,9 @@ repository_node::repository_node(object::repository &repo, std::string name, con
|
||||||
last_child_->previous_sibling_ = first_child_;
|
last_child_->previous_sibling_ = first_child_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<repository_node> repository_node::make_null_node(object::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/*, std::shared_ptr<attribute_definition>{}*/);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
@ -45,8 +45,8 @@ const basic_object_info &repository_node::info() const {
|
||||||
|
|
||||||
void repository_node::update_name(const std::string& name) {
|
void repository_node::update_name(const std::string& name) {
|
||||||
name_ = name;
|
name_ = name;
|
||||||
if (info_->reference_column() && info_->reference_column()->object() != nullptr) {
|
if (info_->reference_column()) {
|
||||||
info_->reference_column()->object()->name_ = name;
|
info_->reference_column()->table_name(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,20 +104,23 @@ utils::result<repository_node::node_ptr, utils::error> repository_node::make_and
|
||||||
return repo.attach_node(node, "");
|
return repo.attach_node(node, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<attribute_definition> repository_node::determine_reference_column(const std::type_index& ti, const std::shared_ptr<object_definition>& obj, const primary_key_info& pk_info, repository& repo) {
|
std::shared_ptr<attribute_definition> 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);
|
const auto it = repo.missing_references_.find(ti);
|
||||||
if (it == repo.missing_references_.end()) {
|
if (it == repo.missing_references_.end()) {
|
||||||
return std::make_shared<attribute_definition>(pk_info.pk_column_name, pk_info.type, attribute_options{utils::constraints::FOREIGN_KEY});
|
return std::make_shared<attribute_definition>(pk_info.pk_column_name, pk_info.type, table_name, attribute_options{utils::constraints::FOREIGN_KEY});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ref_column = it->second;
|
auto ref_column = it->second;
|
||||||
repo.missing_references_.erase(it);
|
repo.missing_references_.erase(it);
|
||||||
ref_column->name(pk_info.pk_column_name);
|
ref_column->name(pk_info.pk_column_name);
|
||||||
ref_column->object(obj);
|
ref_column->table_name(table_name);
|
||||||
ref_column->change_type(pk_info.type);
|
ref_column->change_type(pk_info.type);
|
||||||
ref_column->attributes() = utils::constraints::FOREIGN_KEY;
|
ref_column->attributes() = utils::constraints::FOREIGN_KEY;
|
||||||
|
|
||||||
if (obj->name().empty()) {
|
if (table_name.empty()) {
|
||||||
repo.missing_references_.insert({ti, ref_column});
|
repo.missing_references_.insert({ti, ref_column});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ matador::utils::result<void, matador::utils::error> matador::orm::schema::create
|
||||||
// std::cout << result.sql << std::endl;
|
// std::cout << result.sql << std::endl;
|
||||||
for (const auto &node: repo_) {
|
for (const auto &node: repo_) {
|
||||||
auto ctx = query::query::create()
|
auto ctx = query::query::create()
|
||||||
.table(node->name(), node->info().definition()->columns())
|
.table(node->name(), node->info().attributes())
|
||||||
.compile(*c);
|
.compile(*c);
|
||||||
|
|
||||||
for ( const auto& [sql, command] : ctx.additional_commands ) {
|
for ( const auto& [sql, command] : ctx.additional_commands ) {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||||
auto c = cache_.pool().acquire();
|
auto c = cache_.pool().acquire();
|
||||||
for (const auto &node: *schema_) {
|
for (const auto &node: *schema_) {
|
||||||
auto ctx = query::query::create()
|
auto ctx = query::query::create()
|
||||||
.table(node->name(), node->info().definition()->columns())
|
.table(node->name(), node->info().attributes())
|
||||||
.compile(*c);
|
.compile(*c);
|
||||||
|
|
||||||
for ( const auto& [sql, command] : ctx.additional_commands ) {
|
for ( const auto& [sql, command] : ctx.additional_commands ) {
|
||||||
|
|
@ -100,7 +100,9 @@ utils::result<sql::query_result<sql::record>, utils::error> session::fetch_all(c
|
||||||
}
|
}
|
||||||
// adjust columns from given query
|
// adjust columns from given query
|
||||||
for (auto &col: q.prototype) {
|
for (auto &col: q.prototype) {
|
||||||
if (const auto rit = it->second.find(col.name()); rit != it->second.end()) {
|
if (const auto rit = std::find_if(it->second.begin(), it->second.end(), [&col](const auto &value) {
|
||||||
|
return value.name() == col.name();
|
||||||
|
}); rit != it->second.end()) {
|
||||||
const_cast<object::attribute_definition &>(col).change_type(rit->type());
|
const_cast<object::attribute_definition &>(col).change_type(rit->type());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,14 +138,14 @@ void query_compiler::visit(internal::query_select_part &part)
|
||||||
}
|
}
|
||||||
|
|
||||||
void query_compiler::visit(internal::query_from_part &part) {
|
void query_compiler::visit(internal::query_from_part &part) {
|
||||||
query_.table_name = part.table().alias();
|
query_.table_name = part.table().name();
|
||||||
query_.sql += " " + build_table_name(part.token(), *dialect_, query_.table_name);
|
query_.sql += " " + build_table_name(part.token(), *dialect_, part.table());
|
||||||
query_.table_aliases.insert({query_.table_name, part.table().alias()});
|
query_.table_aliases.insert({query_.table_name, part.table().alias()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void query_compiler::visit(internal::query_join_part &part)
|
void query_compiler::visit(internal::query_join_part &part)
|
||||||
{
|
{
|
||||||
query_.sql += " " + query_compiler::build_table_name(part.token(), *dialect_, part.table());
|
query_.sql += " " + build_table_name(part.token(), *dialect_, part.table());
|
||||||
}
|
}
|
||||||
|
|
||||||
void query_compiler::visit(internal::query_on_part &part) {
|
void query_compiler::visit(internal::query_on_part &part) {
|
||||||
|
|
@ -335,7 +335,7 @@ void query_compiler::visit(internal::query_create_table_part &part)
|
||||||
fk_cmd += " CONSTRAINT FK_" + query_.table_name;
|
fk_cmd += " CONSTRAINT FK_" + query_.table_name;
|
||||||
fk_cmd += "_" + column;
|
fk_cmd += "_" + column;
|
||||||
fk_cmd += " FOREIGN KEY (" + dialect_->prepare_identifier_string(column) + ")";
|
fk_cmd += " FOREIGN KEY (" + dialect_->prepare_identifier_string(column) + ")";
|
||||||
fk_cmd += " REFERENCES " + reference_column->object()->name() + "(" + reference_column->name() + ")";
|
fk_cmd += " REFERENCES " + reference_column->table_name() + "(" + reference_column->name() + ")";
|
||||||
query_.additional_commands.push_back({fk_cmd, sql::sql_command::SQL_ALTER_TABLE});
|
query_.additional_commands.push_back({fk_cmd, sql::sql_command::SQL_ALTER_TABLE});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "matador/sql/interface/connection_impl.hpp"
|
#include "matador/sql/interface/connection_impl.hpp"
|
||||||
|
|
||||||
#include "matador/utils/string.hpp"
|
#include "matador/utils/string.hpp"
|
||||||
|
#include "matador/utils/value.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ using namespace matador::test;
|
||||||
TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][create]") {
|
TEST_CASE_METHOD(QueryFixture, "Test create statement", "[query][statement][create]") {
|
||||||
REQUIRE(repo.attach<matador::test::person>("person"));
|
REQUIRE(repo.attach<matador::test::person>("person"));
|
||||||
auto stmt = query::create()
|
auto stmt = query::create()
|
||||||
.table<matador::test::person>("person", repo)
|
.table<person>("person"_tab, repo)
|
||||||
.prepare(db);
|
.prepare(db);
|
||||||
REQUIRE(stmt);
|
REQUIRE(stmt);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
"name",
|
"name",
|
||||||
basic_type::type_varchar,
|
basic_type::type_varchar,
|
||||||
2,
|
2,
|
||||||
std::make_shared<attribute_definition>("author", "books", basic_type::type_uint32, constraints::FOREIGN_KEY),
|
std::make_shared<attribute_definition>("author", basic_type::type_uint32, "books", attribute_options{constraints::FOREIGN_KEY}),
|
||||||
{255, constraints::FOREIGN_KEY},
|
{255, constraints::FOREIGN_KEY},
|
||||||
null_option_type::NOT_NULL
|
null_option_type::NOT_NULL
|
||||||
);
|
);
|
||||||
|
|
@ -34,7 +34,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
REQUIRE(c.index() == 2);
|
REQUIRE(c.index() == 2);
|
||||||
REQUIRE(c.reference_column());
|
REQUIRE(c.reference_column());
|
||||||
REQUIRE(c.reference_column()->name() == "author");
|
REQUIRE(c.reference_column()->name() == "author");
|
||||||
REQUIRE(c.reference_column()->object()->name() == "books");
|
REQUIRE(c.reference_column()->table_name() == "books");
|
||||||
REQUIRE(c.type() == basic_type::type_varchar);
|
REQUIRE(c.type() == basic_type::type_varchar);
|
||||||
REQUIRE(c.attributes().size() == 255);
|
REQUIRE(c.attributes().size() == 255);
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
REQUIRE(c2.index() == 2);
|
REQUIRE(c2.index() == 2);
|
||||||
REQUIRE(c2.reference_column());
|
REQUIRE(c2.reference_column());
|
||||||
REQUIRE(c2.reference_column()->name() == "author");
|
REQUIRE(c2.reference_column()->name() == "author");
|
||||||
REQUIRE(c2.reference_column()->object()->name() == "books");
|
REQUIRE(c2.reference_column()->table_name() == "books");
|
||||||
REQUIRE(c2.type() == basic_type::type_varchar);
|
REQUIRE(c2.type() == basic_type::type_varchar);
|
||||||
REQUIRE(c2.attributes().size() == 255);
|
REQUIRE(c2.attributes().size() == 255);
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ TEST_CASE("Test copy and move column", "[column]") {
|
||||||
REQUIRE(c3.index() == 2);
|
REQUIRE(c3.index() == 2);
|
||||||
REQUIRE(c3.reference_column());
|
REQUIRE(c3.reference_column());
|
||||||
REQUIRE(c3.reference_column()->name() == "author");
|
REQUIRE(c3.reference_column()->name() == "author");
|
||||||
REQUIRE(c3.reference_column()->object()->name() == "books");
|
REQUIRE(c3.reference_column()->table_name() == "books");
|
||||||
REQUIRE(c3.type() == basic_type::type_varchar);
|
REQUIRE(c3.type() == basic_type::type_varchar);
|
||||||
REQUIRE(c3.attributes().size() == 255);
|
REQUIRE(c3.attributes().size() == 255);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue