#pragma once #include "evo/persistence/postgres.hpp" #include #include #include // One lazily (re)connected PostgreSQL connection for single-owner callers such as the // session ledgers (ADR-0091/0092). A caller that sees a store failure marks the slot broken; // the next get() reconnects. Never retries a statement by itself. namespace evo::server { class PgSlot { public: PgSlot(persistence::PgOptions options, std::chrono::milliseconds connect_timeout) : options_{std::move(options)}, timeout_{connect_timeout} {} // Nullptr when no connection can be made now. [[nodiscard]] persistence::Postgres* get() { if (!db_) if (auto made = persistence::Postgres::connect(options_, timeout_)) db_ = std::move(*made); return db_.get(); } void broken() noexcept { db_.reset(); } private: persistence::PgOptions options_; std::chrono::milliseconds timeout_; std::unique_ptr db_; }; } // namespace evo::server