1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Query and access functions for the in-database property table.
10 from typing import Optional, cast
12 from nominatim.db.connection import Connection
14 def set_property(conn: Connection, name: str, value: str) -> None:
15 """ Add or replace the property with the given name.
17 with conn.cursor() as cur:
18 cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
22 sql = 'INSERT INTO nominatim_properties (value, property) VALUES (%s, %s)'
24 sql = 'UPDATE nominatim_properties SET value = %s WHERE property = %s'
26 cur.execute(sql, (value, name))
30 def get_property(conn: Connection, name: str) -> Optional[str]:
31 """ Return the current value of the given property or None if the property
34 if not conn.table_exists('nominatim_properties'):
37 with conn.cursor() as cur:
38 cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
44 result = cur.fetchone()
45 assert result is not None
47 return cast(Optional[str], result[0])