db_gateway.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <smartbotic/database/client.hpp>
  3. #include <string>
  4. #include <vector>
  5. namespace svapi {
  6. /// Returns `project + ":" + collection` for named projects; returns bare
  7. /// `collection` when project is "" or "default" (back-compat default project).
  8. std::string qualify(const std::string& project, const std::string& collection);
  9. /// Thin wrapper over `smartbotic::database::Client` that adds project-level
  10. /// helpers (listProjects / ensureProject / dropProject) and a uniform
  11. /// connect/healthy lifecycle.
  12. class DbGateway {
  13. public:
  14. /// @param address host:port of the smartbotic-database gRPC endpoint.
  15. /// @param timeoutMs per-call timeout in milliseconds (default 5 s).
  16. explicit DbGateway(std::string address, uint32_t timeoutMs = 5000);
  17. /// Establish the gRPC connection. Returns true on success.
  18. bool connect();
  19. /// Returns true if the server responds to a health-check ping.
  20. bool healthy();
  21. /// Direct access to the underlying client for collection/document ops.
  22. smartbotic::database::Client& client();
  23. /// List all projects on the server (always includes "default").
  24. std::vector<std::string> listProjects();
  25. /// Idempotent createProject. Returns true on success (new or already existed).
  26. bool ensureProject(const std::string& name);
  27. /// Drop a project. Returns false (without throwing) when name == "default".
  28. /// Returns false on any transport or server-side failure.
  29. bool dropProject(const std::string& name);
  30. private:
  31. smartbotic::database::Client client_;
  32. };
  33. } // namespace svapi