// // Created by Kirill Zhukov on 20.04.2025. // #include "DatabaseManager.h" namespace usub::core { DatabaseManager::DatabaseManager(const std::string& config_path) { auto config = toml::parse_file(config_path); if (!config.contains("database")) throw std::runtime_error("No 'database' section found in config"); auto& databases = *config["database"].as_array(); for (auto& db_config : databases) { std::string db_name; if (auto* table = db_config.as_table()) { if (auto it = table->find("name"); it != table->end() && it->second.is_string()) { db_name = it->second.value().value_or(""); } else { throw std::runtime_error("Database name must be a string"); } } else { throw std::runtime_error("Database entry must be a table"); } auto udb = std::make_unique(db_name, "shm_" + db_name); databases_.push_back(DatabaseInstance{std::move(udb), {}}); } } void DatabaseManager::run_all() { for (auto& db : databases_) { db.worker = std::thread([&db]() { db.udb->run(); }); } for (auto& db : databases_) { if (db.worker.joinable()) db.worker.join(); } } } // core // usub