| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "db_gateway.hpp"
- namespace svapi {
- std::string qualify(const std::string& project, const std::string& collection) {
- if (project.empty() || project == "default") return collection;
- return project + ":" + collection;
- }
- namespace {
- smartbotic::database::Client::Config makeConfig(std::string address, uint32_t timeoutMs) {
- smartbotic::database::Client::Config cfg;
- cfg.address = std::move(address);
- cfg.timeoutMs = timeoutMs;
- return cfg; // leave cfg.project = "default"; we qualify per-call
- }
- } // namespace
- DbGateway::DbGateway(std::string address, uint32_t timeoutMs)
- : client_(makeConfig(std::move(address), timeoutMs)) {}
- bool DbGateway::connect() { return client_.connect(); }
- bool DbGateway::healthy() { return client_.healthCheck(); }
- smartbotic::database::Client& DbGateway::client() { return client_; }
- std::vector<std::string> DbGateway::listProjects() { return client_.listProjects(); }
- bool DbGateway::ensureProject(const std::string& name) {
- try { client_.createProject(name); return true; } // idempotent server-side
- catch (const std::exception&) { return false; }
- }
- bool DbGateway::dropProject(const std::string& name) {
- if (name == "default") return false;
- try { client_.dropProject(name); return true; }
- catch (const std::exception&) { return false; }
- }
- } // namespace svapi
|