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
+163
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
@@ -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
@@ -1,7 +1,7 @@
#ifndef 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/data_type_traits.hpp"
@@ -24,9 +24,9 @@ public:
fk_attribute_generator() = default;
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);
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>
@@ -54,15 +54,15 @@ private:
class attribute_definition_generator final {
private:
attribute_definition_generator(std::vector<attribute_definition> &columns, const repository &repo);
attribute_definition_generator(std::vector<attribute> &columns, const repository &repo);
public:
~attribute_definition_generator() = default;
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);
Type obj;
access::process(gen, obj);
@@ -70,8 +70,8 @@ public:
}
template < class Type >
static std::vector<attribute_definition> generate(const Type& obj, const repository &repo) {
std::vector<attribute_definition> columns;
static std::vector<attribute> generate(const Type& obj, const repository &repo) {
std::vector<attribute> columns;
attribute_definition_generator gen(columns, repo);
access::process(gen, obj);
return columns;
@@ -98,12 +98,12 @@ public:
template <class Pointer>
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);
if (const auto result = determine_foreign_ref(std::type_index(ti))) {
ref_column = *result;
} else {
ref_column = std::make_shared<attribute_definition>();
ref_column = std::make_shared<attribute>();
insert_missing_reference_column(ti, ref_column);
}
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*/) {}
private:
[[nodiscard]] utils::result<std::shared_ptr<attribute_definition>, 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;
[[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>& ref_column) const;
private:
size_t index_ = 0;
std::vector<attribute_definition> &columns_;
std::vector<attribute> &columns_;
const repository &repo_;
fk_attribute_generator fk_column_generator_;
+7 -7
View File
@@ -1,7 +1,7 @@
#ifndef 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/utils/identifier.hpp"
@@ -24,8 +24,8 @@ public:
[[nodiscard]] std::type_index type_index() const;
[[nodiscard]] std::string name() const;
[[nodiscard]] const std::vector<attribute_definition>& attributes() const;
[[nodiscard]] std::shared_ptr<attribute_definition> reference_column() const;
[[nodiscard]] const std::vector<attribute>& attributes() const;
[[nodiscard]] std::shared_ptr<attribute> reference_column() const;
[[nodiscard]] bool has_primary_key() const;
[[nodiscard]] const utils::identifier& primary_key() const;
@@ -49,14 +49,14 @@ public:
[[nodiscard]] bool endpoints_empty() const;
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_definition> &attributes);
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> &attributes);
protected:
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::shared_ptr<attribute_definition> pk_as_fk_column_;
std::shared_ptr<attribute> pk_as_fk_column_;
t_endpoint_map relation_endpoints_;
};
+3 -3
View File
@@ -12,15 +12,15 @@ public:
using create_func = std::function<std::unique_ptr<Type>()>;
object_info(const std::shared_ptr<repository_node>& node,
const std::vector<attribute_definition> &attributes,
const std::vector<attribute> &attributes,
utils::identifier &&pk,
const std::shared_ptr<attribute_definition> &ref_column,
const std::shared_ptr<attribute> &ref_column,
create_func&& creator)
: basic_object_info(node, attributes, std::move(pk), ref_column)
, creator_(std::move(creator)){
}
object_info(const std::shared_ptr<repository_node>& node,
const std::vector<attribute_definition> &attributes,
const std::vector<attribute> &attributes,
create_func&& creator)
: basic_object_info(node, attributes)
, creator_(std::move(creator)){
+2 -2
View File
@@ -150,7 +150,7 @@ public:
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;
void dump(std::ostream &os) const;
@@ -187,7 +187,7 @@ private:
t_type_index_node_map nodes_by_type_;
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_;
};
}
+1 -1
View File
@@ -90,7 +90,7 @@ private:
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 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 primary_key_info& pk_info,
repository& repo);
+1 -1
View File
@@ -46,7 +46,7 @@ public:
[[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<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;
private:
+2 -2
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<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;
void dump_schema(std::ostream &os) const;
@@ -150,7 +150,7 @@ private:
const sql::dialect &dialect_;
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>
+21 -22
View File
@@ -1,12 +1,11 @@
#ifndef MATADOR_BUILDER_HPP
#define MATADOR_BUILDER_HPP
#include "matador/object/attribute_definition.hpp"
#include "matador/query/column.hpp"
#include "matador/query/table.hpp"
#include "matador/utils/basic_types.hpp"
#include "matador/utils/constraints.hpp"
#include <string>
@@ -24,26 +23,26 @@ private:
std::string alias_;
};
class attribute {
public:
attribute(std::string name, const utils::basic_type type)
: name_(std::move(name))
, type_(type) {}
[[nodiscard]] const std::string& name() const;
[[nodiscard]] utils::basic_type type() const;
[[nodiscard]] const attribute_options& options() const;
private:
friend class entity;
std::string name_;
std::string alias_;
utils::basic_type type_{};
attribute_options options_;
entity* owner_{nullptr};
};
// class attribute {
// public:
// attribute(std::string name, const utils::basic_type type)
// : name_(std::move(name))
// , type_(type) {}
//
// [[nodiscard]] const std::string& name() const;
// [[nodiscard]] utils::basic_type type() const;
// [[nodiscard]] const attribute_options& options() const;
//
// private:
// friend class entity;
//
// std::string name_;
// std::string alias_;
// utils::basic_type type_{};
// attribute_options options_;
//
// entity* owner_{nullptr};
// };
class constraint {
public:
@@ -13,8 +13,8 @@ class query_create_intermediate : public query_intermediate {
public:
query_create_intermediate();
executable_query table(const table &tab, std::initializer_list<object::attribute_definition> columns);
executable_query table(const query::table &tab, const std::vector<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> &columns);
template<class Type>
executable_query table(const matador::query::table &tab, const object::repository &schema) {
return this->table(tab, object::attribute_definition_generator::generate<Type>(schema));
@@ -9,7 +9,7 @@
#include "matador/query/column.hpp"
#include "matador/query/table.hpp"
#include "matador/object/attribute_definition.hpp"
#include "matador/object/attribute.hpp"
#include "matador/utils/placeholder.hpp"
@@ -364,17 +364,17 @@ private:
class query_create_table_part final : public query_part
{
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 std::vector<object::attribute_definition>& columns() const;
[[nodiscard]] const std::vector<object::attribute>& columns() const;
private:
void accept(query_part_visitor &visitor) override;
private:
class table table_;
std::vector<object::attribute_definition> columns_;
std::vector<object::attribute> columns_;
};
class query_create_schema_part final : public query_part {
+2 -2
View File
@@ -4,7 +4,7 @@
#include <memory>
#include <vector>
#include "matador/object/attribute_definition.hpp"
#include "matador/object/attribute.hpp"
#include "matador/query/table.hpp"
#include "matador/query/query_part.hpp"
@@ -13,7 +13,7 @@ namespace matador::query {
struct query_data {
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{};
};
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef 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/connection_info.hpp"
@@ -126,7 +126,7 @@ public:
*/
[[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 &table_name) const;
@@ -3,7 +3,7 @@
#include <memory>
#include "matador/object/attribute_definition.hpp"
#include "matador/object/attribute.hpp"
#include "matador/sql/connection_info.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<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;
[[nodiscard]] const class dialect &dialect() const;
@@ -12,7 +12,7 @@
#include "matador/sql/internal/query_result_pk_resolver.hpp"
#include "matador/sql/record.hpp"
#include "matador/object/attribute_definition.hpp"
#include "matador/object/attribute.hpp"
#include <iostream>
#include <memory>
@@ -73,9 +73,9 @@ private:
class query_result_impl {
public:
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,
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>
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;
}
[[nodiscard]] const std::vector<object::attribute_definition> &prototype() const;
[[nodiscard]] const std::vector<object::attribute> &prototype() const;
private:
template<class Type>
@@ -209,7 +209,7 @@ private:
protected:
size_t column_index_ = 0;
std::vector<object::attribute_definition> prototype_;
std::vector<object::attribute> prototype_;
std::unique_ptr<query_result_reader> reader_;
detail::pk_reader pk_reader_;
std::stack<std::type_index> type_stack_;
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef 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/utils/types.hpp"
@@ -36,7 +36,7 @@ struct query_context {
std::string command_name{};
std::string schema_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> bind_vars{};
std::vector<utils::database_type> bind_types{};
+2 -2
View File
@@ -9,12 +9,12 @@
#include <string>
#include <ostream>
#define FIELD(x) const sql::column x{*this, #x, ""};
#define FIELD(x) const query::column x{*this, #x, ""};
#define QUERY_HELPER(C, ...) \
namespace matador::qh { \
namespace internal { \
struct C##_query : sql::table { \
struct C##_query : query::table { \
C##_query() : table(#C) {} \
MAP(FIELD, __VA_ARGS__) \
}; } \
+3 -3
View File
@@ -1,7 +1,7 @@
#ifndef 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"
@@ -102,12 +102,12 @@ private:
namespace detail {
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{};
}
template <>
record* create_prototype<record>(const std::vector<object::attribute_definition> &prototype);
record* create_prototype<record>(const std::vector<object::attribute> &prototype);
}