]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_db/tools/convert_sqlite.py
Merge pull request #3586 from lonvia/reduce-lookup-calls
[nominatim.git] / src / nominatim_db / tools / convert_sqlite.py
index d53527d181f4f670e9028b0cf27869751e3a9bfa..e3dae900be9c592253ab88ce40807ce2258932ef 100644 (file)
@@ -21,6 +21,7 @@ from nominatim_api.sql.sqlalchemy_types import Geometry, IntArray
 
 LOG = logging.getLogger()
 
+
 async def convert(project_dir: Optional[Union[str, Path]],
                   outfile: Path, options: Set[str]) -> None:
     """ Export an existing database to sqlite. The resulting database
@@ -53,7 +54,6 @@ class SqliteWriter:
         self.dest = dest
         self.options = options
 
-
     async def write(self) -> None:
         """ Create the database structure and copy the data from
             the source database to the destination.
@@ -67,7 +67,6 @@ class SqliteWriter:
             await self.create_word_table()
         await self.create_indexes()
 
-
     async def create_tables(self) -> None:
         """ Set up the database tables.
         """
@@ -87,7 +86,6 @@ class SqliteWriter:
                         sa.func.RecoverGeometryColumn(table.name, col.name, 4326,
                                                       col.type.subtype.upper(), 'XY')))
 
-
     async def create_class_tables(self) -> None:
         """ Set up the table that serve class/type-specific geometries.
         """
@@ -99,7 +97,6 @@ class SqliteWriter:
                          sa.Column('place_id', sa.BigInteger),
                          sa.Column('centroid', Geometry))
 
-
     async def create_word_table(self) -> None:
         """ Create the word table.
             This table needs the property information to determine the
@@ -122,7 +119,6 @@ class SqliteWriter:
 
         await self.dest.connection.run_sync(sa.Index('idx_word_woken', dest.c.word_token).create)
 
-
     async def copy_data(self) -> None:
         """ Copy data for all registered tables.
         """
@@ -151,7 +147,6 @@ class SqliteWriter:
         data = [{'tablename': t} for t in self.dest.t.meta.tables]
         await self.dest.execute(pg_tables.insert().values(data))
 
-
     async def create_indexes(self) -> None:
         """ Add indexes necessary for the frontend.
         """
@@ -197,14 +192,12 @@ class SqliteWriter:
                     await self.dest.execute(sa.select(
                       sa.func.CreateSpatialIndex(t, 'centroid')))
 
-
     async def create_spatial_index(self, table: str, column: str) -> None:
         """ Create a spatial index on the given table and column.
         """
         await self.dest.execute(sa.select(
                   sa.func.CreateSpatialIndex(getattr(self.dest.t, table).name, column)))
 
-
     async def create_index(self, table_name: str, column: str) -> None:
         """ Create a simple index on the given table and column.
         """
@@ -212,7 +205,6 @@ class SqliteWriter:
         await self.dest.connection.run_sync(
             sa.Index(f"idx_{table}_{column}", getattr(table.c, column)).create)
 
-
     async def create_search_index(self) -> None:
         """ Create the tables and indexes needed for word lookup.
         """
@@ -242,7 +234,6 @@ class SqliteWriter:
         await self.dest.connection.run_sync(
             sa.Index('idx_reverse_search_name_word', rsn.c.word).create)
 
-
     def select_from(self, table: str) -> SaSelect:
         """ Create the SQL statement to select the source columns and rows.
         """
@@ -258,9 +249,9 @@ class SqliteWriter:
                                         columns.geometry),
                                        else_=sa.func.ST_SimplifyPreserveTopology(
                                                 columns.geometry, 0.0001)
-                                )).label('geometry'))
+                                       )).label('geometry'))
 
         sql = sa.select(*(sa.func.ST_AsText(c).label(c.name)
-                             if isinstance(c.type, Geometry) else c for c in columns))
+                        if isinstance(c.type, Geometry) else c for c in columns))
 
         return sql