]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/db/properties.py
move SearchDescription building into tokens
[nominatim.git] / nominatim / db / properties.py
1 """
2 Query and access functions for the in-database property table.
3 """
4
5 def set_property(conn, name, value):
6     """ Add or replace the propery with the given name.
7     """
8     with conn.cursor() as cur:
9         cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
10                     (name, ))
11
12         if cur.rowcount == 0:
13             sql = 'INSERT INTO nominatim_properties (value, property) VALUES (%s, %s)'
14         else:
15             sql = 'UPDATE nominatim_properties SET value = %s WHERE property = %s'
16
17         cur.execute(sql, (value, name))
18     conn.commit()
19
20 def get_property(conn, name):
21     """ Return the current value of the given propery or None if the property
22         is not set.
23     """
24     with conn.cursor() as cur:
25         cur.execute('SELECT value FROM nominatim_properties WHERE property = %s',
26                     (name, ))
27
28         return cur.fetchone()[0] if cur.rowcount > 0 else None