Skip to content

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

Merged
merged 43 commits into from
Jul 25, 2022
Merged

feat: add support for asyncpg driver #390

merged 43 commits into from
Jul 25, 2022

Conversation

jackwotherspoon
Copy link
Collaborator

@jackwotherspoon jackwotherspoon commented Jul 4, 2022

Todo:

  • Wait for 0.26.0 release of asyncpg
  • Determine how to use creator argument or similar for SQLAlchemy create_async_engine
  • Update README with asyncpg connection example

Closes #218

@jackwotherspoon jackwotherspoon changed the title WIP: add support for asyncpg driver feat: add support for asyncpg driver Jul 13, 2022
@jackwotherspoon jackwotherspoon requested a review from kurtisvg July 13, 2022 20:45
connector = await create_async_connector()

# create connection to Cloud SQL database
conn: asyncpg.Connection = await connector.connect_async(
Copy link
Contributor

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

Copy link
Collaborator Author

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(...) ?

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

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?)

Copy link
Collaborator Author

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.

@jackwotherspoon jackwotherspoon requested a review from kurtisvg July 18, 2022 13:29
connector = await create_async_connector()

# create connection to Cloud SQL database
conn: asyncpg.Connection = await connector.connect_async(
Copy link
Contributor

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?)

@jackwotherspoon jackwotherspoon requested a review from kurtisvg July 20, 2022 15:18
@jackwotherspoon jackwotherspoon merged commit 3170b1f into main Jul 25, 2022
@jackwotherspoon jackwotherspoon deleted the asyncpg-support branch July 25, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for asyncpg driver.
2 participants