observer progress, added to schema and added schema_observer class

This commit is contained in:
Sascha Kühl
2025-12-19 15:56:36 +01:00
parent 5e2d2ddde5
commit d104222fdd
16 changed files with 205 additions and 116 deletions
+20 -7
View File
@@ -21,25 +21,38 @@ column operator ""_col(const char *name, const size_t len) {
return column{new table(str.substr(0, pos)), str.substr(pos + 1)};
}
column::column(const char *name, const std::string& as)
: column(std::string(name), as)
column::column(const char *name)
: column(std::string(name))
{}
column::column(std::string name, std::string as)
column::column(std::string name)
: table_(default_table())
, name_(std::move(name)) {}
column::column(std::string name, std::string alias)
: table_(default_table())
, name_(std::move(name))
, alias_(std::move(as)) {}
, alias_(std::move(alias)) {}
column::column(const sql::sql_function_t func, std::string name)
: table_(default_table())
, name_(std::move(name))
, function_(func) {}
column::column(const class table* tab, std::string name, std::string as)
column::column(const class table* tab, std::string name)
: table_(tab)
, name_(std::move(name)) {}
column::column(const class query::table* tab, std::string name, std::string alias)
: table_(tab)
, name_(std::move(name))
, alias_(std::move(as)) {
}
, alias_(std::move(alias)) {}
column::column(const class query::table* tab, std::string name,
const utils::basic_type type,
const utils::field_attributes& attributes)
: table_(tab)
, name_(std::move(name))
, type_(type)
, attributes_(attributes) {}
bool column::equals(const column &x) const {
return *table_ == *x.table_ &&
+1 -1
View File
@@ -6,7 +6,7 @@ column_generator::column_generator(const std::string& table_name, const column_g
table_stack_.push(table_name.empty() ? std::make_shared<table>() : std::make_shared<table>(table_name));
}
column_generator::column_generator(const object::repository& repo, const std::string& table_name, const column_generator_options options)
column_generator::column_generator(const schema& repo, const std::string& table_name, const column_generator_options options)
: repo_(std::cref(repo))
, options_(options) {
table_stack_.push(table_name.empty() ? std::make_shared<table>() : std::make_shared<table>(table_name));
+14 -4
View File
@@ -2,6 +2,8 @@
#include "matador/query/query.hpp"
#include "matador/object/repository_node.hpp"
#include "matador/sql/backend_provider.hpp"
#include "matador/sql/connection_pool.hpp"
#include "matador/sql/dialect.hpp"
@@ -196,9 +198,17 @@ sql::query_context schema::build_add_constraint_context( const object::repositor
}
sql::query_context schema::build_drop_constraint_context( const object::repository_node& node, const object::restriction& cons ) const {
return query::query::alter()
.table(node.name())
.drop_constraint(cons)
.compile(*pool_.acquire());
return query::query::alter()
.table(node.name())
.drop_constraint(cons)
.compile(*pool_.acquire());
}
void schema::insert_table(const std::type_index& ti, const object::repository_node& node) {
std::vector<column> columns;
for (const auto &attr : node.info().attributes()) {
columns.emplace_back(nullptr, attr.name(), attr.type(), attr.attributes());
}
std::ignore = tables_.insert({ti, table(node.name(), "", columns)}).first;
}
} // namespace matador::query
+5 -1
View File
@@ -18,7 +18,11 @@ table::table(std::string name, std::string as)
table::table( std::string name, std::string as, const std::vector<query::column>& columns )
: name_(std::move(name))
, alias_(std::move(as))
, columns_(columns) {}
, columns_(columns) {
for (auto& col : columns_) {
col.table_ = this;
}
}
bool table::operator==( const table& x ) const {
return name_ == x.name_;