]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/tools/convert_sqlite.py
add skeleton code for convert function
[nominatim.git] / nominatim / tools / convert_sqlite.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Exporting a Nominatim database to SQlite.
9 """
10 from typing import Set
11 from pathlib import Path
12
13 import sqlalchemy as sa
14
15 import nominatim.api as napi
16
17 async def convert(project_dir: Path, outfile: Path, options: Set[str]) -> None:
18     """ Export an existing database to sqlite. The resulting database
19         will be usable against the Python frontend of Nominatim.
20     """
21     api = napi.NominatimAPIAsync(project_dir)
22
23     try:
24         outapi = napi.NominatimAPIAsync(project_dir,
25                                         {'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={outfile}"})
26
27         async with api.begin() as inconn, outapi.begin() as outconn:
28             pass
29     finally:
30         await api.close()