renamed class attribute_definition to attribute

This commit is contained in:
Sascha Kühl 2025-11-21 09:22:00 +01:00
parent dae3c1645b
commit 758284c2b3
44 changed files with 490 additions and 491 deletions

View File

@ -35,7 +35,7 @@ public:
utils::result<std::unique_ptr<sql::statement_impl>, utils::error> prepare(const sql::query_context &context) override; utils::result<std::unique_ptr<sql::statement_impl>, utils::error> prepare(const sql::query_context &context) override;
utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> fetch(const sql::query_context &context) override; utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> fetch(const sql::query_context &context) override;
utils::result<std::vector<object::attribute_definition>, utils::error> describe(const std::string& table) override; utils::result<std::vector<object::attribute>, utils::error> describe(const std::string& table) override;
utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override; utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override;
[[nodiscard]] std::string to_escaped_string( const utils::blob& value ) const override; [[nodiscard]] std::string to_escaped_string( const utils::blob& value ) const override;

View File

@ -3,7 +3,7 @@
#include "postgres_result_reader.hpp" #include "postgres_result_reader.hpp"
#include "postgres_statement.hpp" #include "postgres_statement.hpp"
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/sql/error_code.hpp" #include "matador/sql/error_code.hpp"
#include "matador/sql/record.hpp" #include "matador/sql/record.hpp"
@ -89,7 +89,7 @@ utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> postgres_co
return utils::failure(make_error(sql::error_code::FETCH_FAILED, res, conn_, "Failed to fetch", context.sql)); return utils::failure(make_error(sql::error_code::FETCH_FAILED, res, conn_, "Failed to fetch", context.sql));
} }
std::vector<object::attribute_definition> prototype = context.prototype; std::vector<object::attribute> prototype = context.prototype;
const int num_col = PQnfields(res); const int num_col = PQnfields(res);
if (prototype.size() != static_cast<size_t>(num_col)) { if (prototype.size() != static_cast<size_t>(num_col)) {
@ -212,7 +212,7 @@ utils::basic_type string2type(const char *type) {
} }
} }
utils::result<std::vector<object::attribute_definition>, utils::error> postgres_connection::describe(const std::string &table) { utils::result<std::vector<object::attribute>, utils::error> postgres_connection::describe(const std::string &table) {
const std::string stmt( const std::string stmt(
"SELECT ordinal_position, column_name, udt_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema='public' AND table_name='" "SELECT ordinal_position, column_name, udt_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema='public' AND table_name='"
+ table + "'"); + table + "'");
@ -224,7 +224,7 @@ utils::result<std::vector<object::attribute_definition>, utils::error> postgres_
} }
postgres_result_reader reader(res); postgres_result_reader reader(res);
std::vector<object::attribute_definition> prototype; std::vector<object::attribute> prototype;
while (auto fetched = reader.fetch()) { while (auto fetched = reader.fetch()) {
if (!fetched.is_ok()) { if (!fetched.is_ok()) {
return utils::failure(fetched.release_error()); return utils::failure(fetched.release_error());

View File

@ -0,0 +1,163 @@
#ifndef QUERY_COLUMN_DEFINITION_HPP
#define QUERY_COLUMN_DEFINITION_HPP
#include "matador/utils/basic_types.hpp"
#include "matador/utils/default_type_traits.hpp"
#include "matador/utils/field_attributes.hpp"
#include <memory>
namespace matador::object {
enum class null_option_type : uint8_t {
NULLABLE, NOT_NULL
};
struct attribute_options {
utils::field_attributes attributes;
null_option_type null_option{null_option_type::NOT_NULL};
int index{-1};
};
class attribute {
public:
explicit attribute(const char *name); // NOLINT(*-explicit-constructor)
explicit attribute(std::string name); // NOLINT(*-explicit-constructor)
attribute(const attribute&) = default;
attribute& operator=(const attribute&) = default;
attribute(attribute&&) noexcept = default;
attribute& operator=(attribute&&) noexcept = default;
attribute() = default;
attribute(std::string name,
utils::basic_type type,
const utils::field_attributes&,
null_option_type null_opt,
int index = 0);
attribute(std::string name,
utils::basic_type type,
int index,
const std::shared_ptr<attribute> &ref_column,
const utils::field_attributes& attr,
null_option_type null_opt);
attribute(std::string name,
utils::basic_type type,
const std::shared_ptr<attribute> &ref_column = {});
attribute(std::string name,
utils::basic_type type,
std::string table_name,
const attribute_options& options,
const std::shared_ptr<attribute> &ref_column = {});
[[nodiscard]] const std::string& name() const;
void name(const std::string& n);
[[nodiscard]] std::string full_name() const;
[[nodiscard]] int index() const;
[[nodiscard]] const utils::field_attributes& attributes() const;
[[nodiscard]] utils::field_attributes& attributes();
[[nodiscard]] bool is_nullable() 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);
template < typename Type >
void change_type(const utils::field_attributes &attr = utils::null_attributes) {
type_ = utils::data_type_traits<Type>::type(attr.size());
}
[[nodiscard]] std::shared_ptr<attribute> reference_column() const;
[[nodiscard]] bool is_foreign_reference() const;
[[nodiscard]] bool is_integer() const;
[[nodiscard]] bool is_floating_point() const;
[[nodiscard]] bool is_bool() const;
[[nodiscard]] bool is_string() const;
[[nodiscard]] bool is_varchar() const;
[[nodiscard]] bool is_date() const;
[[nodiscard]] bool is_time() const;
[[nodiscard]] bool is_blob() const;
[[nodiscard]] bool is_null() const;
template< typename Type >
[[nodiscard]] bool is_type_of() const {
return type() == utils::data_type_traits<Type>::type(attributes().size());
}
private:
std::string name_;
std::string table_name_;
attribute_options options_;
utils::basic_type type_{utils::basic_type::type_null};
std::shared_ptr<attribute> reference_column_;
};
/**
* User defined literal to have a shortcut creating a column object
* @param name Name of the column
* @param type
* @param attr Length of the column name
* @param null_opt
* @return A column object with a given name
*/
attribute make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr = utils::null_attributes, null_option_type null_opt = null_option_type::NOT_NULL);
template < typename Type >
attribute make_column(const std::string &name, utils::field_attributes attr = utils::null_attributes, null_option_type null_opt = null_option_type::NOT_NULL)
{
return make_column(name, utils::data_type_traits<Type>::type(0), attr, null_opt);
}
template <>
attribute make_column<std::string>(const std::string &name, utils::field_attributes attr, null_option_type null_opt);
template < typename Type >
attribute make_pk_column(const std::string &name, size_t size = 0)
{
return make_column<Type>(name, { size, utils::constraints::PRIMARY_KEY });
}
template <>
attribute make_pk_column<std::string>(const std::string &name, size_t size);
template < typename Type >
attribute make_fk_column(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column) {
return {name, utils::data_type_traits<Type>::type(size), ref_column, { size, utils::constraints::FOREIGN_KEY }};
}
template < typename Type >
[[maybe_unused]] attribute make_fk_column(const std::string &name, const std::shared_ptr<attribute> &ref_column)
{
return {name, utils::data_type_traits<Type>::type(0), 0, ref_column, { 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL};
}
template <>
[[maybe_unused]] attribute make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute> &ref_column);
template < typename Type >
[[maybe_unused]] attribute make_fk_column(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
return {
name, utils::data_type_traits<Type>::type(size), 0,
std::make_shared<attribute>(ref_column_name, ref_table_name, utils::data_type_traits<Type>::type(size), utils::constraints::FOREIGN_KEY),
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
};
}
template < typename Type >
[[maybe_unused]] attribute make_fk_column(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name) {
return {
name, utils::data_type_traits<Type>::type(0), 0,
std::make_shared<attribute>(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
};
}
template <>
[[maybe_unused]] attribute make_fk_column<std::string>(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name);
template <>
[[maybe_unused]] 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);
}
#endif //QUERY_COLUMN_DEFINITION_HPP

View File

@ -1,163 +0,0 @@
#ifndef QUERY_COLUMN_DEFINITION_HPP
#define QUERY_COLUMN_DEFINITION_HPP
#include "matador/utils/basic_types.hpp"
#include "matador/utils/default_type_traits.hpp"
#include "matador/utils/field_attributes.hpp"
#include <memory>
namespace matador::object {
enum class null_option_type : uint8_t {
NULLABLE, NOT_NULL
};
struct attribute_options {
utils::field_attributes attributes;
null_option_type null_option{null_option_type::NOT_NULL};
int index{-1};
};
class attribute_definition {
public:
explicit attribute_definition(const char *name); // NOLINT(*-explicit-constructor)
explicit attribute_definition(std::string name); // NOLINT(*-explicit-constructor)
attribute_definition(const attribute_definition&) = default;
attribute_definition& operator=(const attribute_definition&) = default;
attribute_definition(attribute_definition&&) noexcept = default;
attribute_definition& operator=(attribute_definition&&) noexcept = default;
attribute_definition() = default;
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,
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 std::shared_ptr<attribute_definition> &ref_column = {});
attribute_definition(std::string name,
utils::basic_type type,
std::string table_name,
const attribute_options& options,
const std::shared_ptr<attribute_definition> &ref_column = {});
[[nodiscard]] const std::string& name() const;
void name(const std::string& n);
[[nodiscard]] std::string full_name() const;
[[nodiscard]] int index() const;
[[nodiscard]] const utils::field_attributes& attributes() const;
[[nodiscard]] utils::field_attributes& attributes();
[[nodiscard]] bool is_nullable() 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);
template < typename Type >
void change_type(const utils::field_attributes &attr = utils::null_attributes) {
type_ = utils::data_type_traits<Type>::type(attr.size());
}
[[nodiscard]] std::shared_ptr<attribute_definition> reference_column() const;
[[nodiscard]] bool is_foreign_reference() const;
[[nodiscard]] bool is_integer() const;
[[nodiscard]] bool is_floating_point() const;
[[nodiscard]] bool is_bool() const;
[[nodiscard]] bool is_string() const;
[[nodiscard]] bool is_varchar() const;
[[nodiscard]] bool is_date() const;
[[nodiscard]] bool is_time() const;
[[nodiscard]] bool is_blob() const;
[[nodiscard]] bool is_null() const;
template< typename Type >
[[nodiscard]] bool is_type_of() const {
return type() == utils::data_type_traits<Type>::type(attributes().size());
}
private:
std::string name_;
std::string table_name_;
attribute_options options_;
utils::basic_type type_{utils::basic_type::type_null};
std::shared_ptr<attribute_definition> reference_column_;
};
/**
* User defined literal to have a shortcut creating a column object
* @param name Name of the column
* @param type
* @param attr Length of the column name
* @param null_opt
* @return A column object with a given name
*/
attribute_definition make_column(const std::string &name, utils::basic_type type, utils::field_attributes attr = utils::null_attributes, null_option_type null_opt = null_option_type::NOT_NULL);
template < typename Type >
attribute_definition make_column(const std::string &name, utils::field_attributes attr = utils::null_attributes, null_option_type null_opt = null_option_type::NOT_NULL)
{
return make_column(name, utils::data_type_traits<Type>::type(0), attr, null_opt);
}
template <>
attribute_definition make_column<std::string>(const std::string &name, utils::field_attributes attr, null_option_type null_opt);
template < typename Type >
attribute_definition make_pk_column(const std::string &name, size_t size = 0)
{
return make_column<Type>(name, { size, utils::constraints::PRIMARY_KEY });
}
template <>
attribute_definition make_pk_column<std::string>(const std::string &name, size_t size);
template < typename Type >
attribute_definition make_fk_column(const std::string &name, size_t size, const std::shared_ptr<attribute_definition> &ref_column) {
return {name, utils::data_type_traits<Type>::type(size), ref_column, { size, utils::constraints::FOREIGN_KEY }};
}
template < typename Type >
[[maybe_unused]] attribute_definition make_fk_column(const std::string &name, const std::shared_ptr<attribute_definition> &ref_column)
{
return {name, utils::data_type_traits<Type>::type(0), 0, ref_column, { 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL};
}
template <>
[[maybe_unused]] attribute_definition make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute_definition> &ref_column);
template < typename Type >
[[maybe_unused]] attribute_definition make_fk_column(const std::string &name, size_t size, const std::string &ref_table_name, const std::string &ref_column_name) {
return {
name, utils::data_type_traits<Type>::type(size), 0,
std::make_shared<attribute_definition>(ref_column_name, ref_table_name, utils::data_type_traits<Type>::type(size), utils::constraints::FOREIGN_KEY),
{ 0, utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL
};
}
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) {
return {
name, utils::data_type_traits<Type>::type(0), 0,
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
};
}
template <>
[[maybe_unused]] attribute_definition make_fk_column<std::string>(const std::string &name, const std::string &ref_table_name, const std::string &ref_column_name);
template <>
[[maybe_unused]] 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);
}
#endif //QUERY_COLUMN_DEFINITION_HPP

View File

@ -1,7 +1,7 @@
#ifndef QUERY_COLUMN_DEFINITION_GENERATOR_HPP #ifndef QUERY_COLUMN_DEFINITION_GENERATOR_HPP
#define QUERY_COLUMN_DEFINITION_GENERATOR_HPP #define QUERY_COLUMN_DEFINITION_GENERATOR_HPP
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/utils/access.hpp" #include "matador/utils/access.hpp"
#include "matador/utils/data_type_traits.hpp" #include "matador/utils/data_type_traits.hpp"
@ -24,9 +24,9 @@ public:
fk_attribute_generator() = default; fk_attribute_generator() = default;
template<class Type> template<class Type>
attribute_definition generate(const char *id, Type &x, const std::shared_ptr<attribute_definition> &ref_column) { attribute generate(const char *id, Type &x, const std::shared_ptr<attribute> &ref_column) {
access::process(*this, x); access::process(*this, x);
return attribute_definition{id, type_, 0, ref_column, {utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL}; return attribute{id, type_, 0, ref_column, {utils::constraints::FOREIGN_KEY }, null_option_type::NOT_NULL};
} }
template<typename ValueType> template<typename ValueType>
@ -54,15 +54,15 @@ private:
class attribute_definition_generator final { class attribute_definition_generator final {
private: private:
attribute_definition_generator(std::vector<attribute_definition> &columns, const repository &repo); attribute_definition_generator(std::vector<attribute> &columns, const repository &repo);
public: public:
~attribute_definition_generator() = default; ~attribute_definition_generator() = default;
template < class Type > template < class Type >
static std::vector<attribute_definition> generate(const repository &repo) static std::vector<attribute> generate(const repository &repo)
{ {
std::vector<attribute_definition> columns; std::vector<attribute> columns;
attribute_definition_generator gen(columns, repo); attribute_definition_generator gen(columns, repo);
Type obj; Type obj;
access::process(gen, obj); access::process(gen, obj);
@ -70,8 +70,8 @@ public:
} }
template < class Type > template < class Type >
static std::vector<attribute_definition> generate(const Type& obj, const repository &repo) { static std::vector<attribute> generate(const Type& obj, const repository &repo) {
std::vector<attribute_definition> columns; std::vector<attribute> columns;
attribute_definition_generator gen(columns, repo); attribute_definition_generator gen(columns, repo);
access::process(gen, obj); access::process(gen, obj);
return columns; return columns;
@ -98,12 +98,12 @@ public:
template <class Pointer> template <class Pointer>
void on_foreign_key(const char *id, Pointer &x) { void on_foreign_key(const char *id, Pointer &x) {
std::shared_ptr<attribute_definition> ref_column; std::shared_ptr<attribute> ref_column;
std::type_index ti = typeid(typename Pointer::value_type); std::type_index ti = typeid(typename Pointer::value_type);
if (const auto result = determine_foreign_ref(std::type_index(ti))) { if (const auto result = determine_foreign_ref(std::type_index(ti))) {
ref_column = *result; ref_column = *result;
} else { } else {
ref_column = std::make_shared<attribute_definition>(); ref_column = std::make_shared<attribute>();
insert_missing_reference_column(ti, ref_column); insert_missing_reference_column(ti, ref_column);
} }
if (x.empty()) { if (x.empty()) {
@ -121,12 +121,12 @@ public:
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {} static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
private: private:
[[nodiscard]] utils::result<std::shared_ptr<attribute_definition>, utils::error> determine_foreign_ref(const std::type_index &ti) const; [[nodiscard]] utils::result<std::shared_ptr<attribute>, utils::error> determine_foreign_ref(const std::type_index &ti) const;
void insert_missing_reference_column(const std::type_index &ti, const std::shared_ptr<attribute_definition>& ref_column) const; void insert_missing_reference_column(const std::type_index &ti, const std::shared_ptr<attribute>& ref_column) const;
private: private:
size_t index_ = 0; size_t index_ = 0;
std::vector<attribute_definition> &columns_; std::vector<attribute> &columns_;
const repository &repo_; const repository &repo_;
fk_attribute_generator fk_column_generator_; fk_attribute_generator fk_column_generator_;

View File

@ -1,7 +1,7 @@
#ifndef BASIC_PROTOTYPE_INFO_HPP #ifndef BASIC_PROTOTYPE_INFO_HPP
#define BASIC_PROTOTYPE_INFO_HPP #define BASIC_PROTOTYPE_INFO_HPP
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/object/relation_endpoint.hpp" #include "matador/object/relation_endpoint.hpp"
#include "matador/utils/identifier.hpp" #include "matador/utils/identifier.hpp"
@ -24,8 +24,8 @@ 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 std::vector<attribute_definition>& attributes() const; [[nodiscard]] const std::vector<attribute>& attributes() const;
[[nodiscard]] std::shared_ptr<attribute_definition> reference_column() const; [[nodiscard]] std::shared_ptr<attribute> reference_column() const;
[[nodiscard]] bool has_primary_key() const; [[nodiscard]] bool has_primary_key() const;
[[nodiscard]] const utils::identifier& primary_key() const; [[nodiscard]] const utils::identifier& primary_key() const;
@ -49,14 +49,14 @@ public:
[[nodiscard]] bool endpoints_empty() const; [[nodiscard]] bool endpoints_empty() const;
protected: protected:
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::vector<attribute> &attributes, utils::identifier &&pk, const std::shared_ptr<attribute> &pk_as_fk_column);
basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute_definition> &attributes); basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute> &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::vector<attribute_definition> attributes_; std::vector<attribute> attributes_;
std::optional<utils::identifier> identifier_; std::optional<utils::identifier> identifier_;
std::shared_ptr<attribute_definition> pk_as_fk_column_; std::shared_ptr<attribute> pk_as_fk_column_;
t_endpoint_map relation_endpoints_; t_endpoint_map relation_endpoints_;
}; };

View File

@ -12,15 +12,15 @@ 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,
const std::vector<attribute_definition> &attributes, const std::vector<attribute> &attributes,
utils::identifier &&pk, utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &ref_column, const std::shared_ptr<attribute> &ref_column,
create_func&& creator) create_func&& creator)
: basic_object_info(node, attributes, std::move(pk), ref_column) : basic_object_info(node, attributes, std::move(pk), ref_column)
, 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,
const std::vector<attribute_definition> &attributes, const std::vector<attribute> &attributes,
create_func&& creator) create_func&& creator)
: basic_object_info(node, attributes) : basic_object_info(node, attributes)
, creator_(std::move(creator)){ , creator_(std::move(creator)){

View File

@ -150,7 +150,7 @@ public:
return utils::ok(basic_object_info_ref{result.value()->info()}); return utils::ok(basic_object_info_ref{result.value()->info()});
} }
[[nodiscard]] utils::result<std::shared_ptr<attribute_definition>, utils::error> reference_column( [[nodiscard]] utils::result<std::shared_ptr<attribute>, utils::error> reference_column(
const std::type_index &type_index) const; const std::type_index &type_index) const;
void dump(std::ostream &os) const; void dump(std::ostream &os) const;
@ -187,7 +187,7 @@ private:
t_type_index_node_map nodes_by_type_; t_type_index_node_map nodes_by_type_;
logger::logger log_; logger::logger log_;
std::unordered_map<std::type_index, std::shared_ptr<attribute_definition> > missing_references_; std::unordered_map<std::type_index, std::shared_ptr<attribute> > missing_references_;
}; };
} }

View File

@ -90,7 +90,7 @@ 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 std::shared_ptr<attribute_definition> determine_reference_column(const std::type_index& ti, static std::shared_ptr<attribute> determine_reference_column(const std::type_index& ti,
const std::string& table_name, const std::string& table_name,
const primary_key_info& pk_info, const primary_key_info& pk_info,
repository& repo); repository& repo);

View File

@ -46,7 +46,7 @@ public:
[[nodiscard]] utils::result<void, utils::error> drop_table(); [[nodiscard]] utils::result<void, utils::error> drop_table();
[[nodiscard]] utils::result<void, utils::error> drop_table(const std::string &table_name) const; [[nodiscard]] utils::result<void, utils::error> drop_table(const std::string &table_name) const;
[[nodiscard]] utils::result<std::vector<object::attribute_definition>, utils::error> describe_table(const std::string &table_name) const; [[nodiscard]] utils::result<std::vector<object::attribute>, utils::error> describe_table(const std::string &table_name) const;
[[nodiscard]] utils::result<bool, utils::error> table_exists(const std::string &table_name) const; [[nodiscard]] utils::result<bool, utils::error> table_exists(const std::string &table_name) const;
private: private:

View File

@ -129,7 +129,7 @@ public:
[[nodiscard]] utils::result<sql::query_result<sql::record>, utils::error> fetch_all(const sql::query_context &q) const; [[nodiscard]] utils::result<sql::query_result<sql::record>, utils::error> fetch_all(const sql::query_context &q) const;
[[nodiscard]] utils::result<size_t, utils::error> execute(const std::string &sql) const; [[nodiscard]] utils::result<size_t, utils::error> execute(const std::string &sql) const;
[[nodiscard]] std::vector<object::attribute_definition> describe_table(const std::string &table_name) const; [[nodiscard]] std::vector<object::attribute> describe_table(const std::string &table_name) const;
[[nodiscard]] bool table_exists(const std::string &table_name) const; [[nodiscard]] bool table_exists(const std::string &table_name) const;
void dump_schema(std::ostream &os) const; void dump_schema(std::ostream &os) const;
@ -150,7 +150,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, std::vector<object::attribute_definition>> prototypes_; mutable std::unordered_map<std::string, std::vector<object::attribute>> prototypes_;
}; };
template<typename Type> template<typename Type>

View File

@ -1,12 +1,11 @@
#ifndef MATADOR_BUILDER_HPP #ifndef MATADOR_BUILDER_HPP
#define MATADOR_BUILDER_HPP #define MATADOR_BUILDER_HPP
#include "matador/object/attribute_definition.hpp"
#include "matador/query/column.hpp" #include "matador/query/column.hpp"
#include "matador/query/table.hpp" #include "matador/query/table.hpp"
#include "matador/utils/basic_types.hpp" #include "matador/utils/basic_types.hpp"
#include "matador/utils/constraints.hpp"
#include <string> #include <string>
@ -24,26 +23,26 @@ private:
std::string alias_; std::string alias_;
}; };
class attribute { // class attribute {
public: // public:
attribute(std::string name, const utils::basic_type type) // attribute(std::string name, const utils::basic_type type)
: name_(std::move(name)) // : name_(std::move(name))
, type_(type) {} // , type_(type) {}
//
[[nodiscard]] const std::string& name() const; // [[nodiscard]] const std::string& name() const;
[[nodiscard]] utils::basic_type type() const; // [[nodiscard]] utils::basic_type type() const;
[[nodiscard]] const attribute_options& options() const; // [[nodiscard]] const attribute_options& options() const;
//
private: // private:
friend class entity; // friend class entity;
//
std::string name_; // std::string name_;
std::string alias_; // std::string alias_;
utils::basic_type type_{}; // utils::basic_type type_{};
attribute_options options_; // attribute_options options_;
//
entity* owner_{nullptr}; // entity* owner_{nullptr};
}; // };
class constraint { class constraint {
public: public:

View File

@ -13,8 +13,8 @@ class query_create_intermediate : public query_intermediate {
public: public:
query_create_intermediate(); query_create_intermediate();
executable_query table(const table &tab, std::initializer_list<object::attribute_definition> columns); executable_query table(const table &tab, std::initializer_list<object::attribute> columns);
executable_query table(const query::table &tab, const std::vector<object::attribute_definition> &columns); executable_query table(const query::table &tab, const std::vector<object::attribute> &columns);
template<class Type> template<class Type>
executable_query table(const matador::query::table &tab, const object::repository &schema) { executable_query table(const matador::query::table &tab, const object::repository &schema) {
return this->table(tab, object::attribute_definition_generator::generate<Type>(schema)); return this->table(tab, object::attribute_definition_generator::generate<Type>(schema));

View File

@ -9,7 +9,7 @@
#include "matador/query/column.hpp" #include "matador/query/column.hpp"
#include "matador/query/table.hpp" #include "matador/query/table.hpp"
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/utils/placeholder.hpp" #include "matador/utils/placeholder.hpp"
@ -364,17 +364,17 @@ private:
class query_create_table_part final : public query_part class query_create_table_part final : public query_part
{ {
public: public:
query_create_table_part(table table, std::vector<object::attribute_definition> columns); query_create_table_part(table table, std::vector<object::attribute> columns);
[[nodiscard]] const table& table() const; [[nodiscard]] const table& table() const;
[[nodiscard]] const std::vector<object::attribute_definition>& columns() const; [[nodiscard]] const std::vector<object::attribute>& columns() const;
private: private:
void accept(query_part_visitor &visitor) override; void accept(query_part_visitor &visitor) override;
private: private:
class table table_; class table table_;
std::vector<object::attribute_definition> columns_; std::vector<object::attribute> columns_;
}; };
class query_create_schema_part final : public query_part { class query_create_schema_part final : public query_part {

View File

@ -4,7 +4,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/query/table.hpp" #include "matador/query/table.hpp"
#include "matador/query/query_part.hpp" #include "matador/query/query_part.hpp"
@ -13,7 +13,7 @@ namespace matador::query {
struct query_data { struct query_data {
std::vector<std::unique_ptr<query_part>> parts{}; std::vector<std::unique_ptr<query_part>> parts{};
std::vector<object::attribute_definition> columns{}; std::vector<object::attribute> columns{};
std::unordered_map<std::string, table> tables{}; std::unordered_map<std::string, table> tables{};
}; };

View File

@ -1,7 +1,7 @@
#ifndef QUERY_CONNECTION_HPP #ifndef QUERY_CONNECTION_HPP
#define QUERY_CONNECTION_HPP #define QUERY_CONNECTION_HPP
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/sql/abstract_sql_logger.hpp" #include "matador/sql/abstract_sql_logger.hpp"
#include "matador/sql/connection_info.hpp" #include "matador/sql/connection_info.hpp"
@ -126,7 +126,7 @@ public:
*/ */
[[nodiscard]] utils::result<void, utils::error> rollback() const; [[nodiscard]] utils::result<void, utils::error> rollback() const;
[[nodiscard]] utils::result<std::vector<object::attribute_definition>, utils::error> describe(const std::string &table_name) const; [[nodiscard]] utils::result<std::vector<object::attribute>, utils::error> describe(const std::string &table_name) const;
[[nodiscard]] utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) const; [[nodiscard]] utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) const;
[[nodiscard]] utils::result<bool, utils::error> exists(const std::string &table_name) const; [[nodiscard]] utils::result<bool, utils::error> exists(const std::string &table_name) const;

View File

@ -3,7 +3,7 @@
#include <memory> #include <memory>
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/sql/connection_info.hpp" #include "matador/sql/connection_info.hpp"
#include "matador/sql/query_context.hpp" #include "matador/sql/query_context.hpp"
@ -38,7 +38,7 @@ public:
virtual utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(const query_context &context) = 0; virtual utils::result<std::unique_ptr<query_result_impl>, utils::error> fetch(const query_context &context) = 0;
virtual utils::result<std::unique_ptr<statement_impl>, utils::error> prepare(const query_context &context) = 0; virtual utils::result<std::unique_ptr<statement_impl>, utils::error> prepare(const query_context &context) = 0;
virtual utils::result<std::vector<object::attribute_definition>, utils::error> describe(const std::string &table) = 0; virtual utils::result<std::vector<object::attribute>, utils::error> describe(const std::string &table) = 0;
virtual utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) = 0; virtual utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) = 0;
[[nodiscard]] const class dialect &dialect() const; [[nodiscard]] const class dialect &dialect() const;

View File

@ -12,7 +12,7 @@
#include "matador/sql/internal/query_result_pk_resolver.hpp" #include "matador/sql/internal/query_result_pk_resolver.hpp"
#include "matador/sql/record.hpp" #include "matador/sql/record.hpp"
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include <iostream> #include <iostream>
#include <memory> #include <memory>
@ -73,9 +73,9 @@ private:
class query_result_impl { class query_result_impl {
public: public:
query_result_impl(std::unique_ptr<query_result_reader> &&reader, query_result_impl(std::unique_ptr<query_result_reader> &&reader,
std::vector<object::attribute_definition> &&prototype, size_t column_index = 0); std::vector<object::attribute> &&prototype, size_t column_index = 0);
query_result_impl(std::unique_ptr<query_result_reader> &&reader, query_result_impl(std::unique_ptr<query_result_reader> &&reader,
const std::vector<object::attribute_definition> &prototype, size_t column_index = 0); const std::vector<object::attribute> &prototype, size_t column_index = 0);
template<typename ValueType> template<typename ValueType>
void on_primary_key(const char *id, ValueType &value, const utils::primary_key_attribute& attr = utils::default_pk_attributes) { void on_primary_key(const char *id, ValueType &value, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
@ -183,7 +183,7 @@ public:
return true; return true;
} }
[[nodiscard]] const std::vector<object::attribute_definition> &prototype() const; [[nodiscard]] const std::vector<object::attribute> &prototype() const;
private: private:
template<class Type> template<class Type>
@ -209,7 +209,7 @@ private:
protected: protected:
size_t column_index_ = 0; size_t column_index_ = 0;
std::vector<object::attribute_definition> prototype_; std::vector<object::attribute> prototype_;
std::unique_ptr<query_result_reader> reader_; std::unique_ptr<query_result_reader> reader_;
detail::pk_reader pk_reader_; detail::pk_reader pk_reader_;
std::stack<std::type_index> type_stack_; std::stack<std::type_index> type_stack_;

View File

@ -1,7 +1,7 @@
#ifndef QUERY_QUERY_DATA_HPP #ifndef QUERY_QUERY_DATA_HPP
#define QUERY_QUERY_DATA_HPP #define QUERY_QUERY_DATA_HPP
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/query/table.hpp" #include "matador/query/table.hpp"
#include "matador/utils/types.hpp" #include "matador/utils/types.hpp"
@ -36,7 +36,7 @@ struct query_context {
std::string command_name{}; std::string command_name{};
std::string schema_name{}; std::string schema_name{};
std::string table_name{}; std::string table_name{};
std::vector<object::attribute_definition> prototype{}; std::vector<object::attribute> prototype{};
std::vector<std::string> result_vars{}; std::vector<std::string> result_vars{};
std::vector<std::string> bind_vars{}; std::vector<std::string> bind_vars{};
std::vector<utils::database_type> bind_types{}; std::vector<utils::database_type> bind_types{};

View File

@ -9,12 +9,12 @@
#include <string> #include <string>
#include <ostream> #include <ostream>
#define FIELD(x) const sql::column x{*this, #x, ""}; #define FIELD(x) const query::column x{*this, #x, ""};
#define QUERY_HELPER(C, ...) \ #define QUERY_HELPER(C, ...) \
namespace matador::qh { \ namespace matador::qh { \
namespace internal { \ namespace internal { \
struct C##_query : sql::table { \ struct C##_query : query::table { \
C##_query() : table(#C) {} \ C##_query() : table(#C) {} \
MAP(FIELD, __VA_ARGS__) \ MAP(FIELD, __VA_ARGS__) \
}; } \ }; } \

View File

@ -1,7 +1,7 @@
#ifndef QUERY_QUERY_RESULT_HPP #ifndef QUERY_QUERY_RESULT_HPP
#define QUERY_QUERY_RESULT_HPP #define QUERY_QUERY_RESULT_HPP
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/sql/internal/query_result_impl.hpp" #include "matador/sql/internal/query_result_impl.hpp"
@ -102,12 +102,12 @@ private:
namespace detail { namespace detail {
template < typename Type > template < typename Type >
Type* create_prototype(const std::vector<object::attribute_definition> &/*prototype*/) { Type* create_prototype(const std::vector<object::attribute> &/*prototype*/) {
return new Type{}; return new Type{};
} }
template <> template <>
record* create_prototype<record>(const std::vector<object::attribute_definition> &prototype); record* create_prototype<record>(const std::vector<object::attribute> &prototype);
} }

View File

@ -13,7 +13,7 @@ add_library(matador-core STATIC
../../include/matador/net/reactor.hpp ../../include/matador/net/reactor.hpp
../../include/matador/net/select_fd_sets.hpp ../../include/matador/net/select_fd_sets.hpp
../../include/matador/net/socket_interrupter.hpp ../../include/matador/net/socket_interrupter.hpp
../../include/matador/object/attribute_definition.hpp ../../include/matador/object/attribute.hpp
../../include/matador/object/attribute_definition_generator.hpp ../../include/matador/object/attribute_definition_generator.hpp
../../include/matador/object/basic_object_info.hpp ../../include/matador/object/basic_object_info.hpp
../../include/matador/object/error_code.hpp ../../include/matador/object/error_code.hpp
@ -74,7 +74,7 @@ add_library(matador-core STATIC
logger/log_manager.cpp logger/log_manager.cpp
logger/logger.cpp logger/logger.cpp
logger/rotating_file_sink.cpp logger/rotating_file_sink.cpp
object/attribute_definition.cpp object/attribute.cpp
object/attribute_definition_generator.cpp object/attribute_definition_generator.cpp
object/basic_object_info.cpp object/basic_object_info.cpp
object/error_code.cpp object/error_code.cpp

View File

@ -0,0 +1,178 @@
#include "matador/object/attribute.hpp"
#include <ostream>
#include <utility>
namespace matador::object {
attribute::attribute(const char *name)
: attribute(name, utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute::attribute(std::string name)
: attribute(std::move(name), utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute::attribute(std::string name,
const utils::basic_type type,
const utils::field_attributes &attr,
const null_option_type null_opt,
const int index)
: attribute(std::move(name), type, "", {attr, null_opt, index}) {
}
attribute::attribute(std::string name,
const utils::basic_type type,
const int index,
const std::shared_ptr<attribute> &ref_column,
const utils::field_attributes &attr,
const null_option_type null_opt)
: attribute(std::move(name), type, "", {attr, null_opt, index}, ref_column) {
}
attribute::attribute( std::string name, const utils::basic_type type, const std::shared_ptr<attribute>& ref_column )
: attribute(std::move(name), type, {}, {}, ref_column) {
}
attribute::attribute(std::string name,
const utils::basic_type type,
std::string table_name,
const attribute_options& options,
const std::shared_ptr<attribute>& ref_column)
: name_(std::move(name))
, table_name_(std::move(table_name))
, options_( options )
, type_( type )
, reference_column_( ref_column ) {
}
const std::string &attribute::name() const {
return name_;
}
void attribute::name( const std::string& n ) {
name_ = n;
}
std::string attribute::full_name() const {
return !table_name_.empty() ? table_name_ + "." + name_ : name_;
}
int attribute::index() const {
return options_.index;
}
const utils::field_attributes &attribute::attributes() const {
return options_.attributes;
}
utils::field_attributes& attribute::attributes() {
return options_.attributes;
}
bool attribute::is_nullable() const {
return options_.null_option == null_option_type::NULLABLE;
}
utils::basic_type attribute::type() const {
return type_;
}
const std::string& attribute::table_name() const {
return table_name_;
}
void attribute::table_name( const std::string& name ) {
table_name_ = name;
}
void attribute::change_type(const utils::basic_type type, const utils::field_attributes& attr) {
options_.attributes = attr;
type_ = type;
}
std::shared_ptr<attribute> attribute::reference_column() const {
return reference_column_;
}
bool attribute::is_foreign_reference() const {
return reference_column_ != nullptr;
}
bool attribute::is_integer() const {
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
}
bool attribute::is_floating_point() const {
return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double;
}
bool attribute::is_bool() const {
return type_ == utils::basic_type::type_bool;
}
bool attribute::is_string() const {
return type_ == utils::basic_type::type_text;
}
bool attribute::is_varchar() const {
return type_ == utils::basic_type::type_varchar;
}
bool attribute::is_date() const {
return type_ == utils::basic_type::type_date;
}
bool attribute::is_time() const {
return type_ == utils::basic_type::type_time;
}
bool attribute::is_blob() const {
return type_ == utils::basic_type::type_blob;
}
bool attribute::is_null() const {
return type_ == utils::basic_type::type_null;
}
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::PRIMARY_KEY});
}
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::FOREIGN_KEY}, 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::FOREIGN_KEY}),
{ 0, utils::constraints::FOREIGN_KEY }, 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::FOREIGN_KEY});
return {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
};
}
}

View File

@ -1,178 +0,0 @@
#include "matador/object/attribute_definition.hpp"
#include <ostream>
#include <utility>
namespace matador::object {
attribute_definition::attribute_definition(const char *name)
: attribute_definition(name, utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute_definition::attribute_definition(std::string name)
: attribute_definition(std::move(name), utils::basic_type::type_null, "", {utils::null_attributes}) {
}
attribute_definition::attribute_definition(std::string name,
const utils::basic_type type,
const utils::field_attributes &attr,
const null_option_type null_opt,
const int index)
: attribute_definition(std::move(name), type, "", {attr, null_opt, index}) {
}
attribute_definition::attribute_definition(std::string name,
const utils::basic_type type,
const int index,
const std::shared_ptr<attribute_definition> &ref_column,
const utils::field_attributes &attr,
const null_option_type null_opt)
: 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(std::move(name), type, {}, {}, ref_column) {
}
attribute_definition::attribute_definition(std::string name,
const utils::basic_type type,
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 )
, type_( type )
, reference_column_( ref_column ) {
}
const std::string &attribute_definition::name() const {
return name_;
}
void attribute_definition::name( const std::string& n ) {
name_ = n;
}
std::string attribute_definition::full_name() const {
return !table_name_.empty() ? table_name_ + "." + name_ : name_;
}
int attribute_definition::index() const {
return options_.index;
}
const utils::field_attributes &attribute_definition::attributes() const {
return options_.attributes;
}
utils::field_attributes& attribute_definition::attributes() {
return options_.attributes;
}
bool attribute_definition::is_nullable() const {
return options_.null_option == null_option_type::NULLABLE;
}
utils::basic_type attribute_definition::type() const {
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) {
options_.attributes = attr;
type_ = type;
}
std::shared_ptr<attribute_definition> attribute_definition::reference_column() const {
return reference_column_;
}
bool attribute_definition::is_foreign_reference() const {
return reference_column_ != nullptr;
}
bool attribute_definition::is_integer() const {
return type_ >= utils::basic_type::type_int8 && type_ <= utils::basic_type::type_uint64;
}
bool attribute_definition::is_floating_point() const {
return type_ == utils::basic_type::type_float || type_ == utils::basic_type::type_double;
}
bool attribute_definition::is_bool() const {
return type_ == utils::basic_type::type_bool;
}
bool attribute_definition::is_string() const {
return type_ == utils::basic_type::type_text;
}
bool attribute_definition::is_varchar() const {
return type_ == utils::basic_type::type_varchar;
}
bool attribute_definition::is_date() const {
return type_ == utils::basic_type::type_date;
}
bool attribute_definition::is_time() const {
return type_ == utils::basic_type::type_time;
}
bool attribute_definition::is_blob() const {
return type_ == utils::basic_type::type_blob;
}
bool attribute_definition::is_null() const {
return type_ == utils::basic_type::type_null;
}
attribute_definition 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_definition 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_definition make_pk_column<std::string>(const std::string &name, size_t size) {
return make_column<std::string>(name, {size, utils::constraints::PRIMARY_KEY});
}
template<>
attribute_definition make_fk_column<std::string>(const std::string &name, size_t size, const std::shared_ptr<attribute_definition> &ref_column) {
return {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
};
}
template<>
attribute_definition 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_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
};
}
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) {
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 {
name, utils::data_type_traits<std::string>::type(size), 0, ref_column,
{size, utils::constraints::FOREIGN_KEY}, null_option_type::NOT_NULL
};
}
}

View File

@ -3,7 +3,7 @@
namespace matador::object { namespace matador::object {
attribute_definition_generator::attribute_definition_generator(std::vector<attribute_definition> &columns, const repository &repo) attribute_definition_generator::attribute_definition_generator(std::vector<attribute> &columns, const repository &repo)
: columns_(columns) : columns_(columns)
, repo_(repo) , repo_(repo)
{} {}
@ -12,11 +12,11 @@ void attribute_definition_generator::on_revision(const char *id, uint64_t &rev)
on_attribute(id, rev); on_attribute(id, rev);
} }
utils::result<std::shared_ptr<attribute_definition>, utils::error> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti) const { utils::result<std::shared_ptr<attribute>, utils::error> attribute_definition_generator::determine_foreign_ref(const std::type_index &ti) const {
return repo_.reference_column(ti); return repo_.reference_column(ti);
} }
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, const std::shared_ptr<attribute_definition>& ref_column) const { void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, const std::shared_ptr<attribute>& ref_column) const {
const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column}); const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
} }

View File

@ -6,9 +6,9 @@
namespace matador::object { namespace matador::object {
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, const std::vector<attribute> &attributes,
utils::identifier &&pk, utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &pk_as_fk_column) const std::shared_ptr<attribute> &pk_as_fk_column)
: node_(std::move(node)) : node_(std::move(node))
, attributes_(attributes) , attributes_(attributes)
, identifier_(std::move(pk)) , identifier_(std::move(pk))
@ -16,7 +16,7 @@ basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
} }
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) const std::vector<attribute> &attributes)
: node_(std::move(node)) : node_(std::move(node))
, attributes_(attributes) {} , attributes_(attributes) {}
@ -28,11 +28,11 @@ std::string basic_object_info::name() const {
return node_->name(); return node_->name();
} }
const std::vector<attribute_definition>& basic_object_info::attributes() const { const std::vector<attribute>& basic_object_info::attributes() const {
return attributes_; return attributes_;
} }
std::shared_ptr<attribute_definition> basic_object_info::reference_column() const { std::shared_ptr<attribute> basic_object_info::reference_column() const {
return pk_as_fk_column_; return pk_as_fk_column_;
} }

View File

@ -62,7 +62,7 @@ utils::result<basic_object_info_ref, utils::error> repository::basic_info( const
return utils::ok(basic_object_info_ref{result.value()->info()}); return utils::ok(basic_object_info_ref{result.value()->info()});
} }
utils::result<std::shared_ptr<attribute_definition>, utils::error> repository::reference_column(const std::type_index &type_index) const { utils::result<std::shared_ptr<attribute>, utils::error> repository::reference_column(const std::type_index &type_index) const {
const auto result = find_node(type_index); const auto result = find_node(type_index);
if (result) { if (result) {
return utils::ok((*result)->info().reference_column()); return utils::ok((*result)->info().reference_column());

View File

@ -104,13 +104,13 @@ 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, std::shared_ptr<attribute> repository_node::determine_reference_column(const std::type_index& ti,
const std::string& table_name, const std::string& table_name,
const primary_key_info& pk_info, const primary_key_info& pk_info,
repository& repo) { 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, table_name, attribute_options{utils::constraints::FOREIGN_KEY}); return std::make_shared<attribute>(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;

View File

@ -127,7 +127,7 @@ matador::utils::result<void, matador::utils::error> matador::orm::schema::drop_t
return utils::ok<void>(); return utils::ok<void>();
} }
matador::utils::result<std::vector<matador::object::attribute_definition>, matador::utils::error> matador::orm::schema::describe_table(const std::string& table_name) const { matador::utils::result<std::vector<matador::object::attribute>, matador::utils::error> matador::orm::schema::describe_table(const std::string& table_name) const {
const auto c = pool_.acquire(); const auto c = pool_.acquire();
if (!c.valid()) { if (!c.valid()) {
return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection.")); return utils::failure(make_error(error_code::NoConnectionAvailable, "Failed to acquire connection."));

View File

@ -103,7 +103,7 @@ utils::result<sql::query_result<sql::record>, utils::error> session::fetch_all(c
if (const auto rit = std::find_if(it->second.begin(), it->second.end(), [&col](const auto &value) { if (const auto rit = std::find_if(it->second.begin(), it->second.end(), [&col](const auto &value) {
return value.name() == col.name(); return value.name() == col.name();
}); rit != it->second.end()) { }); rit != it->second.end()) {
const_cast<object::attribute_definition &>(col).change_type(rit->type()); const_cast<object::attribute &>(col).change_type(rit->type());
} }
} }
auto res = fetch(q); auto res = fetch(q);
@ -120,7 +120,7 @@ utils::result<size_t, utils::error> session::execute(const std::string &sql) con
return execute(sql::query_context{sql}); return execute(sql::query_context{sql});
} }
std::vector<object::attribute_definition> session::describe_table(const std::string &table_name) const { std::vector<object::attribute> session::describe_table(const std::string &table_name) const {
const auto c = cache_.pool().acquire(); const auto c = cache_.pool().acquire();
if (!c.valid()) { if (!c.valid()) {
throw std::logic_error("no database connection available"); throw std::logic_error("no database connection available");

View File

@ -7,7 +7,7 @@
namespace matador::query { namespace matador::query {
namespace detail { namespace detail {
sql::record *create_prototype(const std::vector<object::attribute_definition> &prototype) { sql::record *create_prototype(const std::vector<object::attribute> &prototype) {
auto result = std::make_unique<sql::record>(); auto result = std::make_unique<sql::record>();
for (const auto &col: prototype) { for (const auto &col: prototype) {
result->append({ result->append({

View File

@ -8,11 +8,11 @@ query_create_intermediate::query_create_intermediate() {
context_->parts.push_back(std::make_unique<internal::query_create_part>()); context_->parts.push_back(std::make_unique<internal::query_create_part>());
} }
executable_query query_create_intermediate::table(const class table &tab, const std::initializer_list<object::attribute_definition> columns) { executable_query query_create_intermediate::table(const class table &tab, const std::initializer_list<object::attribute> columns) {
return this->table(tab, std::vector<object::attribute_definition>{columns}); return this->table(tab, std::vector<object::attribute>{columns});
} }
executable_query query_create_intermediate::table(const class table &tab, const std::vector<object::attribute_definition> &columns) { executable_query query_create_intermediate::table(const class table &tab, const std::vector<object::attribute> &columns) {
context_->parts.push_back(std::make_unique<internal::query_create_table_part>(tab, columns)); context_->parts.push_back(std::make_unique<internal::query_create_table_part>(tab, columns));
return {context_}; return {context_};
} }

View File

@ -344,7 +344,7 @@ void query_create_part::accept(query_part_visitor &visitor)
visitor.visit(*this); visitor.visit(*this);
} }
query_create_table_part::query_create_table_part(class table table, std::vector<object::attribute_definition> columns) query_create_table_part::query_create_table_part(class table table, std::vector<object::attribute> columns)
: query_part(sql::dialect_token::Table) : query_part(sql::dialect_token::Table)
, table_(std::move(table)) , table_(std::move(table))
, columns_(std::move(columns)) {} , columns_(std::move(columns)) {}
@ -354,7 +354,7 @@ const table &query_create_table_part::table() const
return table_; return table_;
} }
const std::vector<object::attribute_definition> &query_create_table_part::columns() const const std::vector<object::attribute> &query_create_table_part::columns() const
{ {
return columns_; return columns_;
} }

View File

@ -7,14 +7,14 @@ namespace matador::sql {
detail::pk_reader::pk_reader(query_result_reader &reader) detail::pk_reader::pk_reader(query_result_reader &reader)
: reader_(reader) {} : reader_(reader) {}
query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader, std::vector<object::attribute_definition> &&prototype, const size_t column_index) query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader, std::vector<object::attribute> &&prototype, const size_t column_index)
: column_index_(column_index) : column_index_(column_index)
, prototype_(std::move(prototype)) , prototype_(std::move(prototype))
, reader_(std::move(reader)) , reader_(std::move(reader))
, pk_reader_(*reader_) , pk_reader_(*reader_)
{} {}
query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader, const std::vector<object::attribute_definition> &prototype, const size_t column_index) query_result_impl::query_result_impl(std::unique_ptr<query_result_reader> &&reader, const std::vector<object::attribute> &prototype, const size_t column_index)
: column_index_(column_index) : column_index_(column_index)
, prototype_(prototype) , prototype_(prototype)
, reader_(std::move(reader)) , reader_(std::move(reader))
@ -43,7 +43,7 @@ query_result_impl::on_attribute(const char *id, utils::value &val, const utils::
reader_->read_value(id, column_index_++, val, attr.size()); reader_->read_value(id, column_index_++, val, attr.size());
} }
const std::vector<object::attribute_definition>& query_result_impl::prototype() const const std::vector<object::attribute>& query_result_impl::prototype() const
{ {
return prototype_; return prototype_;
} }

View File

@ -291,7 +291,7 @@ void query_compiler::visit(internal::query_create_part &/*create_part*/)
struct fk_context { struct fk_context {
std::string column; std::string column;
std::shared_ptr<object::attribute_definition> reference_column; std::shared_ptr<object::attribute> reference_column;
}; };
struct column_context struct column_context
@ -300,7 +300,7 @@ struct column_context
std::vector<fk_context> foreign_contexts; std::vector<fk_context> foreign_contexts;
}; };
std::string build_create_column(const object::attribute_definition &col, const sql::dialect &d, column_context &context); std::string build_create_column(const object::attribute &col, const sql::dialect &d, column_context &context);
void query_compiler::visit(internal::query_create_table_part &part) void query_compiler::visit(internal::query_create_table_part &part)
{ {
@ -387,7 +387,7 @@ void query_compiler::visit(internal::query_drop_table_part &part)
query_.sql += " " + build_table_name(part.token(), *dialect_, query_.table_name); query_.sql += " " + build_table_name(part.token(), *dialect_, query_.table_name);
} }
std::string build_create_column(const object::attribute_definition &col, const sql::dialect &d, column_context &context) std::string build_create_column(const object::attribute &col, const sql::dialect &d, column_context &context)
{ {
std::string result = d.prepare_identifier_string(col.name()) + " " + d.data_type_at(col.type()); std::string result = d.prepare_identifier_string(col.name()) + " " + d.data_type_at(col.type());
if (col.attributes().size() > 0) { if (col.attributes().size() > 0) {

View File

@ -137,7 +137,7 @@ utils::result<void, utils::error> connection::rollback() const {
return utils::ok<void>(); return utils::ok<void>();
} }
utils::result<std::vector<object::attribute_definition>, utils::error> connection::describe(const std::string &table_name) const { utils::result<std::vector<object::attribute>, utils::error> connection::describe(const std::string &table_name) const {
return connection_->describe(table_name); return connection_->describe(table_name);
} }
@ -154,7 +154,7 @@ utils::result<size_t, utils::error> connection::execute(const std::string &sql)
return connection_->execute(sql); return connection_->execute(sql);
} }
bool has_unknown_columns(const std::vector<object::attribute_definition> &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::type_null;
}); });
@ -229,7 +229,7 @@ utils::result<std::unique_ptr<statement_impl>, utils::error> connection::perform
[&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::type_null && rit != result->end()) {
const_cast<object::attribute_definition&>(col).change_type(rit->type()); const_cast<object::attribute&>(col).change_type(rit->type());
} }
} }
} }

View File

@ -6,7 +6,7 @@
namespace matador::sql::detail { namespace matador::sql::detail {
template<> template<>
record *create_prototype<record>(const std::vector<object::attribute_definition> &prototype) { record *create_prototype<record>(const std::vector<object::attribute> &prototype) {
auto result = std::make_unique<record>(); auto result = std::make_unique<record>();
for (const auto &col: prototype) { for (const auto &col: prototype) {
result->append({ result->append({

View File

@ -1,7 +1,7 @@
#include "catch2/catch_test_macros.hpp" #include "catch2/catch_test_macros.hpp"
#include "catch2/matchers/catch_matchers_string.hpp" #include "catch2/matchers/catch_matchers_string.hpp"
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/object/repository.hpp" #include "matador/object/repository.hpp"
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"
@ -297,27 +297,27 @@ TEST_CASE_METHOD(QueryFixture, "Test describe table", "[query][describe][table]"
"val_bool", /*"val_cstr", */"val_string", "val_varchar", "val_bool", /*"val_cstr", */"val_string", "val_varchar",
// "val_date", "val_time", // "val_date", "val_time",
"val_binary"}; "val_binary"};
const std::vector<std::function<bool (const attribute_definition&)>> type_check = { const std::vector<std::function<bool (const attribute&)>> type_check = {
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_floating_point(); }, [](const attribute &cf) { return cf.is_floating_point(); },
[](const attribute_definition &cf) { return cf.is_floating_point(); }, [](const attribute &cf) { return cf.is_floating_point(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
// [](const attribute_definition &cf) { return cf.is_integer(); }, // [](const attribute_definition &cf) { return cf.is_integer(); },
// [](const attribute_definition &cf) { return cf.is_integer(); }, // [](const attribute_definition &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_integer(); }, [](const attribute &cf) { return cf.is_integer(); },
[](const attribute_definition &cf) { return cf.is_bool(); }, [](const attribute &cf) { return cf.is_bool(); },
// [](const attribute_definition &cf) { return cf.is_varchar(); }, // [](const attribute_definition &cf) { return cf.is_varchar(); },
[](const attribute_definition &cf) { return cf.is_string(); }, [](const attribute &cf) { return cf.is_string(); },
[](const attribute_definition &cf) { return cf.is_varchar(); }, [](const attribute &cf) { return cf.is_varchar(); },
// [](const attribute_definition &cf) { return cf.is_date(); }, // [](const attribute_definition &cf) { return cf.is_date(); },
// [](const attribute_definition &cf) { return cf.is_time(); }, // [](const attribute_definition &cf) { return cf.is_time(); },
[](const attribute_definition &cf) { return cf.is_blob(); } [](const attribute &cf) { return cf.is_blob(); }
}; };
const auto &cols = columns.value(); const auto &cols = columns.value();

View File

@ -1,6 +1,6 @@
#include "catch2/catch_test_macros.hpp" #include "catch2/catch_test_macros.hpp"
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/query/criteria.hpp" #include "matador/query/criteria.hpp"
#include "matador/query/generator.hpp" #include "matador/query/generator.hpp"

View File

@ -1,6 +1,6 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
#include "matador/sql/connection.hpp" #include "matador/sql/connection.hpp"

View File

@ -20,15 +20,15 @@ TEST_CASE("Generate column definitions from object", "[column][definition][gener
auto columns = attribute_definition_generator::generate<matador::test::product>(repo); auto columns = attribute_definition_generator::generate<matador::test::product>(repo);
const std::vector expected_columns = { const std::vector expected_columns = {
attribute_definition{"product_name", basic_type::type_varchar, constraints::PRIMARY_KEY, null_option_type::NOT_NULL }, attribute{"product_name", basic_type::type_varchar, constraints::PRIMARY_KEY, null_option_type::NOT_NULL },
attribute_definition{"supplier_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option_type::NOT_NULL }, attribute{"supplier_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option_type::NOT_NULL },
attribute_definition{"category_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option_type::NOT_NULL }, attribute{"category_id", basic_type::type_uint32, constraints::FOREIGN_KEY, null_option_type::NOT_NULL },
attribute_definition{"quantity_per_unit", basic_type::type_varchar, null_attributes, null_option_type::NOT_NULL }, attribute{"quantity_per_unit", basic_type::type_varchar, null_attributes, null_option_type::NOT_NULL },
attribute_definition{"unit_price", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL }, attribute{"unit_price", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL },
attribute_definition{"units_in_stock", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL }, attribute{"units_in_stock", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL },
attribute_definition{"units_in_order", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL }, attribute{"units_in_order", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL },
attribute_definition{"reorder_level", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL }, attribute{"reorder_level", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL },
attribute_definition{"discontinued", basic_type::type_bool, null_attributes, null_option_type::NOT_NULL } attribute{"discontinued", basic_type::type_bool, null_attributes, null_option_type::NOT_NULL }
}; };
REQUIRE(!columns.empty()); REQUIRE(!columns.empty());
REQUIRE(columns.size() == expected_columns.size()); REQUIRE(columns.size() == expected_columns.size());
@ -46,9 +46,9 @@ TEST_CASE("Generate columns from object with nullable columns", "[column generat
auto columns = attribute_definition_generator::generate<matador::test::optional>(repo); auto columns = attribute_definition_generator::generate<matador::test::optional>(repo);
const std::vector expected_columns = { const std::vector expected_columns = {
attribute_definition{"id", basic_type::type_uint32, constraints::PRIMARY_KEY, null_option_type::NOT_NULL }, attribute{"id", basic_type::type_uint32, constraints::PRIMARY_KEY, null_option_type::NOT_NULL },
attribute_definition{"name", basic_type::type_varchar, null_attributes, null_option_type::NOT_NULL }, attribute{"name", basic_type::type_varchar, null_attributes, null_option_type::NOT_NULL },
attribute_definition{"age", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL } attribute{"age", basic_type::type_uint32, null_attributes, null_option_type::NOT_NULL }
}; };
REQUIRE(!columns.empty()); REQUIRE(!columns.empty());
REQUIRE(columns.size() == expected_columns.size()); REQUIRE(columns.size() == expected_columns.size());

View File

@ -57,8 +57,8 @@ utils::result<std::unique_ptr<sql::statement_impl>, utils::error> test_connectio
return utils::ok(std::move(s)); return utils::ok(std::move(s));
} }
utils::result<std::vector<object::attribute_definition>, utils::error> test_connection::describe(const std::string &/*table*/) { utils::result<std::vector<object::attribute>, utils::error> test_connection::describe(const std::string &/*table*/) {
return utils::ok(std::vector<object::attribute_definition>{}); return utils::ok(std::vector<object::attribute>{});
} }
utils::result<bool, utils::error> test_connection::exists(const std::string &/*schema_name*/, const std::string &/*table_name*/) { utils::result<bool, utils::error> test_connection::exists(const std::string &/*schema_name*/, const std::string &/*table_name*/) {

View File

@ -19,7 +19,7 @@ public:
utils::result<size_t, utils::error> execute(const std::string &stmt) override; utils::result<size_t, utils::error> execute(const std::string &stmt) override;
utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> fetch(const sql::query_context &context) override; utils::result<std::unique_ptr<sql::query_result_impl>, utils::error> fetch(const sql::query_context &context) override;
utils::result<std::unique_ptr<sql::statement_impl>, utils::error> prepare(const sql::query_context &context) override; utils::result<std::unique_ptr<sql::statement_impl>, utils::error> prepare(const sql::query_context &context) override;
utils::result<std::vector<object::attribute_definition>, utils::error> describe(const std::string &table) override; utils::result<std::vector<object::attribute>, utils::error> describe(const std::string &table) override;
utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override; utils::result<bool, utils::error> exists(const std::string &schema_name, const std::string &table_name) override;
[[nodiscard]] std::string to_escaped_string( const utils::blob& value ) const override; [[nodiscard]] std::string to_escaped_string( const utils::blob& value ) const override;

View File

@ -1,12 +1,12 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "matador/object/attribute_definition.hpp" #include "matador/object/attribute.hpp"
using namespace matador::object; using namespace matador::object;
using namespace matador::utils; using namespace matador::utils;
TEST_CASE("Test create empty column", "[column]") { TEST_CASE("Test create empty column", "[column]") {
attribute_definition c("name"); attribute c("name");
REQUIRE(c.name() == "name"); REQUIRE(c.name() == "name");
REQUIRE(c.index() == -1); REQUIRE(c.index() == -1);
@ -21,11 +21,11 @@ TEST_CASE("Test create empty column", "[column]") {
} }
TEST_CASE("Test copy and move column", "[column]") { TEST_CASE("Test copy and move column", "[column]") {
attribute_definition c( attribute c(
"name", "name",
basic_type::type_varchar, basic_type::type_varchar,
2, 2,
std::make_shared<attribute_definition>("author", basic_type::type_uint32, "books", attribute_options{constraints::FOREIGN_KEY}), std::make_shared<attribute>("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
); );