-
Notifications
You must be signed in to change notification settings - Fork 76
feat: add support for asyncpg driver #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
connector = await create_async_connector() | ||
|
||
# create connection to Cloud SQL database | ||
conn: asyncpg.Connection = await connector.connect_async( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this connection should probably use an async with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the connector or connection itself? async with create_async_connector()
or async with connector.connect_async(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The connection itself.
Do we support async enters and exit with the Connector?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not currently, we don't have an __aenter__
or __aexit__
implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the ability to create an async context manager with Connector
and added example to README. I can't use async with
for the connection because the asyncpg.Connection class does not have an __aenter__
or __aexit__
. We could potentially create a Connection
wrapper class of our own to implement an async context manager for the database connection. (Example). However, if in a future PR we are going to support connection pools (either through SQLAlchemy or native asyncpg.Pool
then they will have context manager built in so not sure it is worth it to create the wrapper class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is surprising to me that they don't support those two functions. I think it's fine to leave for now (maybe worth asking why they haven't?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there is an open issue for it actually, if I have some spare time I will try and put up another PR to asyncpg and add the two functions.
connector = await create_async_connector() | ||
|
||
# create connection to Cloud SQL database | ||
conn: asyncpg.Connection = await connector.connect_async( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is surprising to me that they don't support those two functions. I think it's fine to leave for now (maybe worth asking why they haven't?)
Todo:
Determine how to use creator argument or similar for SQLAlchemycreate_async_engineCloses #218