corvix.web.storage_provider =========================== .. py:module:: corvix.web.storage_provider .. autoapi-nested-parse:: Process-wide storage backend singleton for the web app. Production wiring builds a PostgreSQL backend lazily from config on first use and caches it so its connection pool is reused across requests. Tests inject a backend directly via :func:`set_storage_backend` and reset it to ``None`` afterwards. Attributes ---------- .. autoapisummary:: corvix.web.storage_provider._storage_state Classes ------- .. autoapisummary:: corvix.web.storage_provider._StorageState Functions --------- .. autoapisummary:: corvix.web.storage_provider.set_storage_backend corvix.web.storage_provider._get_storage Module Contents --------------- .. py:class:: _StorageState Mutable container for the module-level storage backend. .. py:attribute:: backend :type: corvix.storage.StorageBackend | None :value: None .. py:attribute:: lock :type: threading.Lock .. py:data:: _storage_state .. py:function:: set_storage_backend(backend: corvix.storage.StorageBackend | None) -> None Inject the storage backend used by route handlers. Production wiring leaves this unset and the backend is built lazily from config (PostgreSQL is required). Tests inject a backend directly and reset it to ``None`` afterwards. .. py:function:: _get_storage() -> corvix.storage.StorageBackend Return the injected backend, or lazily build PostgreSQL storage from config. The built backend is cached so its connection pool is reused across requests. Building is guarded by a lock so concurrent first requests don't each create (and leak) a connection pool. Raises ``HTTPException`` (500) when no database is configured.