]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_api/connection.py
Merge pull request #3582 from lonvia/switch-to-flake
[nominatim.git] / src / nominatim_api / connection.py
index 66b00ac8138f955056d523fc23f9764f93a62b2b..e104745ebe784de098b97bb6a9d70f9a5a7a0d52 100644 (file)
@@ -14,13 +14,14 @@ import asyncio
 import sqlalchemy as sa
 from sqlalchemy.ext.asyncio import AsyncConnection
 
 import sqlalchemy as sa
 from sqlalchemy.ext.asyncio import AsyncConnection
 
-from nominatim_core.typing import SaFromClause
-from nominatim_core.db.sqlalchemy_schema import SearchTables
-from nominatim_core.db.sqlalchemy_types import Geometry
+from .typing import SaFromClause
+from .sql.sqlalchemy_schema import SearchTables
+from .sql.sqlalchemy_types import Geometry
 from .logging import log
 
 T = TypeVar('T')
 
 from .logging import log
 
 T = TypeVar('T')
 
+
 class SearchConnection:
     """ An extended SQLAlchemy connection class, that also contains
         the table definitions. The underlying asynchronous SQLAlchemy
 class SearchConnection:
     """ An extended SQLAlchemy connection class, that also contains
         the table definitions. The underlying asynchronous SQLAlchemy
@@ -32,37 +33,32 @@ class SearchConnection:
                  tables: SearchTables,
                  properties: Dict[str, Any]) -> None:
         self.connection = conn
                  tables: SearchTables,
                  properties: Dict[str, Any]) -> None:
         self.connection = conn
-        self.t = tables # pylint: disable=invalid-name
+        self.t = tables
         self._property_cache = properties
         self._classtables: Optional[Set[str]] = None
         self.query_timeout: Optional[int] = None
 
         self._property_cache = properties
         self._classtables: Optional[Set[str]] = None
         self.query_timeout: Optional[int] = None
 
-
     def set_query_timeout(self, timeout: Optional[int]) -> None:
         """ Set the timeout after which a query over this connection
             is cancelled.
         """
         self.query_timeout = timeout
 
     def set_query_timeout(self, timeout: Optional[int]) -> None:
         """ Set the timeout after which a query over this connection
             is cancelled.
         """
         self.query_timeout = timeout
 
-
     async def scalar(self, sql: sa.sql.base.Executable,
     async def scalar(self, sql: sa.sql.base.Executable,
-                     params: Union[Mapping[str, Any], None] = None
-                    ) -> Any:
+                     params: Union[Mapping[str, Any], None] = None) -> Any:
         """ Execute a 'scalar()' query on the connection.
         """
         log().sql(self.connection, sql, params)
         return await asyncio.wait_for(self.connection.scalar(sql, params), self.query_timeout)
 
         """ Execute a 'scalar()' query on the connection.
         """
         log().sql(self.connection, sql, params)
         return await asyncio.wait_for(self.connection.scalar(sql, params), self.query_timeout)
 
-
     async def execute(self, sql: 'sa.Executable',
                       params: Union[Mapping[str, Any], Sequence[Mapping[str, Any]], None] = None
     async def execute(self, sql: 'sa.Executable',
                       params: Union[Mapping[str, Any], Sequence[Mapping[str, Any]], None] = None
-                     ) -> 'sa.Result[Any]':
+                      ) -> 'sa.Result[Any]':
         """ Execute a 'execute()' query on the connection.
         """
         log().sql(self.connection, sql, params)
         return await asyncio.wait_for(self.connection.execute(sql, params), self.query_timeout)
 
         """ Execute a 'execute()' query on the connection.
         """
         log().sql(self.connection, sql, params)
         return await asyncio.wait_for(self.connection.execute(sql, params), self.query_timeout)
 
-
     async def get_property(self, name: str, cached: bool = True) -> str:
         """ Get a property from Nominatim's property table.
 
     async def get_property(self, name: str, cached: bool = True) -> str:
         """ Get a property from Nominatim's property table.
 
@@ -89,7 +85,6 @@ class SearchConnection:
 
         return cast(str, value)
 
 
         return cast(str, value)
 
-
     async def get_db_property(self, name: str) -> Any:
         """ Get a setting from the database. At the moment, only
             'server_version', the version of the database software, can
     async def get_db_property(self, name: str) -> Any:
         """ Get a setting from the database. At the moment, only
             'server_version', the version of the database software, can
@@ -102,7 +97,6 @@ class SearchConnection:
 
         return self._property_cache['DB:server_version']
 
 
         return self._property_cache['DB:server_version']
 
-
     async def get_cached_value(self, group: str, name: str,
                                factory: Callable[[], Awaitable[T]]) -> T:
         """ Access the cache for this Nominatim instance.
     async def get_cached_value(self, group: str, name: str,
                                factory: Callable[[], Awaitable[T]]) -> T:
         """ Access the cache for this Nominatim instance.
@@ -125,7 +119,6 @@ class SearchConnection:
 
         return value
 
 
         return value
 
-
     async def get_class_table(self, cls: str, typ: str) -> Optional[SaFromClause]:
         """ Lookup up if there is a classtype table for the given category
             and return a SQLAlchemy table for it, if it exists.
     async def get_class_table(self, cls: str, typ: str) -> Optional[SaFromClause]:
         """ Lookup up if there is a classtype table for the given category
             and return a SQLAlchemy table for it, if it exists.