]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/db/properties.py
complete documentation for new clean-houseunubmers sanatizer
[nominatim.git] / nominatim / db / properties.py
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
7 """
8 Query and access functions for the in-database property table.
9 """
10
11 def set_property(conn, name, value):
12     """ Add or replace the propery with the given name.
13     """
14     with conn.cursor() as cur:
15         cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
16                     (name, ))
17
18         if cur.rowcount == 0:
19             sql = 'INSERT INTO nominatim_properties (value, property) VALUES (%s, %s)'
20         else:
21             sql = 'UPDATE nominatim_properties SET value = %s WHERE property = %s'
22
23         cur.execute(sql, (value, name))
24     conn.commit()
25
26 def get_property(conn, name):
27     """ Return the current value of the given propery or None if the property
28         is not set.
29     """
30     with conn.cursor() as cur:
31         cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
32                     (name, ))
33
34         return cur.fetchone()[0] if cur.rowcount > 0 else None