X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/27977411e958a6bfc9037db728d61d296c5487c0..48c19f7a025d1cd843afa941c2f8c73c0e1a0a29:/nominatim/db/async_connection.py?ds=inline diff --git a/nominatim/db/async_connection.py b/nominatim/db/async_connection.py index 85b84431..45e83664 100644 --- a/nominatim/db/async_connection.py +++ b/nominatim/db/async_connection.py @@ -11,26 +11,14 @@ from psycopg2.extras import wait_select LOG = logging.getLogger() -def make_connection(options, asynchronous=False): - """ Create a psycopg2 connection from the given options. - """ - params = {'dbname' : options.dbname, - 'user' : options.user, - 'password' : options.password, - 'host' : options.host, - 'port' : options.port, - 'async' : asynchronous} - - return psycopg2.connect(**params) - class DBConnection: """ A single non-blocking database connection. """ - def __init__(self, options): + def __init__(self, dsn): self.current_query = None self.current_params = None - self.options = options + self.dsn = dsn self.conn = None self.cursor = None @@ -46,7 +34,9 @@ class DBConnection: self.cursor.close() self.conn.close() - self.conn = make_connection(self.options, asynchronous=True) + # Use a dict to hand in the parameters because async is a reserved + # word in Python3. + self.conn = psycopg2.connect(**{'dsn' : self.dsn, 'async' : True}) self.wait() self.cursor = self.conn.cursor()