attaching schema nodes progress
This commit is contained in:
@@ -55,8 +55,8 @@ const utils::identifier& basic_object_info::primary_key() const {
|
||||
return identifier_.value();
|
||||
}
|
||||
|
||||
void basic_object_info::register_relation_endpoint(const std::type_index &type, const std::shared_ptr<relation_endpoint> &endpoint) {
|
||||
relation_endpoints_.insert(std::make_pair(type, endpoint));
|
||||
basic_object_info::endpoint_iterator basic_object_info::register_relation_endpoint(const std::type_index &type, const std::shared_ptr<relation_endpoint> &endpoint) {
|
||||
return relation_endpoints_.insert(std::make_pair(type, endpoint)).first;
|
||||
}
|
||||
|
||||
void basic_object_info::unregister_relation_endpoint(const std::type_index &type) {
|
||||
|
||||
@@ -19,6 +19,10 @@ utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::find_node( c
|
||||
return schema_.find_node(type_index);
|
||||
}
|
||||
|
||||
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::find_node( const std::string& name ) const {
|
||||
return schema_.find_node(name);
|
||||
}
|
||||
|
||||
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::attach_node( const std::shared_ptr<schema_node>& node ) const {
|
||||
return schema_.attach_node(node, "");
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::refer
|
||||
|
||||
void schema::dump(std::ostream &os) const {
|
||||
for (const auto &node : *this) {
|
||||
os << "node [" << node->name() << "] (" << node->type_index().name() << ")\n";
|
||||
os << "node [" << node->name() << "] (" /*<< node->type_index().name()*/ << ")\n";
|
||||
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
|
||||
os << " " << /*node.name() << "::" <<*/ it->second->field_name() << " (" << it->second->type_name() << ")";
|
||||
os << " " /*<< node->name() << "::"*/ << it->second->field_name() << " (" << it->second->type_name() << ")";
|
||||
if (it->second->foreign_endpoint()) {
|
||||
os << " <---> " << it->second->foreign_endpoint()->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
|
||||
os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
|
||||
} else {
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
+33
-14
@@ -27,17 +27,31 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
|
||||
dependency_graph[node->name()].push_back(it->second->node().name());
|
||||
|
||||
in_degree[it->second->node().name()] = std::make_pair(0, it->second->node_ptr());
|
||||
in_degree[it->second->node().name()].first++;
|
||||
auto n = it->second->node_ptr();
|
||||
auto nn = node->name();
|
||||
if (it->second->is_has_one()) {
|
||||
continue;
|
||||
}
|
||||
if (const auto dit = in_degree.find(it->second->node().name()); dit == in_degree.end()) {
|
||||
in_degree[it->second->node().name()] = std::make_pair(1, it->second->node_ptr());
|
||||
} else {
|
||||
in_degree[it->second->node().name()].first++;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the current node exists in the graph representation
|
||||
|
||||
if (in_degree.find(node->name()) == in_degree.end()) {
|
||||
in_degree[node->name()].first = 0;
|
||||
in_degree[node->name()] = std::make_pair(0, node);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &it : dependency_graph) {
|
||||
std::cout << "Dependency graph " << it.first << std::endl;
|
||||
for (const auto &neighbor: it.second) {
|
||||
std::cout << " " << neighbor << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
// Step 2: Perform topological sorting (Kahn's Algorithm)
|
||||
std::queue<object::schema::node_ptr> zero_in_degree;
|
||||
std::vector<object::schema::node_ptr> sorted_order;
|
||||
@@ -48,6 +62,11 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &it : in_degree) {
|
||||
std::cout << "In degree table " << it.second.second->name() << " (" << it.second.first << ")" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
while (!zero_in_degree.empty()) {
|
||||
auto current = zero_in_degree.front();
|
||||
zero_in_degree.pop();
|
||||
@@ -65,7 +84,7 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
// Step 3: Check for cycles
|
||||
|
||||
if (sorted_order.size() != in_degree.size()) {
|
||||
throw std::logic_error("Cycle detected in table dependencies");
|
||||
// throw std::logic_error("Cycle detected in table dependencies");
|
||||
}
|
||||
|
||||
// Step 4: Create tables in the sorted order
|
||||
@@ -86,15 +105,15 @@ utils::result<void, utils::error> session::create_schema() const {
|
||||
// }
|
||||
}
|
||||
|
||||
auto c = pool_.acquire();
|
||||
for (const auto &node: *schema_) {
|
||||
auto result = query::query::create()
|
||||
.table(node->name(), node->info().definition().columns())
|
||||
.execute(*c);
|
||||
if (!result) {
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
}
|
||||
// auto c = pool_.acquire();
|
||||
// for (const auto &node: *schema_) {
|
||||
// auto result = query::query::create()
|
||||
// .table(node->name(), node->info().definition().columns())
|
||||
// .execute(*c);
|
||||
// if (!result) {
|
||||
// return utils::failure(result.err());
|
||||
// }
|
||||
// }
|
||||
|
||||
return utils::ok<void>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user