1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Classes and function releated to status call.
10 from typing import Optional
14 import sqlalchemy as sa
16 from nominatim.api.connection import SearchConnection
17 from nominatim import version
19 @dataclasses.dataclass
21 """ Result of a call to the status API.
25 software_version = version.NOMINATIM_VERSION
26 data_updated: Optional[dt.datetime] = None
27 database_version: Optional[version.NominatimVersion] = None
30 async def get_status(conn: SearchConnection) -> StatusResult:
31 """ Execute a status API call.
33 status = StatusResult(0, 'OK')
36 sql = sa.select(conn.t.import_status.c.lastimportdate).limit(1)
37 status.data_updated = await conn.scalar(sql)
39 if status.data_updated is not None:
40 status.data_updated = status.data_updated.replace(tzinfo=dt.timezone.utc)
44 verstr = await conn.get_property('database_version')
45 status.database_version = version.parse_version(verstr)