From d868e239ae2ccd042773498fea5ded33c8033d40 Mon Sep 17 00:00:00 2001 From: Wojciech Barcik <wbarcik@syncad.com> Date: Wed, 11 Nov 2020 11:29:44 +0100 Subject: [PATCH] Handle postgres connection string with unix socket, fix #100 --- hive/server/db.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hive/server/db.py b/hive/server/db.py index e7608b4b6..60ce93912 100644 --- a/hive/server/db.py +++ b/hive/server/db.py @@ -38,13 +38,20 @@ class Db: async def init(self, url): """Initialize the aiopg.sa engine.""" conf = make_url(url) - self.db = await create_engine(user=conf.username, - database=conf.database, - password=conf.password, - host=conf.host, - port=conf.port, - maxsize=20, - **conf.query) + dsn = {} + if conf.username: + dsn['user'] = conf.username + if conf.database: + dsn['database'] = conf.database + if conf.password: + dsn['password'] = conf.password + if conf.host: + dsn['host'] = conf.host + if conf.port: + dsn['port'] = conf.port + if 'application_name' not in conf.query: + dsn['application_name'] = 'hive_server' + self.db = await create_engine(**dsn, maxsize=20, **conf.query) def close(self): """Close pool.""" -- GitLab