add function to get a DSN for psycopg

Converts the PHP DSN syntax into psycopg syntax when necessary.
This commit is contained in:
Sarah Hoffmann
2021-01-17 17:06:18 +01:00
parent cd0001b55a
commit b79c79fa73
2 changed files with 31 additions and 0 deletions

View File

@@ -29,6 +29,18 @@ class Configuration:
return os.environ.get(name) or self._config[name]
def get_libpq_dsn(self):
""" Get configured database DSN converted into the key/value format
understood by libpq and psycopg.
"""
dsn = self.DATABASE_DSN
if dsn.startswith('pgsql:'):
# Old PHP DSN format. Convert before returning.
return dsn[6:].replace(';', ' ')
return dsn
def get_os_env(self):
""" Return a copy of the OS environment with the Nominatim configuration
merged in.