1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 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 .connection import Connection, table_exists
15 def set_property(conn: Connection, name: str, value: str) -> None:
16 """ Add or replace the property with the given name.
18 with conn.cursor() as cur:
19 cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
23 sql = 'INSERT INTO nominatim_properties (value, property) VALUES (%s, %s)'
25 sql = 'UPDATE nominatim_properties SET value = %s WHERE property = %s'
27 cur.execute(sql, (value, name))
31 def get_property(conn: Connection, name: str) -> Optional[str]:
32 """ Return the current value of the given property or None if the property
35 if not table_exists(conn, 'nominatim_properties'):
38 with conn.cursor() as cur:
39 cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
45 result = cur.fetchone()
46 assert result is not None
48 return cast(Optional[str], result[0])