From 46c0f6670d72040f5b6b4cdcfb1b38690cfa1471 Mon Sep 17 00:00:00 2001 From: David Grigorenko Date: Wed, 4 Dec 2024 16:49:40 +0300 Subject: [PATCH] feat: Psycopg3 driver support for async sqlalchemy. --- hasql/asyncsqlalchemy.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hasql/asyncsqlalchemy.py b/hasql/asyncsqlalchemy.py index b409828..4e353e6 100644 --- a/hasql/asyncsqlalchemy.py +++ b/hasql/asyncsqlalchemy.py @@ -35,8 +35,9 @@ async def _is_master(self, connection: AsyncConnection): return result async def _pool_factory(self, dsn: Dsn): - # TODO: Add support of psycopg3 after release of sqlalchemy 2.0 - d = str(dsn).replace("postgresql", "postgresql+asyncpg") + d = str(dsn) + if d.startswith('postgresql://'): + d = d.replace('postgresql://', 'postgresql+asyncpg://', 1) return create_async_engine(d, **self.pool_factory_kwargs) def _prepare_pool_factory_kwargs(self, kwargs: dict) -> dict: