]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/api.py
fix error message for non-existing database
[nominatim.git] / nominatim / api.py
index 60165d33e762e4c2e6e54175736a665e91f4248d..e129c4f8de4e9e13c5f87a9183cc6deabbf14ec4 100644 (file)
@@ -7,15 +7,13 @@
 """
 Implementation of classes for API access via libraries.
 """
-from typing import Mapping, Optional, TypeVar, Callable, Any
-import functools
+from typing import Mapping, Optional
 import asyncio
 from pathlib import Path
 
 from sqlalchemy.engine.url import URL
 from sqlalchemy.ext.asyncio import create_async_engine
 
-from nominatim.typing import StrPath
 from nominatim.config import Configuration
 from nominatim.apicmd.status import get_status, StatusResult
 
@@ -40,6 +38,14 @@ class NominatimAPIAsync:
                                           future=True)
 
 
+    async def close(self) -> None:
+        """ Close all active connections to the database. The NominatimAPIAsync
+            object remains usable after closing. If a new API functions is
+            called, new connections are created.
+        """
+        await self.engine.dispose()
+
+
     async def status(self) -> StatusResult:
         """ Return the status of the database.
         """
@@ -55,5 +61,15 @@ class NominatimAPI:
         self.async_api = NominatimAPIAsync(project_dir, environ)
 
 
+    def close(self) -> None:
+        """ Close all active connections to the database. The NominatimAPIAsync
+            object remains usable after closing. If a new API functions is
+            called, new connections are created.
+        """
+        asyncio.get_event_loop().run_until_complete(self.async_api.close())
+
+
     def status(self) -> StatusResult:
+        """ Return the status of the database.
+        """
         return asyncio.get_event_loop().run_until_complete(self.async_api.status())