creating tables progress

This commit is contained in:
Sascha Kühl
2025-07-16 16:15:31 +02:00
parent a0bfa3261b
commit 581b93c5ea
7 changed files with 266 additions and 100 deletions
+14 -9
View File
@@ -64,16 +64,21 @@ 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";
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
os << " " /*<< node->name() << "::"*/ << it->second->field_name() << " (" << it->second->type_name() << ")";
if (it->second->foreign_endpoint()) {
os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
} else {
os << "\n";
}
}
dump(os, node);
}
os << "\n";
}
void schema::dump( std::ostream& os, const node_ptr& node ) {
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() << ")";
if (it->second->foreign_endpoint()) {
os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
} else {
os << " -> " << it->second->node().name() << " (type: " << it->second->node().type_index().name() << ")\n";
}
}
}
utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
+15 -20
View File
@@ -25,13 +25,12 @@ utils::result<void, utils::error> session::create_schema() const {
for (const auto &node: *schema_) {
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
std::cout << "Dependency graph " << node->name() << " (" << node.get() << ")" << " -> " << it->second->node_ptr()->name() << " (" << it->second->node_ptr().get() << ")" << std::endl;
dependency_graph[node->name()].push_back(it->second->node().name());
auto n = it->second->node_ptr();
auto nn = node->name();
if (it->second->is_has_one()) {
continue;
}
// if (it->second->is_has_many()) {
// 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 {
@@ -62,9 +61,9 @@ 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;
}
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()) {
@@ -84,25 +83,21 @@ utils::result<void, utils::error> session::create_schema() const {
// Step 3: Check for cycles
if (sorted_order.size() != in_degree.size()) {
std::cout << "Cycle detected in table dependencies (sorted order size: " << sorted_order.size() << ", in degree size: " << in_degree.size() << ")" << std::endl;
// throw std::logic_error("Cycle detected in table dependencies");
}
// Step 4: Create tables in the sorted order
auto c = pool_.acquire();
for (const auto &node : sorted_order) {
std::cout << "Creating table " << node->name() << std::endl;
// schema_.
// auto result = query::query::create()
//
// .table(table_name, /* Pass table definition here */)
//
// .execute(*c);
//
// if (!result) {
//
// return utils::failure(result.err());
//
// }
// 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();