Closed bamartin125 closed 1 year ago
Looking at this again this morning, I think I am beginning to realize that asyncpg
has no intention of integrating itself with nor aligning itself with psycopg
or its APIs because they are in fact two separate projects implemented in quite different ways.
As I briefly learned about the use of this library within my project at work, I was somehow inclined to think that asyncpg
was simply a compatibility layer built on top of psycopg
for the asyncio
usecase. This assumption was completely wrong. The "compatibility layer" design I describe does exist and one implementation of it is called aiopg
. In my project (which uses sqlalchemy
), I need to decide to do one of the following:
asyncpg
and thus migrate away from psycopg
(using the sqlalchemy
postgresql+asyncpg
dialect/driver)aiopg
on top of psycopg2
(using aiopg
's create_engine
to get an async
sqlalchemy
Engine
)psycopg
(v3) and sqlalchemy>=2.0
(using the sqlalchemy
postgresql+psycopg_async
dialect/driver)
sqlalchemy==2.0
is still in beta as of this writing, so I'd probably have to waitClosing this issue, though I hope this helps others that may fall into the same mindset/situation as I did.
Honestly, I'm unsure if this should be a bug report or feature request as I am unaware of whether the lack of support for the
cursor
cursor_factory
keyword was (un)intended.The
psycopg2
connection
class'scursor()
method has a signature that contains acursor_factory
keyword argument (see connection.cursor & connection-and-cursor-factories). Thecursor_factory
keyword argument is expected to be accepted for a portion of the internalpsycopg2
implementation (see psycopg2/lib/extras.py#L773-L783).One such case that the
cursor_factory
keyword is expected internally ofpsycopg2
is when callingpsycopg2.extras.register_composite
. Currently, when callingregister_composite
,psycopg2
chokes on the fact thatasyncpg.connection.Connection.cursor
does not accept thecursor_factory
keyword.Here is an example traceback snippet:
where the
conn
above is anasyncpg.connection.Connection
.I am very new to the
asyncpg
project and its internals. I also do not currently have the time to investigate this further, so I cannot currently comment on a path toward resolution. I'm hoping that someone else can comment or that I can come back soon to revisit this issue and further contribute to a solution. I don't know if it helps, but theaiopg
project does document that it supports thecursor_factory
keyword viaaiopg.Connection.cursor
.