schema progress (does not compile)
This commit is contained in:
@@ -68,25 +68,25 @@ public:
|
||||
operator column() const; // NOLINT(*-explicit-constructor)
|
||||
|
||||
column_builder& not_null();
|
||||
column_builder& primary_key();
|
||||
column_builder& unique();
|
||||
|
||||
private:
|
||||
std::string column_name_;
|
||||
utils::basic_type type_{};
|
||||
utils::constraints constraints_{};
|
||||
utils::constraints constraints_{utils::constraints::NotNull};
|
||||
size_t size_{0};
|
||||
};
|
||||
|
||||
class table_builder {
|
||||
public:
|
||||
explicit table_builder(std::string name);
|
||||
|
||||
table_builder& as(std::string table_alias);
|
||||
|
||||
// ReSharper disable once CppNonExplicitConversionOperator
|
||||
operator table() const; // NOLINT(*-explicit-constructor)
|
||||
|
||||
private:
|
||||
std::string table_name;
|
||||
std::string alias;
|
||||
};
|
||||
|
||||
class constraint_builder {
|
||||
@@ -100,16 +100,16 @@ public:
|
||||
operator class constraint() const; // NOLINT(*-explicit-constructor)
|
||||
|
||||
private:
|
||||
std::string constraint_name;
|
||||
std::string pk_column_name;
|
||||
std::string fk_column_name;
|
||||
std::string table_name;
|
||||
std::string column_name;
|
||||
std::string constraint_name_;
|
||||
std::string column_name_;
|
||||
std::string ref_table_name_;
|
||||
std::string ref_column_name_;
|
||||
utils::constraints type_{};
|
||||
};
|
||||
|
||||
constraint_builder constraint(std::string name);
|
||||
// table_builder table(std::string name);
|
||||
// column_builder column(std::string name, utils::basic_type type, size_t size = 0);
|
||||
column_builder column(std::string name, utils::basic_type type, size_t size = 0);
|
||||
|
||||
}
|
||||
#endif //MATADOR_BUILDER_HPP
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
@@ -23,6 +24,9 @@ public:
|
||||
column(const class table* tab, std::string name);
|
||||
column(const class table* tab, std::string name, std::string alias);
|
||||
column(const class table* tab, std::string name, utils::basic_type type, const utils::field_attributes& attributes);
|
||||
column(const class table*, std::string name, std::string alias, utils::basic_type type, const utils::field_attributes& attributes);
|
||||
column& operator=(const column& other);
|
||||
column(const column& other);
|
||||
|
||||
[[nodiscard]] bool equals(const column &x) const;
|
||||
|
||||
@@ -39,18 +43,15 @@ public:
|
||||
[[nodiscard]] bool has_alias() const;
|
||||
|
||||
[[nodiscard]] const class table* table() const;
|
||||
void table(const query::table* t);
|
||||
void table(const query::table* tab);
|
||||
|
||||
// ReSharper disable once CppNonExplicitConversionOperator
|
||||
operator const std::string&() const; // NOLINT(*-explicit-constructor)
|
||||
|
||||
private:
|
||||
static query::table* default_table();
|
||||
|
||||
private:
|
||||
friend class table;
|
||||
|
||||
const query::table* table_{nullptr};
|
||||
const class table* table_{nullptr};
|
||||
std::string name_;
|
||||
std::string alias_;
|
||||
utils::basic_type type_{utils::basic_type::Unknown};
|
||||
|
||||
@@ -13,7 +13,9 @@ public:
|
||||
constraint() = default;
|
||||
constraint(std::string column_name, std::string table_name, utils::constraints type);
|
||||
constraint(std::string column_name, std::string table_name, utils::constraints type, std::string referenced_table, std::string referenced_column);
|
||||
constraint(std::string name, std::string column_name, std::string table_name, utils::constraints type, std::string referenced_table, std::string referenced_column);
|
||||
|
||||
[[nodiscard]] std::string name() const;
|
||||
[[nodiscard]] std::string column_name() const;
|
||||
[[nodiscard]] std::string table_name() const;
|
||||
[[nodiscard]] const utils::constraints& type() const;
|
||||
@@ -24,6 +26,7 @@ public:
|
||||
[[nodiscard]] const std::string& referenced_column() const;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string column_name_;
|
||||
std::string table_name_;
|
||||
utils::constraints type_{};
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace matador::query {
|
||||
class abstract_column_criteria : public abstract_criteria {
|
||||
public:
|
||||
abstract_column_criteria() = delete;
|
||||
explicit abstract_column_criteria(column col);
|
||||
explicit abstract_column_criteria(const class column& col);
|
||||
|
||||
[[nodiscard]] const column& col() const;
|
||||
[[nodiscard]] const class column& col() const;
|
||||
|
||||
protected:
|
||||
column column_;
|
||||
class column column_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,15 +4,13 @@
|
||||
#include "matador/query/criteria/abstract_column_criteria.hpp"
|
||||
#include "matador/query/criteria/criteria_utils.hpp"
|
||||
|
||||
#include "matador/utils/value.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
class between_criteria final : public abstract_column_criteria {
|
||||
public:
|
||||
between_criteria() = delete;
|
||||
between_criteria(column col, int64_t min, int64_t max);
|
||||
between_criteria(column col, utils::placeholder min, utils::placeholder max);
|
||||
between_criteria(const class column& col, int64_t min, int64_t max);
|
||||
between_criteria(const class column& col, utils::placeholder min, utils::placeholder max);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ enum class binary_operator {
|
||||
class binary_criteria final : public abstract_column_criteria {
|
||||
public:
|
||||
binary_criteria() = delete;
|
||||
binary_criteria(column col, binary_operator operand, criteria_value value);
|
||||
binary_criteria(const class column& col, binary_operator operand, criteria_value value);
|
||||
|
||||
void accept( criteria_visitor& visitor ) const override;
|
||||
|
||||
@@ -34,18 +34,18 @@ private:
|
||||
class binary_column_criteria final : public abstract_criteria {
|
||||
public:
|
||||
binary_column_criteria() = delete;
|
||||
binary_column_criteria(column left_column, binary_operator operand, column right_column);
|
||||
binary_column_criteria(const class column& left_column, binary_operator operand, const class column& right_column);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
[[nodiscard]] const column& left_column() const;
|
||||
[[nodiscard]] const class column& left_column() const;
|
||||
[[nodiscard]] binary_operator operand() const;
|
||||
[[nodiscard]] const column& right_column() const;
|
||||
[[nodiscard]] const class column& right_column() const;
|
||||
|
||||
private:
|
||||
column left_column_;
|
||||
class column left_column_;
|
||||
binary_operator operator_{};
|
||||
column right_column_;
|
||||
class column right_column_;
|
||||
};
|
||||
}
|
||||
#endif //CRITERIA_BINARY_CRITERIA_NODE_HPP
|
||||
@@ -4,10 +4,12 @@
|
||||
#include "matador/query/criteria/abstract_column_criteria.hpp"
|
||||
#include "matador/query/criteria/criteria_utils.hpp"
|
||||
|
||||
#include "matador/query/column.hpp"
|
||||
#include "matador/query/table.hpp"
|
||||
#include "matador/sql/query_context.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
class column;
|
||||
|
||||
enum class collection_operator {
|
||||
In,
|
||||
Out
|
||||
@@ -36,8 +38,8 @@ public:
|
||||
* @param operand_ Operator to use
|
||||
* @param values List of values
|
||||
*/
|
||||
collection_criteria(column col, collection_operator operand_, std::vector<criteria_value> values);
|
||||
collection_criteria(column col, collection_operator operand_, std::initializer_list<criteria_value> values);
|
||||
collection_criteria(const class column& col, collection_operator operand_, std::vector<criteria_value> values);
|
||||
collection_criteria(const class column& col, collection_operator operand_, std::initializer_list<criteria_value> values);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
@@ -52,7 +54,7 @@ private:
|
||||
class collection_query_criteria final : public abstract_column_criteria {
|
||||
public:
|
||||
collection_query_criteria() = delete;
|
||||
collection_query_criteria(column col, collection_operator operand_, sql::query_context ctx);
|
||||
collection_query_criteria(const class column& col, collection_operator operand_, sql::query_context ctx);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
|
||||
@@ -14,48 +14,48 @@ namespace matador::query {
|
||||
class column;
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator==(const column &col, Type val) {
|
||||
criteria_ptr operator==(const class column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::EQUALS, utils::value(val));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator!=(const column &col, Type val) {
|
||||
criteria_ptr operator!=(const class column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::NOT_EQUALS, utils::value(val));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator>(const column &col, Type val) {
|
||||
criteria_ptr operator>(const class column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::GREATER_THAN, utils::value(val));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator>=(const column &col, Type val) {
|
||||
criteria_ptr operator>=(const class column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::GREATER_THAN_OR_EQUAL, utils::value(val));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator<(const column &col, Type val) {
|
||||
criteria_ptr operator<(const class column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::LESS_THAN, utils::value(val));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator<=(const column &col, Type val) {
|
||||
criteria_ptr operator<=(const class column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::LESS_THAN_OR_EQUAL, utils::value(val));
|
||||
}
|
||||
|
||||
criteria_ptr operator==(const column &col_left, const column &col_right);
|
||||
criteria_ptr operator!=(const column &col_left, const column &col_right);
|
||||
criteria_ptr operator>(const column &col_left, const column &col_right);
|
||||
criteria_ptr operator>=(const column &col_left, const column &col_right);
|
||||
criteria_ptr operator<(const column &col_left, const column &col_right);
|
||||
criteria_ptr operator<=(const column &col_left, const column &col_right);
|
||||
criteria_ptr operator==(const class column &col_left, const class column &col_right);
|
||||
criteria_ptr operator!=(const class column &col_left, const class column &col_right);
|
||||
criteria_ptr operator>(const class column &col_left, const class column &col_right);
|
||||
criteria_ptr operator>=(const class column &col_left, const class column &col_right);
|
||||
criteria_ptr operator<(const class column &col_left, const class column &col_right);
|
||||
criteria_ptr operator<=(const class column &col_left, const class column &col_right);
|
||||
|
||||
criteria_ptr operator==(const column &col, utils::placeholder p);
|
||||
criteria_ptr operator!=(const column &col, utils::placeholder p);
|
||||
criteria_ptr operator>(const column &col, utils::placeholder p);
|
||||
criteria_ptr operator>=(const column &col, utils::placeholder p);
|
||||
criteria_ptr operator<(const column &col, utils::placeholder p);
|
||||
criteria_ptr operator<=(const column &col, utils::placeholder p);
|
||||
criteria_ptr operator==(const class column &col, utils::placeholder p);
|
||||
criteria_ptr operator!=(const class column &col, utils::placeholder p);
|
||||
criteria_ptr operator>(const class column &col, utils::placeholder p);
|
||||
criteria_ptr operator>=(const class column &col, utils::placeholder p);
|
||||
criteria_ptr operator<(const class column &col, utils::placeholder p);
|
||||
criteria_ptr operator<=(const class column &col, utils::placeholder p);
|
||||
|
||||
criteria_ptr operator&&(criteria_ptr left, criteria_ptr right);
|
||||
|
||||
@@ -64,7 +64,7 @@ criteria_ptr operator||(criteria_ptr left, criteria_ptr right);
|
||||
criteria_ptr operator!(criteria_ptr clause);
|
||||
|
||||
template < class Type >
|
||||
criteria_ptr in(const column &col, std::initializer_list<Type> args) {
|
||||
criteria_ptr in(const class column &col, std::initializer_list<Type> args) {
|
||||
std::vector<criteria_value> values;
|
||||
for ( auto &&arg : args ) {
|
||||
values.emplace_back(utils::value{std::move(arg)});
|
||||
@@ -73,12 +73,12 @@ criteria_ptr in(const column &col, std::initializer_list<Type> args) {
|
||||
}
|
||||
|
||||
template <>
|
||||
criteria_ptr in(const column &col, std::initializer_list<utils::placeholder> args);
|
||||
criteria_ptr in(const class column &col, std::initializer_list<utils::placeholder> args);
|
||||
|
||||
criteria_ptr in(const column &col, sql::query_context &&ctx);
|
||||
criteria_ptr in(const class column &col, sql::query_context &&ctx);
|
||||
|
||||
template < class Type >
|
||||
criteria_ptr out(const column &col, std::initializer_list<Type> args) {
|
||||
criteria_ptr out(const class column &col, std::initializer_list<Type> args) {
|
||||
std::vector<criteria_value> values;
|
||||
for ( auto &&arg : args ) {
|
||||
values.emplace_back(utils::value{std::move(arg)});
|
||||
@@ -87,14 +87,14 @@ criteria_ptr out(const column &col, std::initializer_list<Type> args) {
|
||||
}
|
||||
|
||||
template <>
|
||||
criteria_ptr out(const column &col, std::initializer_list<utils::placeholder> args);
|
||||
criteria_ptr out(const class column &col, std::initializer_list<utils::placeholder> args);
|
||||
|
||||
criteria_ptr out(const column &col, sql::query_context &&ctx);
|
||||
criteria_ptr out(const class column &col, sql::query_context &&ctx);
|
||||
|
||||
criteria_ptr between(const column &col, int64_t min, int64_t max);
|
||||
criteria_ptr between(const column &col, utils::placeholder min, utils::placeholder max);
|
||||
criteria_ptr between(const class column &col, int64_t min, int64_t max);
|
||||
criteria_ptr between(const class column &col, utils::placeholder min, utils::placeholder max);
|
||||
|
||||
criteria_ptr like(const column &col, const std::string &pattern);
|
||||
criteria_ptr like(const class column &col, const std::string &pattern);
|
||||
|
||||
}
|
||||
#endif //CRITERIA_CRITERIA_OPERATORS_HPP
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "matador/query/criteria/abstract_column_criteria.hpp"
|
||||
|
||||
#include "matador/query/column.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
class column;
|
||||
|
||||
class like_criteria final : public abstract_column_criteria {
|
||||
public:
|
||||
like_criteria() = delete;
|
||||
like_criteria(column col, std::string pattern);
|
||||
like_criteria(const class column& col, std::string pattern);
|
||||
|
||||
void accept(criteria_visitor &visitor) const override;
|
||||
|
||||
|
||||
@@ -45,8 +45,6 @@ constexpr auto default_column_generator_options = column_generator_options::Forc
|
||||
|
||||
class column_generator {
|
||||
public:
|
||||
explicit column_generator(const std::string &table_name = "",
|
||||
column_generator_options options = default_column_generator_options);
|
||||
explicit column_generator(const schema &repo,
|
||||
const std::string &table_name = "",
|
||||
column_generator_options options = default_column_generator_options);
|
||||
@@ -322,20 +320,5 @@ std::vector<column> columns(const Type &obj,
|
||||
return generator.generate(obj);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
std::vector<column> columns(const std::string &table_name = "",
|
||||
const column_generator_options options = default_column_generator_options) {
|
||||
column_generator generator(table_name, options);
|
||||
return generator.generate<Type>();
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
std::vector<column> columns(const Type &obj,
|
||||
const std::string &table_name = "",
|
||||
const column_generator_options options = default_column_generator_options) {
|
||||
column_generator generator(table_name, options);
|
||||
return generator.generate(obj);
|
||||
}
|
||||
|
||||
}
|
||||
#endif //MATADOR_GENERATOR_HPP
|
||||
@@ -3,19 +3,18 @@
|
||||
|
||||
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||
#include "matador/query/intermediates/query_into_intermediate.hpp"
|
||||
|
||||
#include "matador/query/schema.hpp"
|
||||
#include "matador/query/generator.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
class query_insert_intermediate : public query_intermediate
|
||||
{
|
||||
class query_insert_intermediate : public query_intermediate {
|
||||
public:
|
||||
query_insert_intermediate();
|
||||
|
||||
template<class Type>
|
||||
query_into_intermediate into(const table &tab, const object::repository &schema) {
|
||||
return into(tab, generator::columns<Type>(schema));
|
||||
query_into_intermediate into(const table &tab, const schema &scm) {
|
||||
return into(tab, generator::columns<Type>(scm));
|
||||
}
|
||||
query_into_intermediate into(const table &tab, std::initializer_list<column> columns);
|
||||
query_into_intermediate into(const table &tab, std::vector<column> &&columns);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "matador/query/query_intermediates.hpp"
|
||||
|
||||
#include "matador/query/generator.hpp"
|
||||
#include "matador/query/schema.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
class connection;
|
||||
@@ -26,8 +27,8 @@ public:
|
||||
[[nodiscard]] static query_select_intermediate select(const std::vector<std::string> &column_names);
|
||||
[[nodiscard]] static query_select_intermediate select(std::vector<column> columns, std::initializer_list<column> additional_columns);
|
||||
template<class Type>
|
||||
[[nodiscard]] static query_select_intermediate select(const object::repository &schema) {
|
||||
return select(generator::columns<Type>(schema));
|
||||
[[nodiscard]] static query_select_intermediate select(const schema &scm) {
|
||||
return select(generator::columns<Type>(scm));
|
||||
}
|
||||
[[nodiscard]] static query_insert_intermediate insert();
|
||||
[[nodiscard]] static query_update_intermediate update(const table &table);
|
||||
|
||||
@@ -77,9 +77,9 @@ protected:
|
||||
static std::string build_table_name(sql::dialect_token token, const sql::dialect &d, const table& t);
|
||||
static std::string determine_value(value_visitor &visitor, const std::variant<utils::placeholder, utils::database_type> &val);
|
||||
|
||||
std::string build_add_constraint_string(const class constraint& c);
|
||||
std::string build_drop_constraint_string(const class constraint& c);
|
||||
std::string build_constraint_name(const class constraint& c);
|
||||
std::string build_add_constraint_string(const class constraint& c) const;
|
||||
std::string build_drop_constraint_string(const class constraint& c) const;
|
||||
static std::string build_constraint_name(const class constraint& c);
|
||||
|
||||
protected:
|
||||
const query_data *data_{};
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace matador::query {
|
||||
class column;
|
||||
|
||||
[[nodiscard]] std::string prepare_identifier(const sql::dialect& d, const column &col);
|
||||
[[nodiscard]] std::string prepare_identifier(const sql::dialect& d, const table &tab, const column &col);
|
||||
[[nodiscard]] std::string prepare_criteria(const sql::dialect& d, const column &col);
|
||||
}
|
||||
#endif //MATADOR_QUERY_UTILS_HPP
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
namespace matador::sql {
|
||||
class connection_pool;
|
||||
class connection;
|
||||
}
|
||||
|
||||
namespace matador::query {
|
||||
@@ -34,20 +35,42 @@ class schema_observer final : public object::observer<Type> {
|
||||
public:
|
||||
explicit schema_observer(schema& s)
|
||||
: schema_(s) {}
|
||||
void on_attach(object::repository_node &node, const Type &prototype) override;
|
||||
void on_detach(object::repository_node &node, const Type &prototype) override;
|
||||
void on_insert(Type &obj) override;
|
||||
void on_update(Type &obj) override;
|
||||
void on_delete(Type &obj) override;
|
||||
template<typename OtherType>
|
||||
explicit schema_observer(const schema_observer<OtherType> &x)
|
||||
: schema_(x.schema_)
|
||||
{}
|
||||
void on_attach(const object::repository_node &node, const Type &prototype) const override;
|
||||
void on_detach(const object::repository_node &node, const Type &prototype) const override;
|
||||
void on_insert(const Type &obj) override;
|
||||
void on_update(const Type &obj) override;
|
||||
void on_delete(const Type &obj) override;
|
||||
|
||||
private:
|
||||
template < class OtherType >
|
||||
friend class schema_observer;
|
||||
|
||||
schema& schema_;
|
||||
};
|
||||
|
||||
class schema_node final {
|
||||
public:
|
||||
schema_node(class table tab, const object::repository_node& node);
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const class table& table() const;
|
||||
[[nodiscard]] const object::repository_node& node() const;
|
||||
|
||||
private:
|
||||
class table table_;
|
||||
const object::repository_node& node_;
|
||||
};
|
||||
class schema final {
|
||||
public:
|
||||
explicit schema(sql::connection_pool &pool);
|
||||
schema(sql::connection_pool &pool, const std::string &name);
|
||||
using iterator = std::unordered_map<std::type_index, schema_node>::iterator;
|
||||
using const_iterator = std::unordered_map<std::type_index, schema_node>::const_iterator;
|
||||
|
||||
schema() = default;
|
||||
explicit schema(const std::string &name);
|
||||
|
||||
template<typename Type, typename... Observers>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &name, Observers&&... observers) {
|
||||
@@ -64,21 +87,33 @@ public:
|
||||
return repo_.attach<Type, SuperType>(name, schema_observer<Type>{*this}, std::forward<Observers>(observers)...);
|
||||
}
|
||||
|
||||
[[nodiscard]] utils::result<void, utils::error> create() const;
|
||||
[[nodiscard]] utils::result<void, utils::error> drop() const;
|
||||
[[nodiscard]] utils::result<void, utils::error> create(const sql::connection &conn) const;
|
||||
[[nodiscard]] utils::result<void, utils::error> drop(const sql::connection &conn) const;
|
||||
|
||||
template<typename Type>
|
||||
[[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 sql::connection &conn);
|
||||
[[nodiscard]] utils::result<void, utils::error> drop_table(const std::string &table_name, const sql::connection &conn) 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<std::vector<object::attribute>, utils::error> describe_table(const std::string &table_name, const sql::connection &conn) const;
|
||||
[[nodiscard]] utils::result<bool, utils::error> table_exists(const std::string &table_name, const sql::connection &conn) const;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
||||
iterator find(const std::type_index& ti) { return schema_nodes_.find(ti); }
|
||||
const_iterator find(const std::type_index& ti) const { return schema_nodes_.find(ti); }
|
||||
|
||||
iterator find(const std::string& name);
|
||||
const_iterator find(const std::string& name) const;
|
||||
|
||||
const object::repository &repo() const { return repo_; }
|
||||
object::repository &repo() { return repo_; }
|
||||
|
||||
private:
|
||||
[[nodiscard]] sql::query_context build_add_constraint_context( const object::repository_node& node, const object::restriction& cons ) const;
|
||||
[[nodiscard]] sql::query_context build_drop_constraint_context( const object::repository_node& node, const object::restriction& cons ) const;
|
||||
[[nodiscard]] sql::query_context build_add_constraint_context(const object::repository_node& node, const object::restriction& cons, const sql::connection &conn) const;
|
||||
[[nodiscard]] sql::query_context build_drop_constraint_context(const object::repository_node& node, const object::restriction& cons, const sql::connection &conn) const;
|
||||
|
||||
void insert_table(const std::type_index& ti, const object::repository_node &node);
|
||||
|
||||
@@ -87,31 +122,30 @@ private:
|
||||
friend class schema_observer;
|
||||
|
||||
object::repository repo_;
|
||||
std::unordered_map<std::type_index, table> tables_;
|
||||
sql::connection_pool &pool_;
|
||||
std::unordered_map<std::type_index, schema_node> schema_nodes_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> schema::drop_table() {
|
||||
utils::result<void, utils::error> schema::drop_table(const sql::connection &conn) {
|
||||
auto info = repo_.info<Type>();
|
||||
if (info) {
|
||||
return drop_table(info->get().name());
|
||||
return drop_table(info->get().name(), conn);
|
||||
}
|
||||
|
||||
return utils::failure(info.err());
|
||||
}
|
||||
template <typename Type>
|
||||
void schema_observer<Type>::on_attach(object::repository_node &node, const Type &prototype) {
|
||||
void schema_observer<Type>::on_attach(const object::repository_node &node, const Type &/*prototype*/) const {
|
||||
schema_.insert_table(typeid(Type), node);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void schema_observer<Type>::on_detach(object::repository_node &node, const Type &prototype) {}
|
||||
void schema_observer<Type>::on_detach(const object::repository_node &/*node*/, const Type &/*prototype*/) const {}
|
||||
template <typename Type>
|
||||
void schema_observer<Type>::on_insert(Type &obj) {}
|
||||
void schema_observer<Type>::on_insert(const Type &/*obj*/) {}
|
||||
template <typename Type>
|
||||
void schema_observer<Type>::on_update(Type &obj) {}
|
||||
void schema_observer<Type>::on_update(const Type &/*obj*/) {}
|
||||
template <typename Type>
|
||||
void schema_observer<Type>::on_delete(Type &obj) {}
|
||||
void schema_observer<Type>::on_delete(const Type &/*obj*/) {}
|
||||
} // namespace matador::query
|
||||
#endif //MATADOR_SCHEMA_HPP
|
||||
@@ -13,24 +13,36 @@ class table {
|
||||
public:
|
||||
table() = default;
|
||||
table(const char *name); // NOLINT(*-explicit-constructor)
|
||||
table(std::string name); // NOLINT(*-explicit-constructor)
|
||||
table(std::string name, std::string as);
|
||||
table(std::string name, std::string as, const std::vector<column> &columns);
|
||||
table(const std::string& name); // NOLINT(*-explicit-constructor)
|
||||
table(const std::string& name, const std::vector<column>& columns);
|
||||
table(const table& other);
|
||||
table& operator=(const table& other);
|
||||
table(table&& other) noexcept;
|
||||
table& operator=(table&& other) noexcept;
|
||||
~table() = default;
|
||||
|
||||
table as(const std::string &a);
|
||||
[[nodiscard]] table as(const std::string &alias) const;
|
||||
|
||||
[[nodiscard]] bool operator==(const table &x) const;
|
||||
|
||||
[[nodiscard]] table as(const std::string &a) const;
|
||||
[[nodiscard]] const std::string& table_name() const;
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const std::vector<column>& columns() const;
|
||||
|
||||
[[nodiscard]] bool has_alias() const;
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] const std::string& alias() const;
|
||||
[[nodiscard]] const std::vector<column>& columns() const;
|
||||
|
||||
// ReSharper disable once CppNonExplicitConversionOperator
|
||||
operator const std::vector<query::column>&() const; // NOLINT(*-explicit-constructor)
|
||||
|
||||
const class column* operator[](const std::string& column_name) const;
|
||||
static const class column* column_by_name(const table &tab, const std::string& column_name);
|
||||
|
||||
protected:
|
||||
static const column& create_column(class table& tab, const std::string& name);
|
||||
|
||||
private:
|
||||
table(std::string name, std::string alias, const std::vector<column>& columns);
|
||||
|
||||
private:
|
||||
friend class column;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user